Module: Tooth::PageObject

Included in:
Widgeon::PageObject
Defined in:
lib/deps/tooth/page_object.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)



117
118
119
120
121
122
123
# File 'lib/deps/tooth/page_object.rb', line 117

def method_missing(meth, *args, &block)
  if( element_finder = page_element[meth.to_sym])
    element_finder.call(*args)
  else
    element_with_finders.send(meth, *args, &block)
  end
end

Instance Method Details

#button(name, locator) ⇒ Object



59
60
61
# File 'lib/deps/tooth/page_object.rb', line 59

def button name, locator
  page_element[name] = lambda { |*args| element_with_finders.find_button(locator_string(locator, args)) }
end

#component(name, component_class, locator, options = {}) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/deps/tooth/page_object.rb', line 76

def component name, component_class, locator, options = {}
  page_element[name] = lambda { |*args|
      component_element = find(locator_string(locator, args), options)
  component_class.tap do |cmp|
    cmp.element_with_finders = component_element
  end
  }
end

#element(name, locator, options = {}) ⇒ Object

TODO: refactor to support :xpath locators



64
65
66
67
68
# File 'lib/deps/tooth/page_object.rb', line 64

def element name, locator, options = {}
  page_element[name] = lambda { |*args|
      element_with_finders.find(locator_string(locator, args), options)
  }
end

#elements(name, locator, options = {}) ⇒ Object



70
71
72
73
74
# File 'lib/deps/tooth/page_object.rb', line 70

def elements name, locator, options = {}
  page_element[name] = lambda { |*args|
      element_with_finders.all(locator_string(locator, args), options)
  }
end

#field(name, locator) ⇒ Object



55
56
57
# File 'lib/deps/tooth/page_object.rb', line 55

def field name, locator
  page_element[name] = lambda { |*args| element_with_finders.find_field(locator_string(locator, args)) }
end


51
52
53
# File 'lib/deps/tooth/page_object.rb', line 51

def link name, locator
  page_element[name] = lambda { |*args| element_with_finders.find_link(locator_string(locator, args)) }
end

#not_shows?(&block) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
# File 'lib/deps/tooth/page_object.rb', line 91

def not_shows? &block
  instance_eval &block
rescue Capybara::ElementNotFound
else
  raise 'Element is shown'
end

#shows?(&block) ⇒ Boolean Also known as: scenario

convenience methods

Returns:

  • (Boolean)


86
87
88
# File 'lib/deps/tooth/page_object.rb', line 86

def shows? &block
  instance_eval &block
end

#within(scope_locator, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/deps/tooth/page_object.rb', line 38

def within scope_locator, &block
  within_scope_klass = Class.new
  within_scope_klass.extend Widgeon::PageObject #TODO: is there a better way to update the #within?
  within_scope_klass.instance_variable_set :@page_element, page_element
  # todo: think on refactoring the following code to something like:
  #   `within_scope_klass.element_with_finders = lambda{ element_with_finders.find(scope_locator).should be_visible? }`
  # i.e. use rspec matchers instead, and be more of 'selenide' style (see selenide.org)
  within_scope_klass.element_with_finders = lambda do
    wait_for { element_with_finders.find(scope_locator) }
  end
  within_scope_klass.class_eval &block
end