page-object 0.0.5 → 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +46 -1
- data/README.md +2 -0
- data/cucumber.yml +2 -2
- data/features/button.feature +11 -2
- data/features/check_box.feature +7 -5
- data/features/div.feature +7 -15
- data/features/{element.feature → element_attributes.feature} +1 -1
- data/features/form.feature +7 -6
- data/features/hidden_field.feature +9 -1
- data/features/html/static_elements.html +6 -1
- data/features/image.feature +9 -9
- data/features/link.feature +8 -1
- data/features/list_item.feature +6 -13
- data/features/ordered_list.feature +9 -17
- data/features/radio_button.feature +7 -6
- data/features/select_list.feature +12 -10
- data/features/span.feature +7 -15
- data/features/step_definitions/accessor_steps.rb +101 -26
- data/features/step_definitions/element_steps.rb +5 -0
- data/features/support/page.rb +36 -0
- data/features/table.feature +6 -15
- data/features/table_cell.feature +6 -12
- data/features/text_area.feature +7 -6
- data/features/text_field.feature +7 -6
- data/features/unordered_list.feature +9 -17
- data/lib/page-object/accessors.rb +93 -76
- data/lib/page-object/elements.rb +1 -0
- data/lib/page-object/elements/element.rb +76 -6
- data/lib/page-object/elements/option.rb +7 -0
- data/lib/page-object/elements/select_list.rb +24 -1
- data/lib/page-object/page_factory.rb +3 -3
- data/lib/page-object/platforms/selenium_select_list.rb +29 -0
- data/lib/page-object/platforms/watir_select_list.rb +30 -0
- data/lib/page-object/selenium_page_object.rb +53 -3
- data/lib/page-object/version.rb +1 -1
- data/lib/page-object/watir_page_object.rb +20 -1
- data/page-object.gemspec +2 -2
- data/spec/page-object/accessors_spec.rb +2 -2
- data/spec/page-object/elements/button_spec.rb +1 -1
- data/spec/page-object/elements/check_box_spec.rb +1 -1
- data/spec/page-object/elements/div_spec.rb +1 -1
- data/spec/page-object/elements/hidden_field_spec.rb +1 -1
- data/spec/page-object/elements/image_spec.rb +1 -1
- data/spec/page-object/elements/link_spec.rb +1 -1
- data/spec/page-object/elements/list_item_spec.rb +1 -1
- data/spec/page-object/elements/ordered_list_spec.rb +1 -1
- data/spec/page-object/elements/radio_button_spec.rb +1 -1
- data/spec/page-object/elements/select_list_spec.rb +43 -2
- data/spec/page-object/elements/span_spec.rb +1 -1
- data/spec/page-object/elements/table_row_spec.rb +5 -1
- data/spec/page-object/elements/table_spec.rb +1 -1
- data/spec/page-object/elements/text_area_spec.rb +1 -1
- data/spec/page-object/elements/text_field_spec.rb +1 -1
- data/spec/page-object/elements/unordered_list_spec.rb +1 -1
- metadata +9 -6
data/lib/page-object/elements.rb
CHANGED
@@ -17,16 +17,86 @@ module PageObject
|
|
17
17
|
|
18
18
|
# @private
|
19
19
|
def self.watir_identifier_for identifier
|
20
|
-
|
20
|
+
if should_build_watir_xpath(identifier)
|
21
|
+
how = :xpath
|
22
|
+
what = build_xpath_for(identifier)
|
23
|
+
return how => what
|
24
|
+
end
|
25
|
+
all_identities = {}
|
26
|
+
identifier.each do |key, value|
|
27
|
+
each = {key => value}
|
28
|
+
ident = identifier_for each, watir_finders, watir_mapping
|
29
|
+
all_identities[ident.keys.first] = ident.values.first
|
30
|
+
end
|
31
|
+
all_identities
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.should_build_watir_xpath identifier
|
35
|
+
['table', 'span', 'div', 'td', 'li', 'ul', 'ol'].include? identifier[:tag_name] and identifier[:name]
|
21
36
|
end
|
22
37
|
|
23
38
|
# @private
|
24
39
|
def self.selenium_identifier_for identifier
|
25
|
-
|
26
|
-
|
40
|
+
if identifier.length == 1
|
41
|
+
identifier = identifier_for identifier, selenium_finders, selenium_mapping
|
42
|
+
return identifier.keys.first, identifier.values.first
|
43
|
+
elsif identifier.length > 1
|
44
|
+
how = :xpath
|
45
|
+
what = build_xpath_for identifier
|
46
|
+
return how, what
|
47
|
+
end
|
27
48
|
end
|
28
|
-
|
49
|
+
|
29
50
|
protected
|
51
|
+
|
52
|
+
def self.build_xpath_for identifier
|
53
|
+
tag_locator = identifier.delete(:tag_name)
|
54
|
+
idx = identifier.delete(:index)
|
55
|
+
identifier.delete(:tag_name)
|
56
|
+
xpath = ".//#{tag_locator}"
|
57
|
+
xpath << "[#{attribute_expression(identifier)}]" unless identifier.empty?
|
58
|
+
xpath << "[#{idx+1}]" if idx
|
59
|
+
xpath
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.attribute_expression(identifier)
|
63
|
+
identifier.map do |key, value|
|
64
|
+
if value.kind_of?(Array)
|
65
|
+
"(" + value.map { |v| equal_pair(key, v) }.join(" or ") + ")"
|
66
|
+
else
|
67
|
+
equal_pair(key, value)
|
68
|
+
end
|
69
|
+
end.join(" and ")
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.equal_pair(key, value)
|
73
|
+
if key == :label
|
74
|
+
"@id=//label[normalize-space()=#{xpath_string(value)}]/@for"
|
75
|
+
else
|
76
|
+
"#{lhs_for(key)}=#{xpath_string(value)}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.lhs_for(key)
|
81
|
+
case key
|
82
|
+
when :text, 'text'
|
83
|
+
'normalize-space()'
|
84
|
+
when :href
|
85
|
+
'normalize-space(@href)'
|
86
|
+
else
|
87
|
+
"@#{key.to_s.gsub("_", "-")}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.xpath_string(value)
|
92
|
+
if value.include? "'"
|
93
|
+
parts = value.split("'", -1).map { |part| "'#{part}'" }
|
94
|
+
string = parts.join(%{,"'",})
|
95
|
+
"concat(#{string})"
|
96
|
+
else
|
97
|
+
"'#{value}'"
|
98
|
+
end
|
99
|
+
end
|
30
100
|
|
31
101
|
def self.identifier_for identifier, find_by, find_by_mapping
|
32
102
|
how, what = identifier.keys.first, identifier.values.first
|
@@ -44,7 +114,7 @@ module PageObject
|
|
44
114
|
end
|
45
115
|
|
46
116
|
def self.selenium_finders
|
47
|
-
[:class, :id, :name, :xpath]
|
117
|
+
[:class, :id, :name, :xpath, :index]
|
48
118
|
end
|
49
119
|
|
50
120
|
def self.selenium_mapping
|
@@ -64,4 +134,4 @@ module PageObject
|
|
64
134
|
end
|
65
135
|
end
|
66
136
|
end
|
67
|
-
end
|
137
|
+
end
|
@@ -2,11 +2,34 @@ module PageObject
|
|
2
2
|
module Elements
|
3
3
|
class SelectList < Element
|
4
4
|
|
5
|
+
def initialize(element, platform)
|
6
|
+
@element = element
|
7
|
+
include_platform_for platform
|
8
|
+
end
|
9
|
+
|
5
10
|
protected
|
11
|
+
|
12
|
+
def child_xpath
|
13
|
+
".//child::option"
|
14
|
+
end
|
6
15
|
|
7
16
|
def self.watir_finders
|
8
17
|
super + [:text, :value]
|
9
18
|
end
|
19
|
+
|
20
|
+
def include_platform_for platform
|
21
|
+
super
|
22
|
+
if platform[:platform] == :watir
|
23
|
+
require 'page-object/platforms/watir_select_list'
|
24
|
+
self.class.send :include, PageObject::Platforms::WatirSelectList
|
25
|
+
elsif platform[:platform] == :selenium
|
26
|
+
require 'page-object/platforms/selenium_select_list'
|
27
|
+
self.class.send :include, PageObject::Platforms::SeleniumSelectList
|
28
|
+
else
|
29
|
+
raise ArgumentError, "expect platform to be :watir or :selenium"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
10
33
|
end
|
11
34
|
end
|
12
|
-
end
|
35
|
+
end
|
@@ -35,9 +35,9 @@ module PageObject
|
|
35
35
|
#
|
36
36
|
# Create a page object.
|
37
37
|
#
|
38
|
-
# @param [PageObject]
|
39
|
-
# @param [
|
40
|
-
# @param an optional block to be called
|
38
|
+
# @param [PageObject] a class that has included the PageObject module
|
39
|
+
# @param [Boolean] a boolean indicating if the page should be visited? default is false.
|
40
|
+
# @param [block] an optional block to be called
|
41
41
|
# @return [PageObject] the newly created page object
|
42
42
|
#
|
43
43
|
def on_page(page_class, visit=false, &block)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Platforms
|
3
|
+
module SeleniumSelectList
|
4
|
+
|
5
|
+
#
|
6
|
+
# Return the PageObject::Elements::Option for the index provided. Index
|
7
|
+
# is zero based.
|
8
|
+
#
|
9
|
+
# @return [PageObject::Elements::Option]
|
10
|
+
#
|
11
|
+
def [](idx)
|
12
|
+
options[idx]
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Return an array of Options contained in the select lit.
|
17
|
+
#
|
18
|
+
# @return [array of PageObject::Elements::Option]
|
19
|
+
def options
|
20
|
+
options = @element.find_elements(:xpath, child_xpath)
|
21
|
+
elements = []
|
22
|
+
options.each do |opt|
|
23
|
+
elements << PageObject::Elements::Option.new(opt, :platform => :selenium)
|
24
|
+
end
|
25
|
+
elements
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Platforms
|
3
|
+
module WatirSelectList
|
4
|
+
|
5
|
+
#
|
6
|
+
# Return the PageObject::Elements::Option for the index provided. Index
|
7
|
+
# is zero based.
|
8
|
+
#
|
9
|
+
# @return [PageObject::Elements::Option]
|
10
|
+
#
|
11
|
+
def [](idx)
|
12
|
+
PageObject::Elements::Option.new(options[idx], :platform => :watir)
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Return an array of Options contained in the select lit.
|
17
|
+
#
|
18
|
+
# @return [array of PageObject::Elements::Option]
|
19
|
+
#
|
20
|
+
def options
|
21
|
+
elements = []
|
22
|
+
options = @element.wd.find_elements(:xpath, child_xpath)
|
23
|
+
options.each do |opt|
|
24
|
+
elements << PageObject::Elements::Option.new(opt, :platform => :watir)
|
25
|
+
end
|
26
|
+
elements
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -48,6 +48,7 @@ module PageObject
|
|
48
48
|
# See PageObject::Accessors#text_field
|
49
49
|
#
|
50
50
|
def text_field_value_for(identifier)
|
51
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'text'
|
51
52
|
how, what = Elements::TextField.selenium_identifier_for identifier
|
52
53
|
@browser.find_element(how, what).attribute('value')
|
53
54
|
end
|
@@ -57,6 +58,7 @@ module PageObject
|
|
57
58
|
# See PageObject::Accessors#text_field
|
58
59
|
#
|
59
60
|
def text_field_value_set(identifier, value)
|
61
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'text'
|
60
62
|
how, what = Elements::TextField.selenium_identifier_for identifier
|
61
63
|
@browser.find_element(how, what).send_keys(value)
|
62
64
|
end
|
@@ -66,6 +68,7 @@ module PageObject
|
|
66
68
|
# See PageObject::Accessors#text_field
|
67
69
|
#
|
68
70
|
def text_field_for(identifier)
|
71
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'text'
|
69
72
|
how, what = Elements::TextField.selenium_identifier_for identifier
|
70
73
|
element = @browser.find_element(how, what)
|
71
74
|
PageObject::Elements::TextField.new(element, :platform => :selenium)
|
@@ -76,6 +79,7 @@ module PageObject
|
|
76
79
|
# See PageObject::Accessors#hidden_field
|
77
80
|
#
|
78
81
|
def hidden_field_value_for(identifier)
|
82
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'hidden'
|
79
83
|
how, what = Elements::HiddenField.selenium_identifier_for identifier
|
80
84
|
@browser.find_element(how, what).attribute('value')
|
81
85
|
end
|
@@ -85,6 +89,7 @@ module PageObject
|
|
85
89
|
# See PageObject::Accessors#hidden_field
|
86
90
|
#
|
87
91
|
def hidden_field_for(identifier)
|
92
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'hidden'
|
88
93
|
how, what = Elements::HiddenField.selenium_identifier_for identifier
|
89
94
|
element = @browser.find_element(how, what)
|
90
95
|
Elements::HiddenField.new(element, :platform => :selenium)
|
@@ -95,6 +100,7 @@ module PageObject
|
|
95
100
|
# See PageObject::Accessors#text_area
|
96
101
|
#
|
97
102
|
def text_area_value_set(identifier, value)
|
103
|
+
identifier = add_tagname_if_needed identifier, 'textarea'
|
98
104
|
how, what = Elements::TextArea.selenium_identifier_for identifier
|
99
105
|
@browser.find_element(how, what).send_keys(value)
|
100
106
|
end
|
@@ -104,6 +110,7 @@ module PageObject
|
|
104
110
|
# See PageObject::Accessors#text_area
|
105
111
|
#
|
106
112
|
def text_area_value_for(identifier)
|
113
|
+
identifier = add_tagname_if_needed identifier, 'textarea'
|
107
114
|
how, what = Elements::TextArea.selenium_identifier_for identifier
|
108
115
|
@browser.find_element(how, what).attribute('value')
|
109
116
|
end
|
@@ -113,6 +120,7 @@ module PageObject
|
|
113
120
|
# See PageObject::Accessors#text_area
|
114
121
|
#
|
115
122
|
def text_area_for(identifier)
|
123
|
+
identifier = add_tagname_if_needed identifier, 'textarea'
|
116
124
|
how, what = Elements::TextArea.selenium_identifier_for identifier
|
117
125
|
element = @browser.find_element(how, what)
|
118
126
|
Elements::TextArea.new(element, :platform => :selenium)
|
@@ -123,6 +131,7 @@ module PageObject
|
|
123
131
|
# See PageObject::Accessors#select_list
|
124
132
|
#
|
125
133
|
def select_list_value_for(identifier)
|
134
|
+
identifier = add_tagname_if_needed identifier, 'select'
|
126
135
|
how, what = Elements::SelectList.selenium_identifier_for identifier
|
127
136
|
@browser.find_element(how, what).attribute('value')
|
128
137
|
end
|
@@ -132,6 +141,7 @@ module PageObject
|
|
132
141
|
# See PageObject::Accessors#select_list
|
133
142
|
#
|
134
143
|
def select_list_value_set(identifier, value)
|
144
|
+
identifier = add_tagname_if_needed identifier, 'select'
|
135
145
|
how, what = Elements::SelectList.selenium_identifier_for identifier
|
136
146
|
@browser.find_element(how, what).send_keys(value)
|
137
147
|
end
|
@@ -141,6 +151,7 @@ module PageObject
|
|
141
151
|
# See PageObject::Accessors#select_list
|
142
152
|
#
|
143
153
|
def select_list_for(identifier)
|
154
|
+
identifier = add_tagname_if_needed identifier, 'select'
|
144
155
|
how, what = Elements::SelectList.selenium_identifier_for identifier
|
145
156
|
element = @browser.find_element(how, what)
|
146
157
|
Elements::SelectList.new(element, :platform => :selenium)
|
@@ -151,6 +162,7 @@ module PageObject
|
|
151
162
|
# See PageObject::Accessors#link
|
152
163
|
#
|
153
164
|
def click_link_for(identifier)
|
165
|
+
identifier = add_tagname_if_needed identifier, "a"
|
154
166
|
how, what = Elements::Link.selenium_identifier_for identifier
|
155
167
|
@browser.find_element(how, what).click
|
156
168
|
end
|
@@ -160,6 +172,7 @@ module PageObject
|
|
160
172
|
# see PageObject::Accessors#link
|
161
173
|
#
|
162
174
|
def link_for(identifier)
|
175
|
+
identifier = add_tagname_if_needed identifier, "a"
|
163
176
|
how, what = Elements::Link.selenium_identifier_for identifier
|
164
177
|
element = @browser.find_element(how, what)
|
165
178
|
Elements::Link.new(element, :platform => :selenium)
|
@@ -170,8 +183,9 @@ module PageObject
|
|
170
183
|
# See PageObject::Accessors#checkbox
|
171
184
|
#
|
172
185
|
def check_checkbox(identifier)
|
186
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
|
173
187
|
how, what = Elements::CheckBox.selenium_identifier_for identifier
|
174
|
-
@browser.find_element(how, what).
|
188
|
+
@browser.find_element(how, what).click unless @browser.find_element(how, what).selected?
|
175
189
|
end
|
176
190
|
|
177
191
|
#
|
@@ -179,8 +193,9 @@ module PageObject
|
|
179
193
|
# See PageObject::Accessors#checkbox
|
180
194
|
#
|
181
195
|
def uncheck_checkbox(identifier)
|
196
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
|
182
197
|
how, what = Elements::CheckBox.selenium_identifier_for identifier
|
183
|
-
@browser.find_element(how, what).
|
198
|
+
@browser.find_element(how, what).click if @browser.find_element(how, what).selected?
|
184
199
|
end
|
185
200
|
|
186
201
|
#
|
@@ -188,6 +203,7 @@ module PageObject
|
|
188
203
|
# See PageObject::Accessors#checkbox
|
189
204
|
#
|
190
205
|
def checkbox_checked?(identifier)
|
206
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
|
191
207
|
how, what = Elements::CheckBox.selenium_identifier_for identifier
|
192
208
|
@browser.find_element(how, what).selected?
|
193
209
|
end
|
@@ -197,6 +213,7 @@ module PageObject
|
|
197
213
|
# See PageObject::Accessors#checkbox
|
198
214
|
#
|
199
215
|
def checkbox_for(identifier)
|
216
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
|
200
217
|
how, what = Elements::CheckBox.selenium_identifier_for identifier
|
201
218
|
element = @browser.find_element(how, what)
|
202
219
|
Elements::CheckBox.new(element, :platform => :selenium)
|
@@ -207,6 +224,7 @@ module PageObject
|
|
207
224
|
# See PageObject::Accessors#radio_button
|
208
225
|
#
|
209
226
|
def select_radio(identifier)
|
227
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
|
210
228
|
how, what = Elements::RadioButton.selenium_identifier_for identifier
|
211
229
|
@browser.find_element(how, what).click unless @browser.find_element(how, what).selected?
|
212
230
|
end
|
@@ -216,6 +234,7 @@ module PageObject
|
|
216
234
|
# See PageObject::Accessors#radio_button
|
217
235
|
#
|
218
236
|
def clear_radio(identifier)
|
237
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
|
219
238
|
how, what = Elements::RadioButton.selenium_identifier_for identifier
|
220
239
|
@browser.find_element(how, what).click if @browser.find_element(how, what).selected?
|
221
240
|
end
|
@@ -225,6 +244,7 @@ module PageObject
|
|
225
244
|
# See PageObject::Accessors#radio_button
|
226
245
|
#
|
227
246
|
def radio_selected?(identifier)
|
247
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
|
228
248
|
how, what = Elements::RadioButton.selenium_identifier_for identifier
|
229
249
|
@browser.find_element(how, what).selected?
|
230
250
|
end
|
@@ -234,6 +254,7 @@ module PageObject
|
|
234
254
|
# See PageObject::Accessors#radio_button
|
235
255
|
#
|
236
256
|
def radio_button_for(identifier)
|
257
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
|
237
258
|
how, what = Elements::RadioButton.selenium_identifier_for identifier
|
238
259
|
element = @browser.find_element(how, what)
|
239
260
|
PageObject::Elements::RadioButton.new(element, :platform => :selenium)
|
@@ -244,6 +265,7 @@ module PageObject
|
|
244
265
|
# See PageObject::Accessors#div
|
245
266
|
#
|
246
267
|
def div_text_for(identifier)
|
268
|
+
identifier = add_tagname_if_needed identifier, 'div'
|
247
269
|
how, what = Elements::Div.selenium_identifier_for identifier
|
248
270
|
@browser.find_element(how, what).text
|
249
271
|
end
|
@@ -253,6 +275,7 @@ module PageObject
|
|
253
275
|
# See PageObject::Accessors#div
|
254
276
|
#
|
255
277
|
def div_for(identifier)
|
278
|
+
identifier = add_tagname_if_needed identifier, 'div'
|
256
279
|
how, what = Elements::Div.selenium_identifier_for identifier
|
257
280
|
element = @browser.find_element(how, what)
|
258
281
|
PageObject::Elements::Div.new(element, :platform => :selenium)
|
@@ -263,6 +286,7 @@ module PageObject
|
|
263
286
|
# See PageObject::Accessors#span
|
264
287
|
#
|
265
288
|
def span_text_for(identifier)
|
289
|
+
identifier = add_tagname_if_needed identifier, 'span'
|
266
290
|
how, what = Elements::Span.selenium_identifier_for identifier
|
267
291
|
@browser.find_element(how, what).text
|
268
292
|
end
|
@@ -272,6 +296,7 @@ module PageObject
|
|
272
296
|
# See PageObject::Accessors#span
|
273
297
|
#
|
274
298
|
def span_for(identifier)
|
299
|
+
identifier = add_tagname_if_needed identifier, 'span'
|
275
300
|
how, what = Elements::Span.selenium_identifier_for identifier
|
276
301
|
element = @browser.find_element(how, what)
|
277
302
|
PageObject::Elements::Span.new(element, :platform => :selenium)
|
@@ -282,6 +307,7 @@ module PageObject
|
|
282
307
|
# See PageObject::Accessors#button
|
283
308
|
#
|
284
309
|
def click_button_for(identifier)
|
310
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'submit'
|
285
311
|
how, what = Elements::Button.selenium_identifier_for identifier
|
286
312
|
@browser.find_element(how, what).click
|
287
313
|
end
|
@@ -291,6 +317,7 @@ module PageObject
|
|
291
317
|
# See PageObject::Accessors#button
|
292
318
|
#
|
293
319
|
def button_for(identifier)
|
320
|
+
identifier = add_tagname_if_needed identifier, 'input', :type => 'submit'
|
294
321
|
how, what = Elements::Button.selenium_identifier_for identifier
|
295
322
|
element = @browser.find_element(how, what)
|
296
323
|
PageObject::Elements::Button.new(element, :platform => :selenium)
|
@@ -301,6 +328,7 @@ module PageObject
|
|
301
328
|
# See PageObject::Accessors#table
|
302
329
|
#
|
303
330
|
def table_for(identifier)
|
331
|
+
identifier = add_tagname_if_needed identifier, 'table'
|
304
332
|
how, what = Elements::Table.selenium_identifier_for identifier
|
305
333
|
element = @browser.find_element(how, what)
|
306
334
|
PageObject::Elements::Table.new(element, :platform => :selenium)
|
@@ -311,6 +339,7 @@ module PageObject
|
|
311
339
|
# See PageObject::Accessors#cell
|
312
340
|
#
|
313
341
|
def cell_text_for(identifier)
|
342
|
+
identifier = add_tagname_if_needed identifier, 'td'
|
314
343
|
how, what = Elements::TableCell.selenium_identifier_for identifier
|
315
344
|
@browser.find_element(how, what).text
|
316
345
|
end
|
@@ -320,6 +349,7 @@ module PageObject
|
|
320
349
|
# See PageObject::Accessors#cell
|
321
350
|
#
|
322
351
|
def cell_for(identifier)
|
352
|
+
identifier = add_tagname_if_needed identifier, 'td'
|
323
353
|
how, what = Elements::TableCell.selenium_identifier_for identifier
|
324
354
|
element = @browser.find_element(how, what)
|
325
355
|
PageObject::Elements::TableCell.new(element, :platform => :selenium)
|
@@ -330,6 +360,7 @@ module PageObject
|
|
330
360
|
# See PageObject::Accessors#image
|
331
361
|
#
|
332
362
|
def image_for(identifier)
|
363
|
+
identifier = add_tagname_if_needed identifier, 'img'
|
333
364
|
how, what = Elements::Image.selenium_identifier_for identifier
|
334
365
|
element = @browser.find_element(how, what)
|
335
366
|
PageObject::Elements::Image.new(element, :platform => :selenium)
|
@@ -340,6 +371,7 @@ module PageObject
|
|
340
371
|
# See PageObject::Accessors#form
|
341
372
|
#
|
342
373
|
def form_for(identifier)
|
374
|
+
identifier = add_tagname_if_needed identifier, 'form'
|
343
375
|
how, what = Elements::Form.selenium_identifier_for identifier
|
344
376
|
element = @browser.find_element(how, what)
|
345
377
|
PageObject::Elements::Form.new(element, :platform => :selenium)
|
@@ -350,6 +382,7 @@ module PageObject
|
|
350
382
|
# See PageObject::Accessors#list_item
|
351
383
|
#
|
352
384
|
def list_item_text_for(identifier)
|
385
|
+
identifier = add_tagname_if_needed identifier, 'li'
|
353
386
|
how, what = Elements::ListItem.selenium_identifier_for identifier
|
354
387
|
@browser.find_element(how, what).text
|
355
388
|
end
|
@@ -359,7 +392,8 @@ module PageObject
|
|
359
392
|
# See PageObject::Accessors#list_item
|
360
393
|
#
|
361
394
|
def list_item_for(identifier)
|
362
|
-
|
395
|
+
identifier = add_tagname_if_needed identifier, 'li'
|
396
|
+
how, what = Elements::ListItem.selenium_identifier_for identifier
|
363
397
|
element = @browser.find_element(how, what)
|
364
398
|
PageObject::Elements::ListItem.new(element, :platform => :selenium)
|
365
399
|
end
|
@@ -369,6 +403,7 @@ module PageObject
|
|
369
403
|
# See PageObject::Accessors#unordered_list
|
370
404
|
#
|
371
405
|
def unordered_list_for(identifier)
|
406
|
+
identifier = add_tagname_if_needed identifier, 'ul'
|
372
407
|
how, what = Elements::UnorderedList.selenium_identifier_for identifier
|
373
408
|
element = @browser.find_element(how, what)
|
374
409
|
PageObject::Elements::UnorderedList.new(element, :platform => :selenium)
|
@@ -379,9 +414,24 @@ module PageObject
|
|
379
414
|
# See PageObject::Accessors#ordered_list
|
380
415
|
#
|
381
416
|
def ordered_list_for(identifier)
|
417
|
+
identifier = add_tagname_if_needed identifier, 'ol'
|
382
418
|
how, what = Elements::OrderedList.selenium_identifier_for identifier
|
383
419
|
element = @browser.find_element(how, what)
|
384
420
|
PageObject::Elements::OrderedList.new(element, :platform => :selenium)
|
385
421
|
end
|
422
|
+
|
423
|
+
private
|
424
|
+
|
425
|
+
def add_tagname_if_needed identifier, tag, additional=nil
|
426
|
+
return identifier if identifier.length < 2 and identifier[:index].nil?
|
427
|
+
identifier[:tag_name] = tag
|
428
|
+
if additional
|
429
|
+
additional.each do |key, value|
|
430
|
+
identifier[key] = value
|
431
|
+
end
|
432
|
+
end
|
433
|
+
identifier
|
434
|
+
end
|
435
|
+
|
386
436
|
end
|
387
437
|
end
|