page-object 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +15 -0
- data/features/button.feature +1 -0
- data/features/element.feature +60 -56
- data/features/frames.feature +1 -0
- data/features/generic_elements.feature +24 -0
- data/features/html/multi_elements.html +4 -0
- data/features/html/nested_elements.html +4 -1
- data/features/html/static_elements.html +15 -1
- data/features/label.feature +44 -0
- data/features/link.feature +1 -0
- data/features/sample-app/public/prototype.html +1 -0
- data/features/step_definitions/element_steps.rb +22 -6
- data/features/step_definitions/frames_steps.rb +4 -0
- data/features/step_definitions/generic_element_steps.rb +19 -0
- data/features/step_definitions/label_steps.rb +19 -0
- data/features/support/page.rb +17 -0
- data/lib/page-object.rb +7 -0
- data/lib/page-object/accessors.rb +73 -1
- data/lib/page-object/element_locators.rb +36 -0
- data/lib/page-object/elements.rb +2 -1
- data/lib/page-object/elements/button.rb +2 -2
- data/lib/page-object/elements/element.rb +6 -6
- data/lib/page-object/elements/label.rb +19 -0
- data/lib/page-object/elements/link.rb +2 -2
- data/lib/page-object/elements/text_field.rb +1 -1
- data/lib/page-object/nested_elements.rb +8 -0
- data/lib/page-object/page_factory.rb +6 -0
- data/lib/page-object/platforms/selenium_webdriver/element.rb +17 -17
- data/lib/page-object/platforms/selenium_webdriver/form.rb +2 -2
- data/lib/page-object/platforms/selenium_webdriver/image.rb +2 -2
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +54 -1
- data/lib/page-object/platforms/selenium_webdriver/select_list.rb +2 -2
- data/lib/page-object/platforms/selenium_webdriver/table.rb +2 -2
- data/lib/page-object/platforms/watir_webdriver/element.rb +14 -14
- data/lib/page-object/platforms/watir_webdriver/form.rb +2 -2
- data/lib/page-object/platforms/watir_webdriver/image.rb +2 -2
- data/lib/page-object/platforms/watir_webdriver/page_object.rb +72 -9
- data/lib/page-object/platforms/watir_webdriver/select_list.rb +5 -5
- data/lib/page-object/platforms/watir_webdriver/table.rb +2 -2
- data/lib/page-object/version.rb +1 -1
- data/page-object.gemspec +1 -1
- data/spec/page-object/accessors_spec.rb +15 -3
- data/spec/page-object/element_locators_spec.rb +24 -0
- data/spec/page-object/elements/button_spec.rb +2 -2
- data/spec/page-object/elements/label_spec.rb +29 -0
- data/spec/page-object/elements/link_spec.rb +2 -2
- data/spec/page-object/page-object_spec.rb +7 -1
- data/spec/page-object/page_factory_spec.rb +26 -0
- data/spec/page-object/platforms/watir_webdriver_spec.rb +1 -0
- metadata +26 -15
@@ -11,7 +11,7 @@ module PageObject
|
|
11
11
|
protected
|
12
12
|
|
13
13
|
def self.watir_finders
|
14
|
-
super + [:href, :text]
|
14
|
+
super + [:href, :text, :css]
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.watir_mapping
|
@@ -19,7 +19,7 @@ module PageObject
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.selenium_finders
|
22
|
-
super + [:link, :link_text]
|
22
|
+
super + [:link, :link_text, :css]
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.selenium_mapping
|
@@ -193,6 +193,14 @@ module PageObject
|
|
193
193
|
@platform.paragraphs_for(identifier)
|
194
194
|
end
|
195
195
|
|
196
|
+
def label_element(identifier={:index => 0})
|
197
|
+
@platform.label_for(identifier)
|
198
|
+
end
|
199
|
+
|
200
|
+
def label_elements(identifier={:index => 0})
|
201
|
+
@platform.labels_for(identifier)
|
202
|
+
end
|
203
|
+
|
196
204
|
def file_field_element(identifier={:index => 0})
|
197
205
|
@platform.file_field_for(identifier)
|
198
206
|
end
|
@@ -43,6 +43,9 @@ module PageObject
|
|
43
43
|
on_page page_class, true, &block
|
44
44
|
end
|
45
45
|
|
46
|
+
# Support 'visit' for readability of usage
|
47
|
+
alias_method :visit, :visit_page
|
48
|
+
|
46
49
|
#
|
47
50
|
# Create a page object.
|
48
51
|
#
|
@@ -57,6 +60,9 @@ module PageObject
|
|
57
60
|
@current_page
|
58
61
|
end
|
59
62
|
|
63
|
+
# Support 'on' for readability of usage
|
64
|
+
alias_method :on, :on_page
|
65
|
+
|
60
66
|
#
|
61
67
|
# Navigate to a specific page following a predefined path.
|
62
68
|
#
|
@@ -13,14 +13,14 @@ module PageObject
|
|
13
13
|
# return true if an element is visible
|
14
14
|
#
|
15
15
|
def visible?
|
16
|
-
|
16
|
+
element.displayed?
|
17
17
|
end
|
18
18
|
|
19
19
|
#
|
20
20
|
# return true if an element exists
|
21
21
|
#
|
22
22
|
def exists?
|
23
|
-
not
|
23
|
+
not element.nil?
|
24
24
|
end
|
25
25
|
|
26
26
|
#
|
@@ -29,7 +29,7 @@ module PageObject
|
|
29
29
|
# @return [String]
|
30
30
|
#
|
31
31
|
def text
|
32
|
-
|
32
|
+
element.text
|
33
33
|
end
|
34
34
|
|
35
35
|
#
|
@@ -38,14 +38,14 @@ module PageObject
|
|
38
38
|
# @return [String]
|
39
39
|
#
|
40
40
|
def value
|
41
|
-
|
41
|
+
element.attribute('value')
|
42
42
|
end
|
43
43
|
|
44
44
|
#
|
45
45
|
# compare this element to another to determine if they are equal
|
46
46
|
#
|
47
47
|
def ==(other)
|
48
|
-
|
48
|
+
element == other.element
|
49
49
|
end
|
50
50
|
|
51
51
|
#
|
@@ -54,7 +54,7 @@ module PageObject
|
|
54
54
|
# @return [String]
|
55
55
|
#
|
56
56
|
def tag_name
|
57
|
-
|
57
|
+
element.tag_name
|
58
58
|
end
|
59
59
|
|
60
60
|
#
|
@@ -88,7 +88,7 @@ module PageObject
|
|
88
88
|
# attribute value
|
89
89
|
#
|
90
90
|
def attribute(attribute_name)
|
91
|
-
|
91
|
+
element.attribute attribute_name
|
92
92
|
end
|
93
93
|
|
94
94
|
#
|
@@ -97,8 +97,8 @@ module PageObject
|
|
97
97
|
def fire_event(event_name)
|
98
98
|
event_name = event_name.to_s.sub(/^on/, '').downcase
|
99
99
|
script = "return (%s).apply(null, arguments)" % ATOMS.fetch(:fireEvent)
|
100
|
-
bridge =
|
101
|
-
bridge.executeScript(script,
|
100
|
+
bridge = element.instance_variable_get(:@bridge)
|
101
|
+
bridge.executeScript(script, element, event_name)
|
102
102
|
end
|
103
103
|
|
104
104
|
#
|
@@ -106,9 +106,9 @@ module PageObject
|
|
106
106
|
#
|
107
107
|
def parent
|
108
108
|
script = "return (%s).apply(null, arguments)" % ATOMS.fetch(:getParentElement)
|
109
|
-
bridge =
|
110
|
-
parent = bridge.executeScript(script,
|
111
|
-
type =
|
109
|
+
bridge = element.instance_variable_get(:@bridge)
|
110
|
+
parent = bridge.executeScript(script, element)
|
111
|
+
type = element.attribute(:type).to_s.downcase if parent.tag_name.to_sym == :input
|
112
112
|
cls = ::PageObject::Elements.element_class_for(parent.tag_name, type)
|
113
113
|
cls.new(parent, :platform => :selenium_webdriver)
|
114
114
|
end
|
@@ -117,15 +117,15 @@ module PageObject
|
|
117
117
|
# Set the focus to the current element
|
118
118
|
#
|
119
119
|
def focus
|
120
|
-
bridge =
|
121
|
-
bridge.executeScript("return arguments[0].focus()",
|
120
|
+
bridge = element.instance_variable_get(:@bridge)
|
121
|
+
bridge.executeScript("return arguments[0].focus()", element)
|
122
122
|
end
|
123
123
|
|
124
124
|
#
|
125
125
|
# Click this element
|
126
126
|
#
|
127
127
|
def right_click
|
128
|
-
|
128
|
+
element.context_click
|
129
129
|
end
|
130
130
|
|
131
131
|
#
|
@@ -193,14 +193,14 @@ module PageObject
|
|
193
193
|
# @see Selenium::WebDriver::Keys::KEYS
|
194
194
|
#
|
195
195
|
def send_keys(*args)
|
196
|
-
|
196
|
+
element.send_keys(*args)
|
197
197
|
end
|
198
198
|
|
199
199
|
#
|
200
200
|
# clear the contents of the element
|
201
201
|
#
|
202
202
|
def clear
|
203
|
-
|
203
|
+
element.clear
|
204
204
|
end
|
205
205
|
end
|
206
206
|
end
|
@@ -121,6 +121,16 @@ module PageObject
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
+
#
|
125
|
+
# find the element that has focus
|
126
|
+
#
|
127
|
+
def element_with_focus
|
128
|
+
element = @browser.execute_script("return document.activeElement")
|
129
|
+
type = element.attribute(:type).to_s.downcase if element.tag_name.to_sym == :input
|
130
|
+
cls = ::PageObject::Elements.element_class_for(element.tag_name, type)
|
131
|
+
cls.new(element, :platform => :selenium_webdriver)
|
132
|
+
end
|
133
|
+
|
124
134
|
#
|
125
135
|
# platform method to switch to a frame and execute a block
|
126
136
|
# See PageObject#in_frame
|
@@ -795,6 +805,33 @@ module PageObject
|
|
795
805
|
find_selenium_elements(identifier, Elements::Paragraph, 'p')
|
796
806
|
end
|
797
807
|
|
808
|
+
#
|
809
|
+
# platform method to return the text for a label
|
810
|
+
# See PageObject::Accessors#label
|
811
|
+
#
|
812
|
+
def label_text_for(identifier)
|
813
|
+
process_selenium_call(identifier, Elements::Label, 'label') do |how, what|
|
814
|
+
@browser.find_element(how, what).text
|
815
|
+
end
|
816
|
+
end
|
817
|
+
|
818
|
+
|
819
|
+
#
|
820
|
+
# platform method to return a PageObject::Elements::Label element
|
821
|
+
# See PageObject::Accessors#label
|
822
|
+
#
|
823
|
+
def label_for(identifier)
|
824
|
+
find_selenium_element(identifier, Elements::Label, 'label')
|
825
|
+
end
|
826
|
+
|
827
|
+
|
828
|
+
#
|
829
|
+
# platform method to retrieve all label elements
|
830
|
+
#
|
831
|
+
def labels_for(identifier)
|
832
|
+
find_selenium_elements(identifier, Elements::Label, 'label')
|
833
|
+
end
|
834
|
+
|
798
835
|
#
|
799
836
|
# platform method to set the file on a file_field element
|
800
837
|
# See PageObject::Accessors#file_field
|
@@ -813,6 +850,22 @@ module PageObject
|
|
813
850
|
find_selenium_element(identifier, Elements::FileField, 'input', :type => 'file')
|
814
851
|
end
|
815
852
|
|
853
|
+
#
|
854
|
+
# platform method to retrieve a generic element
|
855
|
+
# See PageObject::Accessors#element
|
856
|
+
#
|
857
|
+
def element_for(tag, identifier)
|
858
|
+
find_selenium_element(identifier, Elements::FileField, tag.to_s)
|
859
|
+
end
|
860
|
+
|
861
|
+
#
|
862
|
+
# platform method to retrieve a collection of generic elements
|
863
|
+
# See PageObject::Accessors#elements
|
864
|
+
#
|
865
|
+
def elements_for(tag, identifier)
|
866
|
+
find_selenium_elements(identifier, Elements::FileField, tag.to_s)
|
867
|
+
end
|
868
|
+
|
816
869
|
private
|
817
870
|
|
818
871
|
def process_selenium_call(identifier, type, tag, other=nil)
|
@@ -868,7 +921,7 @@ module PageObject
|
|
868
921
|
['submit', 'image', 'button', 'reset'].include? additional[:type]
|
869
922
|
return false if identifier[:src] and tag == 'img'
|
870
923
|
return false if identifier[:text] and tag == 'input' and additional[:type] == 'hidden'
|
871
|
-
return false if identifier[:text] and ['div', 'span', 'td'].include? tag
|
924
|
+
return false if identifier[:text] and ['div', 'span', 'td', 'label'].include? tag
|
872
925
|
return false if identifier[:title] and tag == 'input' and additional[:type] == 'text'
|
873
926
|
return false if identifier[:title] and tag == 'input' and additional[:type] == 'file'
|
874
927
|
return false if identifier[:value] and tag == 'input' and
|
@@ -17,7 +17,7 @@ module PageObject
|
|
17
17
|
# Select a value from the list
|
18
18
|
#
|
19
19
|
def select(value)
|
20
|
-
|
20
|
+
element.send_keys(value)
|
21
21
|
end
|
22
22
|
|
23
23
|
#
|
@@ -57,7 +57,7 @@ module PageObject
|
|
57
57
|
private
|
58
58
|
|
59
59
|
def find_options
|
60
|
-
|
60
|
+
element.find_elements(:xpath, child_xpath)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -10,14 +10,14 @@ module PageObject
|
|
10
10
|
# return true if an element is visible
|
11
11
|
#
|
12
12
|
def visible?
|
13
|
-
|
13
|
+
element.present?
|
14
14
|
end
|
15
15
|
|
16
16
|
#
|
17
17
|
# return true if an element exists
|
18
18
|
#
|
19
19
|
def exists?
|
20
|
-
|
20
|
+
element.exists?
|
21
21
|
end
|
22
22
|
|
23
23
|
#
|
@@ -26,7 +26,7 @@ module PageObject
|
|
26
26
|
# @return [String]
|
27
27
|
#
|
28
28
|
def text
|
29
|
-
|
29
|
+
element.text
|
30
30
|
end
|
31
31
|
|
32
32
|
#
|
@@ -35,14 +35,14 @@ module PageObject
|
|
35
35
|
# @return [String]
|
36
36
|
#
|
37
37
|
def value
|
38
|
-
|
38
|
+
element.value
|
39
39
|
end
|
40
40
|
|
41
41
|
#
|
42
42
|
# compare this element to another to determine if they are equal
|
43
43
|
#
|
44
44
|
def ==(other)
|
45
|
-
|
45
|
+
element == other.element
|
46
46
|
end
|
47
47
|
|
48
48
|
#
|
@@ -51,7 +51,7 @@ module PageObject
|
|
51
51
|
# @return [String]
|
52
52
|
#
|
53
53
|
def tag_name
|
54
|
-
|
54
|
+
element.tag_name
|
55
55
|
end
|
56
56
|
|
57
57
|
#
|
@@ -85,22 +85,22 @@ module PageObject
|
|
85
85
|
# attribute value
|
86
86
|
#
|
87
87
|
def attribute(attribute_name)
|
88
|
-
|
88
|
+
element.attribute_value attribute_name
|
89
89
|
end
|
90
90
|
|
91
91
|
#
|
92
92
|
# Fire the provided event on the current element
|
93
93
|
#
|
94
94
|
def fire_event(event_name)
|
95
|
-
|
95
|
+
element.fire_event(event_name)
|
96
96
|
end
|
97
97
|
|
98
98
|
#
|
99
99
|
# find the parent element
|
100
100
|
#
|
101
101
|
def parent
|
102
|
-
parent =
|
103
|
-
type =
|
102
|
+
parent = element.parent
|
103
|
+
type = element.type if parent.tag_name.to_sym == :input
|
104
104
|
cls = ::PageObject::Elements.element_class_for(parent.tag_name, type)
|
105
105
|
cls.new(parent, :platform => :watir_webdriver)
|
106
106
|
end
|
@@ -109,7 +109,7 @@ module PageObject
|
|
109
109
|
# Set the focus to the current element
|
110
110
|
#
|
111
111
|
def focus
|
112
|
-
|
112
|
+
element.focus
|
113
113
|
end
|
114
114
|
|
115
115
|
#
|
@@ -118,7 +118,7 @@ module PageObject
|
|
118
118
|
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
119
119
|
#
|
120
120
|
def when_present(timeout=5)
|
121
|
-
|
121
|
+
element.wait_until_present(timeout)
|
122
122
|
self
|
123
123
|
end
|
124
124
|
|
@@ -171,14 +171,14 @@ module PageObject
|
|
171
171
|
# @see Selenium::WebDriver::Keys::KEYS
|
172
172
|
#
|
173
173
|
def send_keys(*args)
|
174
|
-
|
174
|
+
element.send_keys(*args)
|
175
175
|
end
|
176
176
|
|
177
177
|
#
|
178
178
|
# clear the contents of the element
|
179
179
|
#
|
180
180
|
def clear
|
181
|
-
|
181
|
+
element.clear
|
182
182
|
end
|
183
183
|
end
|
184
184
|
end
|