Class: PageMagic::ElementContext

Inherits:
Object
  • Object
show all
Defined in:
lib/page_magic/element_context.rb

Overview

class ElementContext - resolves which element definition to use when accessing the browser.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_element) ⇒ ElementContext

Returns a new instance of ElementContext.



8
9
10
# File 'lib/page_magic/element_context.rb', line 8

def initialize(page_element)
  @page_element = page_element
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object, ...

acts as proxy to element definitions defined on @page_element

Returns:

  • (Object)

    result of calling method on page_element

  • (Element)

    page element containing located browser element

  • (Array<Element>)

    array of elements if more that one result was found the browser



16
17
18
19
20
21
22
23
24
# File 'lib/page_magic/element_context.rb', line 16

def method_missing(method, *args, &block)
  return page_element.send(method, *args, &block) if page_element.methods.include?(method)

  builder = page_element.element_by_name(method, *args)

  super unless builder

  builder.build(page_element.browser_element)
end

Instance Attribute Details

#page_elementObject (readonly)

Returns the value of attribute page_element.



6
7
8
# File 'lib/page_magic/element_context.rb', line 6

def page_element
  @page_element
end

Instance Method Details

#respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/page_magic/element_context.rb', line 26

def respond_to_missing?(*args)
  page_element.respond_to?(*args) || super
end