Sha256: b17db67c1a85c787bd62ed0c4a09742d5f04b29a619165eea934bc6c04714581

Contents?: true

Size: 900 Bytes

Versions: 4

Compression:

Stored size: 900 Bytes

Contents

module PageMagic
  # class ElementContext - resolves which element definition to use when accessing the browser.
  class ElementContext
    attr_reader :page_element

    def initialize(page_element)
      @page_element = page_element
    end

    # acts as proxy to element defintions defined on @page_element
    def method_missing(method, *args, &block)
      return page_element.send(method, *args, &block) if page_element.methods.include?(method)

      element_locator_factory = page_element.element_definitions[method]

      fail ElementMissingException, "Could not find: #{method}" unless element_locator_factory

      element_locator = element_locator_factory.call(page_element, *args)

      element_locator.section? ? element_locator : element_locator.browser_element
    end

    def respond_to?(*args)
      page_element.element_definitions.keys.include?(args.first)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
page_magic-1.0.0.alpha21 lib/page_magic/element_context.rb
page_magic-1.0.0.alpha20 lib/page_magic/element_context.rb
page_magic-1.0.0.alpha19 lib/page_magic/element_context.rb
page_magic-1.0.0.alpha18 lib/page_magic/element_context.rb