Sha256: de05d3c16f2c64cb0e67a1cdb71651089922291107cd64736812405b5765f040

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require "watir"
require "watir-webdriver"

module Symbiote
  include Situation

  module_function

  def elements
    @elements = Watir::Container.instance_methods unless @elements
  end

  def hosts?(method)
    Symbiote.elements.include? method.to_sym
  end

  module Elements
    module Accessor
      def reference_element(element, locator)
        browser.send(element, *locator).to_subtype
      rescue NoMethodError
        browser.send(element, *locator)
      end
    end

    def method_missing(method, *args)
      abort("The method '#{method}' is not a recognized element method.")
      super
    end

    def respond_to_missing?(method)
      super
    end

    Symbiote.elements.each do |element|
      define_method(element) do |*signature, &block|
        identifier, locator = parse_signature(signature)
        define_element_accessor(identifier, locator, element, &block)
      end
    end

    private

    def define_element_accessor(identifier, *locator, element, &block)
      define_method(identifier.to_s.to_sym) do |*values|
        if block_given?
          instance_exec(*values, &block)
        else
          no_locator(self.class, identifier) if empty_locator(locator, values)
          locator = values if locator[0].nil?
          reference_element(element, locator)
        end
      end
    end

    def parse_signature(signature)
      [signature.shift, signature.shift]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
symbiote-0.2.0 lib/symbiote/elements.rb