Module: Tooth::PageObject
- Defined in:
- lib/tooth/page_object.rb
Instance Method Summary
collapse
-
#button(name, locator) ⇒ Object
-
#component(name, component_class, locator, options = {}) ⇒ Object
-
#element(name, locator, options = {}) ⇒ Object
-
#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
76
77
78
79
80
81
82
|
# File 'lib/tooth/page_object.rb', line 76
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
19
20
21
|
# File 'lib/tooth/page_object.rb', line 19
def button name, locator
page_element[name] = ->(*args){ element_with_finders.find_button(locator_string(locator, args)) }
end
|
#component(name, component_class, locator, options = {}) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/tooth/page_object.rb', line 35
def component name, component_class, locator, options = {}
page_element[name] = ->(*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
23
24
25
26
27
|
# File 'lib/tooth/page_object.rb', line 23
def element name, locator, options = {}
page_element[name] = ->(*args){
element_with_finders.find(locator_string(locator, args), options)
}
end
|
#elements(name, locator, options = {}) ⇒ Object
29
30
31
32
33
|
# File 'lib/tooth/page_object.rb', line 29
def elements name, locator, options = {}
page_element[name] = ->(*args){
element_with_finders.all(locator_string(locator, args), options)
}
end
|
#field(name, locator) ⇒ Object
15
16
17
|
# File 'lib/tooth/page_object.rb', line 15
def field name, locator
page_element[name] = ->(*args){ element_with_finders.find_field(locator_string(locator, args)) }
end
|
#link(name, locator) ⇒ Object
11
12
13
|
# File 'lib/tooth/page_object.rb', line 11
def link name, locator
page_element[name] = ->(*args){ element_with_finders.find_link(locator_string(locator, args)) }
end
|
#not_shows?(&block) ⇒ Boolean
50
51
52
53
54
55
|
# File 'lib/tooth/page_object.rb', line 50
def not_shows? &block
instance_eval &block
rescue Capybara::ElementNotFound
else
raise 'Element is shown'
end
|
#shows?(&block) ⇒ Boolean
Also known as:
scenario
45
46
47
|
# File 'lib/tooth/page_object.rb', line 45
def shows? &block
instance_eval &block
end
|
#within(scope_locator, &block) ⇒ Object
3
4
5
6
7
8
9
|
# File 'lib/tooth/page_object.rb', line 3
def within scope_locator, &block
within_scope_klass = Class.new
within_scope_klass.extend PageObject
within_scope_klass.instance_variable_set :@page_element, page_element
within_scope_klass.element_with_finders = -> { element_with_finders.find(scope_locator) }
within_scope_klass.class_eval &block
end
|