Module: LitePage::ElementFactory

Defined in:
lib/lite_page/element_factory.rb

Instance Method Summary collapse

Instance Method Details

#def_elements(root_elem_var_name, element_definitions = {}) ⇒ Object

Provides convenient method for concisely defining element getters

Parameters:

  • root_elem_var_name (Symbol)

    the name of the instance variable containing the element on which methods should be caleld (typically the browser instance).

  • element_definitions (Hash) (defaults to: {})

    the hash used to define element getters on the class instance where each key represents the name of the method to be defined and whose value is an array containing first, the element tag name and second, the selectors with which to locate it.



12
13
14
15
16
17
18
19
# File 'lib/lite_page/element_factory.rb', line 12

def def_elements(root_elem_var_name, element_definitions = {})
  element_definitions.each do |name, definition|
    define_method(name) do |other_selectors = {}|
      definition[1].merge!(other_selectors)
      instance_variable_get(root_elem_var_name.to_sym).send(*definition)
    end
  end
end