Module: Tooth::PageObject
Instance Method Summary
collapse
-
#button(name, locator) ⇒ Object
-
#component(name, component_class, locator, options = {}) ⇒ Object
-
#element(name, locator, options = {}) ⇒ Object
TODO: refactor to support :xpath locators.
-
#elements(name, locator, options = {}) ⇒ Object
-
#field(name, locator) ⇒ Object
-
#link(name, locator) ⇒ Object
-
#not_shows?(&block) ⇒ Boolean
-
#shows?(&block) ⇒ Boolean
(also: #scenario)
-
#within(scope_locator, &block) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
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
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
|
#link(name, locator) ⇒ Object
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
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
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
within_scope_klass.instance_variable_set :@page_element, page_element
within_scope_klass.element_with_finders = lambda do
wait_for { element_with_finders.find(scope_locator) }
end
within_scope_klass.class_eval &block
end
|