page-object 0.2 → 0.2.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.
Files changed (134) hide show
  1. data/.gitignore +1 -0
  2. data/.rvmrc +1 -1
  3. data/ChangeLog +12 -6
  4. data/README.md +1 -1
  5. data/Rakefile +3 -19
  6. data/features/async.feature +8 -8
  7. data/features/button.feature +7 -7
  8. data/features/check_box.feature +8 -8
  9. data/features/div.feature +7 -6
  10. data/features/element_attributes.feature +14 -14
  11. data/features/form.feature +5 -5
  12. data/features/frames.feature +12 -0
  13. data/features/hidden_field.feature +5 -5
  14. data/features/html/frame_1.html +18 -0
  15. data/features/html/frame_2.html +16 -0
  16. data/features/html/frames.html +11 -0
  17. data/features/html/iframes.html +12 -0
  18. data/features/html/static_elements.html +50 -42
  19. data/features/html/success.html +5 -5
  20. data/features/image.feature +11 -11
  21. data/features/link.feature +1 -1
  22. data/features/list_item.feature +5 -5
  23. data/features/ordered_list.feature +6 -6
  24. data/features/page_level_actions.feature +16 -5
  25. data/features/radio_button.feature +12 -12
  26. data/features/select_list.feature +12 -12
  27. data/features/span.feature +5 -5
  28. data/features/step_definitions/accessor_steps.rb +2 -2
  29. data/features/step_definitions/async_steps.rb +1 -1
  30. data/features/step_definitions/element_steps.rb +1 -1
  31. data/features/step_definitions/frames_steps.rb +21 -0
  32. data/features/step_definitions/page_level_actions_steps.rb +24 -2
  33. data/features/step_definitions/page_traversal_steps.rb +0 -1
  34. data/features/support/env.rb +20 -6
  35. data/features/support/page.rb +14 -11
  36. data/features/support/url_helper.rb +4 -0
  37. data/features/table.feature +9 -9
  38. data/features/table_cell.feature +6 -6
  39. data/features/text_area.feature +6 -6
  40. data/features/text_field.feature +7 -7
  41. data/features/unordered_list.feature +6 -6
  42. data/lib/page-object.rb +40 -16
  43. data/lib/page-object/accessors.rb +15 -15
  44. data/lib/page-object/elements.rb +0 -1
  45. data/lib/page-object/elements/button.rb +24 -24
  46. data/lib/page-object/elements/div.rb +8 -3
  47. data/lib/page-object/elements/element.rb +27 -28
  48. data/lib/page-object/elements/form.rb +7 -7
  49. data/lib/page-object/elements/hidden_field.rb +5 -5
  50. data/lib/page-object/elements/image.rb +8 -8
  51. data/lib/page-object/elements/link.rb +9 -9
  52. data/lib/page-object/elements/list_item.rb +1 -1
  53. data/lib/page-object/elements/option.rb +1 -1
  54. data/lib/page-object/elements/ordered_list.rb +13 -13
  55. data/lib/page-object/elements/select_list.rb +6 -6
  56. data/lib/page-object/elements/span.rb +2 -2
  57. data/lib/page-object/elements/table.rb +11 -11
  58. data/lib/page-object/elements/table_row.rb +9 -9
  59. data/lib/page-object/elements/text_area.rb +4 -4
  60. data/lib/page-object/elements/text_field.rb +4 -4
  61. data/lib/page-object/elements/unordered_list.rb +13 -13
  62. data/lib/page-object/loads_platform.rb +24 -0
  63. data/lib/page-object/page_factory.rb +3 -3
  64. data/lib/page-object/platforms.rb +18 -0
  65. data/lib/page-object/platforms/selenium.rb +16 -0
  66. data/lib/page-object/platforms/selenium/button.rb +15 -0
  67. data/lib/page-object/platforms/selenium/element.rb +168 -0
  68. data/lib/page-object/platforms/selenium/form.rb +16 -0
  69. data/lib/page-object/platforms/selenium/image.rb +28 -0
  70. data/lib/page-object/platforms/selenium/link.rb +16 -0
  71. data/lib/page-object/platforms/selenium/ordered_list.rb +33 -0
  72. data/lib/page-object/platforms/selenium/page_object.rb +524 -0
  73. data/lib/page-object/platforms/selenium/select_list.rb +32 -0
  74. data/lib/page-object/platforms/selenium/table.rb +40 -0
  75. data/lib/page-object/platforms/selenium/table_row.rb +32 -0
  76. data/lib/page-object/platforms/selenium/unordered_list.rb +33 -0
  77. data/lib/page-object/platforms/watir.rb +16 -0
  78. data/lib/page-object/platforms/watir/element.rb +154 -0
  79. data/lib/page-object/platforms/watir/form.rb +16 -0
  80. data/lib/page-object/platforms/watir/image.rb +22 -0
  81. data/lib/page-object/platforms/watir/ordered_list.rb +32 -0
  82. data/lib/page-object/{watir_page_object.rb → platforms/watir/page_object.rb} +62 -35
  83. data/lib/page-object/platforms/watir/select_list.rb +33 -0
  84. data/lib/page-object/platforms/watir/table.rb +27 -0
  85. data/lib/page-object/platforms/watir/table_row.rb +24 -0
  86. data/lib/page-object/platforms/watir/unordered_list.rb +33 -0
  87. data/lib/page-object/version.rb +1 -1
  88. data/page-object.gemspec +13 -13
  89. data/spec/page-object/accessors_spec.rb +142 -108
  90. data/spec/page-object/elements/button_spec.rb +33 -33
  91. data/spec/page-object/elements/check_box_spec.rb +1 -1
  92. data/spec/page-object/elements/div_spec.rb +3 -3
  93. data/spec/page-object/elements/element_spec.rb +51 -41
  94. data/spec/page-object/elements/form_spec.rb +3 -3
  95. data/spec/page-object/elements/hidden_field_spec.rb +3 -3
  96. data/spec/page-object/elements/image_spec.rb +7 -7
  97. data/spec/page-object/elements/link_spec.rb +8 -8
  98. data/spec/page-object/elements/list_item_spec.rb +1 -1
  99. data/spec/page-object/elements/ordered_list_spec.rb +9 -9
  100. data/spec/page-object/elements/radio_button_spec.rb +1 -1
  101. data/spec/page-object/elements/select_list_spec.rb +2 -2
  102. data/spec/page-object/elements/span_spec.rb +1 -1
  103. data/spec/page-object/elements/table_row_spec.rb +6 -6
  104. data/spec/page-object/elements/table_spec.rb +9 -9
  105. data/spec/page-object/elements/text_area_spec.rb +3 -3
  106. data/spec/page-object/elements/text_field_spec.rb +3 -3
  107. data/spec/page-object/elements/unordered_list_spec.rb +10 -10
  108. data/spec/page-object/loads_platform_spec.rb +38 -0
  109. data/spec/page-object/page-object_spec.rb +70 -10
  110. data/spec/page-object/page_factory_spec.rb +3 -3
  111. data/spec/page-object/{selenium_page_object_spec.rb → platforms/selenium/selenium_page_object_spec.rb} +10 -3
  112. data/spec/page-object/platforms/selenium_spec.rb +26 -0
  113. data/spec/page-object/platforms/watir_spec.rb +27 -0
  114. data/spec/spec_helper.rb +18 -5
  115. metadata +48 -26
  116. data/lib/page-object/platforms/selenium_button.rb +0 -13
  117. data/lib/page-object/platforms/selenium_element.rb +0 -142
  118. data/lib/page-object/platforms/selenium_form.rb +0 -14
  119. data/lib/page-object/platforms/selenium_image.rb +0 -26
  120. data/lib/page-object/platforms/selenium_link.rb +0 -13
  121. data/lib/page-object/platforms/selenium_ordered_list.rb +0 -31
  122. data/lib/page-object/platforms/selenium_select_list.rb +0 -29
  123. data/lib/page-object/platforms/selenium_table.rb +0 -38
  124. data/lib/page-object/platforms/selenium_table_row.rb +0 -29
  125. data/lib/page-object/platforms/selenium_unordered_list.rb +0 -31
  126. data/lib/page-object/platforms/watir_element.rb +0 -136
  127. data/lib/page-object/platforms/watir_form.rb +0 -14
  128. data/lib/page-object/platforms/watir_image.rb +0 -20
  129. data/lib/page-object/platforms/watir_ordered_list.rb +0 -30
  130. data/lib/page-object/platforms/watir_select_list.rb +0 -30
  131. data/lib/page-object/platforms/watir_table.rb +0 -24
  132. data/lib/page-object/platforms/watir_table_row.rb +0 -22
  133. data/lib/page-object/platforms/watir_unordered_list.rb +0 -31
  134. data/lib/page-object/selenium_page_object.rb +0 -486
@@ -1,24 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module WatirTable
4
-
5
- #
6
- # Return the PageObject::Elements::TableRow for the index provided. Index
7
- # is zero based.
8
- #
9
- # @return [PageObject::Elements::TableRow]
10
- #
11
- def [](idx)
12
- PageObject::Elements::TableRow.new(@element[idx], :platform => :watir)
13
- end
14
-
15
- #
16
- # Returns the number of rows in the table.
17
- #
18
- def rows
19
- element.wd.find_elements(:xpath, child_xpath).size
20
- end
21
-
22
- end
23
- end
24
- end
@@ -1,22 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module WatirTableRow
4
-
5
- #
6
- # Return the PageObject::Elements::TableCell for the index provided. Index
7
- # is zero based.
8
- #
9
- def [](idx)
10
- PageObject::Elements::TableCell.new(element[idx], :platform => :watir)
11
- end
12
-
13
- #
14
- # Returns the number of columns in the table.
15
- #
16
- def columns
17
- element.wd.find_elements(:xpath, child_xpath).size
18
- end
19
-
20
- end
21
- end
22
- end
@@ -1,31 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module WatirUnorderedList
4
-
5
- #
6
- # Return the PageObject::Elements::ListItem for the index provided. Index
7
- # is zero based.
8
- #
9
- # @return [PageObject::Elements::ListItem]
10
- #
11
- def [](idx)
12
- eles = list_items
13
- PageObject::Elements::ListItem.new(eles[idx], :platform => :watir)
14
- end
15
-
16
- #
17
- # Return the number of items contained in the unordered list
18
- #
19
- def items
20
- list_items.size
21
- end
22
-
23
- private
24
-
25
- def list_items
26
- element.wd.find_elements(:xpath, child_xpath)
27
- end
28
-
29
- end
30
- end
31
- end
@@ -1,486 +0,0 @@
1
- require 'page-object/elements'
2
-
3
- module PageObject
4
- #
5
- # Selenium implementation of the page object platform driver. You should not use the
6
- # class directly. Instead you should include the PageObject module in your page object
7
- # and use the methods dynamically added from the PageObject::Accessors module.
8
- #
9
- class SeleniumPageObject
10
- def initialize(browser)
11
- @browser = browser
12
- end
13
-
14
- #
15
- # platform method to navigate to a provided url
16
- # See PageObject#navigate_to
17
- #
18
- def navigate_to(url)
19
- @browser.navigate.to url
20
- end
21
-
22
- #
23
- # platform method to retrieve the text from the current page
24
- # See PageObject#text
25
- #
26
- def text
27
- @browser.find_element(:tag_name, 'body').text
28
- end
29
-
30
- #
31
- # platform method to retrieve the html for the current page
32
- # See PageObject#html
33
- #
34
- def html
35
- @browser.page_source
36
- end
37
-
38
- #
39
- # platform method to retrieve the title for the current page
40
- # See PageObject#title
41
- #
42
- def title
43
- @browser.title
44
- end
45
-
46
- #
47
- # platform method to wait for a block to return true
48
- # See PageObject#wait_until
49
- #
50
- def wait_until(timeout, message = nil, &block)
51
- wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
52
- wait.until &block
53
- end
54
-
55
- #
56
- # platform method to handle an alert popup
57
- # See PageObject#alert
58
- #
59
- def alert(&block)
60
- @browser.execute_script "window.alert = function(msg) { window.__lastWatirAlert = msg; }"
61
- yield
62
- @browser.execute_script "return window.__lastWatirAlert"
63
- end
64
-
65
- #
66
- # platform method to handle a confirm popup
67
- # See PageObject#confirm
68
- #
69
- def confirm(response, &block)
70
- @browser.execute_script "window.confirm = function(msg) { window.__lastWatirConfirm = msg; return #{!!response} }"
71
- yield
72
- @browser.execute_script "return window.__lastWatirConfirm"
73
- end
74
-
75
- #
76
- # platform method to handle a prompt popup
77
- # See PageObject#prompt
78
- #
79
- def prompt(answer, &block)
80
- @browser.execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer.to_json}; }"
81
- yield
82
- result = @browser.execute_script "return window.__lastWatirPrompt"
83
-
84
- result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k)}
85
- result
86
- end
87
-
88
- #
89
- # platform method to get the value stored in a text field
90
- # See PageObject::Accessors#text_field
91
- #
92
- def text_field_value_for(identifier)
93
- identifier = add_tagname_if_needed identifier, 'input', :type => 'text'
94
- how, what = Elements::TextField.selenium_identifier_for identifier
95
- @browser.find_element(how, what).attribute('value')
96
- end
97
-
98
- #
99
- # platform method to set the value for a text field
100
- # See PageObject::Accessors#text_field
101
- #
102
- def text_field_value_set(identifier, value)
103
- identifier = add_tagname_if_needed identifier, 'input', :type => 'text'
104
- how, what = Elements::TextField.selenium_identifier_for identifier
105
- @browser.find_element(how, what).send_keys(value)
106
- end
107
-
108
- #
109
- # platform method to retrieve a text field element
110
- # See PageObject::Accessors#text_field
111
- #
112
- def text_field_for(identifier)
113
- identifier = add_tagname_if_needed identifier, 'input', :type => 'text'
114
- how, what = Elements::TextField.selenium_identifier_for identifier
115
- element = @browser.find_element(how, what)
116
- PageObject::Elements::TextField.new(element, :platform => :selenium)
117
- end
118
-
119
- #
120
- # platform method to get the value stored in a hidden field
121
- # See PageObject::Accessors#hidden_field
122
- #
123
- def hidden_field_value_for(identifier)
124
- identifier = add_tagname_if_needed identifier, 'input', :type => 'hidden'
125
- how, what = Elements::HiddenField.selenium_identifier_for identifier
126
- @browser.find_element(how, what).attribute('value')
127
- end
128
-
129
- #
130
- # platform method to retrieve a hidden field element
131
- # See PageObject::Accessors#hidden_field
132
- #
133
- def hidden_field_for(identifier)
134
- identifier = add_tagname_if_needed identifier, 'input', :type => 'hidden'
135
- how, what = Elements::HiddenField.selenium_identifier_for identifier
136
- element = @browser.find_element(how, what)
137
- Elements::HiddenField.new(element, :platform => :selenium)
138
- end
139
-
140
- #
141
- # platform method to set text in a textarea
142
- # See PageObject::Accessors#text_area
143
- #
144
- def text_area_value_set(identifier, value)
145
- identifier = add_tagname_if_needed identifier, 'textarea'
146
- how, what = Elements::TextArea.selenium_identifier_for identifier
147
- @browser.find_element(how, what).send_keys(value)
148
- end
149
-
150
- #
151
- # platform method to get the text from a textarea
152
- # See PageObject::Accessors#text_area
153
- #
154
- def text_area_value_for(identifier)
155
- identifier = add_tagname_if_needed identifier, 'textarea'
156
- how, what = Elements::TextArea.selenium_identifier_for identifier
157
- @browser.find_element(how, what).attribute('value')
158
- end
159
-
160
- #
161
- # platform method to get the text area element
162
- # See PageObject::Accessors#text_area
163
- #
164
- def text_area_for(identifier)
165
- identifier = add_tagname_if_needed identifier, 'textarea'
166
- how, what = Elements::TextArea.selenium_identifier_for identifier
167
- element = @browser.find_element(how, what)
168
- Elements::TextArea.new(element, :platform => :selenium)
169
- end
170
-
171
- #
172
- # platform method to get the currently selected value from a select list
173
- # See PageObject::Accessors#select_list
174
- #
175
- def select_list_value_for(identifier)
176
- identifier = add_tagname_if_needed identifier, 'select'
177
- how, what = Elements::SelectList.selenium_identifier_for identifier
178
- @browser.find_element(how, what).attribute('value')
179
- end
180
-
181
- #
182
- # platform method to select a value from a select list
183
- # See PageObject::Accessors#select_list
184
- #
185
- def select_list_value_set(identifier, value)
186
- identifier = add_tagname_if_needed identifier, 'select'
187
- how, what = Elements::SelectList.selenium_identifier_for identifier
188
- @browser.find_element(how, what).send_keys(value)
189
- end
190
-
191
- #
192
- # platform method to return the select list element
193
- # See PageObject::Accessors#select_list
194
- #
195
- def select_list_for(identifier)
196
- identifier = add_tagname_if_needed identifier, 'select'
197
- how, what = Elements::SelectList.selenium_identifier_for identifier
198
- element = @browser.find_element(how, what)
199
- Elements::SelectList.new(element, :platform => :selenium)
200
- end
201
-
202
- #
203
- # platform method to click a link
204
- # See PageObject::Accessors#link
205
- #
206
- def click_link_for(identifier)
207
- identifier = add_tagname_if_needed identifier, "a"
208
- how, what = Elements::Link.selenium_identifier_for identifier
209
- @browser.find_element(how, what).click
210
- end
211
-
212
- #
213
- # platform method to return a PageObject::Elements::Link object
214
- # see PageObject::Accessors#link
215
- #
216
- def link_for(identifier)
217
- identifier = add_tagname_if_needed identifier, "a"
218
- how, what = Elements::Link.selenium_identifier_for identifier
219
- element = @browser.find_element(how, what)
220
- Elements::Link.new(element, :platform => :selenium)
221
- end
222
-
223
- #
224
- # platform method to check a checkbox
225
- # See PageObject::Accessors#checkbox
226
- #
227
- def check_checkbox(identifier)
228
- identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
229
- how, what = Elements::CheckBox.selenium_identifier_for identifier
230
- @browser.find_element(how, what).click unless @browser.find_element(how, what).selected?
231
- end
232
-
233
- #
234
- # platform method to uncheck a checkbox
235
- # See PageObject::Accessors#checkbox
236
- #
237
- def uncheck_checkbox(identifier)
238
- identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
239
- how, what = Elements::CheckBox.selenium_identifier_for identifier
240
- @browser.find_element(how, what).click if @browser.find_element(how, what).selected?
241
- end
242
-
243
- #
244
- # platform method to determine if a checkbox is checked
245
- # See PageObject::Accessors#checkbox
246
- #
247
- def checkbox_checked?(identifier)
248
- identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
249
- how, what = Elements::CheckBox.selenium_identifier_for identifier
250
- @browser.find_element(how, what).selected?
251
- end
252
-
253
- #
254
- # platform method to return a PageObject::Elements::CheckBox element
255
- # See PageObject::Accessors#checkbox
256
- #
257
- def checkbox_for(identifier)
258
- identifier = add_tagname_if_needed identifier, 'input', :type => 'checkbox'
259
- how, what = Elements::CheckBox.selenium_identifier_for identifier
260
- element = @browser.find_element(how, what)
261
- Elements::CheckBox.new(element, :platform => :selenium)
262
- end
263
-
264
- #
265
- # platform method to select a radio button
266
- # See PageObject::Accessors#radio_button
267
- #
268
- def select_radio(identifier)
269
- identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
270
- how, what = Elements::RadioButton.selenium_identifier_for identifier
271
- @browser.find_element(how, what).click unless @browser.find_element(how, what).selected?
272
- end
273
-
274
- #
275
- # platform method to clear a radio button
276
- # See PageObject::Accessors#radio_button
277
- #
278
- def clear_radio(identifier)
279
- identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
280
- how, what = Elements::RadioButton.selenium_identifier_for identifier
281
- @browser.find_element(how, what).click if @browser.find_element(how, what).selected?
282
- end
283
-
284
- #
285
- # platform method to determine if a radio button is selected
286
- # See PageObject::Accessors#radio_button
287
- #
288
- def radio_selected?(identifier)
289
- identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
290
- how, what = Elements::RadioButton.selenium_identifier_for identifier
291
- @browser.find_element(how, what).selected?
292
- end
293
-
294
- #
295
- # platform method to return a PageObject::Eements::RadioButton element
296
- # See PageObject::Accessors#radio_button
297
- #
298
- def radio_button_for(identifier)
299
- identifier = add_tagname_if_needed identifier, 'input', :type => 'radio'
300
- how, what = Elements::RadioButton.selenium_identifier_for identifier
301
- element = @browser.find_element(how, what)
302
- PageObject::Elements::RadioButton.new(element, :platform => :selenium)
303
- end
304
-
305
- #
306
- # platform method to return the text for a div
307
- # See PageObject::Accessors#div
308
- #
309
- def div_text_for(identifier)
310
- identifier = add_tagname_if_needed identifier, 'div'
311
- how, what = Elements::Div.selenium_identifier_for identifier
312
- @browser.find_element(how, what).text
313
- end
314
-
315
- #
316
- # platform method to return a PageObject::Elements::Div element
317
- # See PageObject::Accessors#div
318
- #
319
- def div_for(identifier)
320
- identifier = add_tagname_if_needed identifier, 'div'
321
- how, what = Elements::Div.selenium_identifier_for identifier
322
- element = @browser.find_element(how, what)
323
- PageObject::Elements::Div.new(element, :platform => :selenium)
324
- end
325
-
326
- #
327
- # platform method to return the text for a span
328
- # See PageObject::Accessors#span
329
- #
330
- def span_text_for(identifier)
331
- identifier = add_tagname_if_needed identifier, 'span'
332
- how, what = Elements::Span.selenium_identifier_for identifier
333
- @browser.find_element(how, what).text
334
- end
335
-
336
- #
337
- # platform method to return a PageObject::Elements::Span element
338
- # See PageObject::Accessors#span
339
- #
340
- def span_for(identifier)
341
- identifier = add_tagname_if_needed identifier, 'span'
342
- how, what = Elements::Span.selenium_identifier_for identifier
343
- element = @browser.find_element(how, what)
344
- PageObject::Elements::Span.new(element, :platform => :selenium)
345
- end
346
-
347
- #
348
- # platform method to click a button
349
- # See PageObject::Accessors#button
350
- #
351
- def click_button_for(identifier)
352
- identifier = add_tagname_if_needed identifier, 'input', :type => 'submit'
353
- how, what = Elements::Button.selenium_identifier_for identifier
354
- @browser.find_element(how, what).click
355
- end
356
-
357
- #
358
- # platform method to retrieve a button element
359
- # See PageObject::Accessors#button
360
- #
361
- def button_for(identifier)
362
- identifier = add_tagname_if_needed identifier, 'input', :type => 'submit'
363
- how, what = Elements::Button.selenium_identifier_for identifier
364
- element = @browser.find_element(how, what)
365
- PageObject::Elements::Button.new(element, :platform => :selenium)
366
- end
367
-
368
- #
369
- # platform method to retrieve a table element
370
- # See PageObject::Accessors#table
371
- #
372
- def table_for(identifier)
373
- identifier = add_tagname_if_needed identifier, 'table'
374
- how, what = Elements::Table.selenium_identifier_for identifier
375
- element = @browser.find_element(how, what)
376
- PageObject::Elements::Table.new(element, :platform => :selenium)
377
- end
378
-
379
- #
380
- # platform method to retrieve the text from a table cell
381
- # See PageObject::Accessors#cell
382
- #
383
- def cell_text_for(identifier)
384
- identifier = add_tagname_if_needed identifier, 'td'
385
- how, what = Elements::TableCell.selenium_identifier_for identifier
386
- @browser.find_element(how, what).text
387
- end
388
-
389
- #
390
- # platform method to retrieve a table cell element
391
- # See PageObject::Accessors#cell
392
- #
393
- def cell_for(identifier)
394
- identifier = add_tagname_if_needed identifier, 'td'
395
- how, what = Elements::TableCell.selenium_identifier_for identifier
396
- element = @browser.find_element(how, what)
397
- PageObject::Elements::TableCell.new(element, :platform => :selenium)
398
- end
399
-
400
- #
401
- # platform method to retrieve an image element
402
- # See PageObject::Accessors#image
403
- #
404
- def image_for(identifier)
405
- identifier = add_tagname_if_needed identifier, 'img'
406
- how, what = Elements::Image.selenium_identifier_for identifier
407
- element = @browser.find_element(how, what)
408
- PageObject::Elements::Image.new(element, :platform => :selenium)
409
- end
410
-
411
- #
412
- # platform method to retrieve a form element
413
- # See PageObject::Accessors#form
414
- #
415
- def form_for(identifier)
416
- identifier = add_tagname_if_needed identifier, 'form'
417
- how, what = Elements::Form.selenium_identifier_for identifier
418
- element = @browser.find_element(how, what)
419
- PageObject::Elements::Form.new(element, :platform => :selenium)
420
- end
421
-
422
- #
423
- # platform method to retrieve the text from a list item
424
- # See PageObject::Accessors#list_item
425
- #
426
- def list_item_text_for(identifier)
427
- identifier = add_tagname_if_needed identifier, 'li'
428
- how, what = Elements::ListItem.selenium_identifier_for identifier
429
- @browser.find_element(how, what).text
430
- end
431
-
432
- #
433
- # platform method to retrieve a list item element
434
- # See PageObject::Accessors#list_item
435
- #
436
- def list_item_for(identifier)
437
- identifier = add_tagname_if_needed identifier, 'li'
438
- how, what = Elements::ListItem.selenium_identifier_for identifier
439
- element = @browser.find_element(how, what)
440
- PageObject::Elements::ListItem.new(element, :platform => :selenium)
441
- end
442
-
443
- #
444
- # platform method to retrieve an unordered list element
445
- # See PageObject::Accessors#unordered_list
446
- #
447
- def unordered_list_for(identifier)
448
- identifier = add_tagname_if_needed identifier, 'ul'
449
- how, what = Elements::UnorderedList.selenium_identifier_for identifier
450
- element = @browser.find_element(how, what)
451
- PageObject::Elements::UnorderedList.new(element, :platform => :selenium)
452
- end
453
-
454
- #
455
- # platform method to retrieve an ordered list element
456
- # See PageObject::Accessors#ordered_list
457
- #
458
- def ordered_list_for(identifier)
459
- identifier = add_tagname_if_needed identifier, 'ol'
460
- how, what = Elements::OrderedList.selenium_identifier_for identifier
461
- element = @browser.find_element(how, what)
462
- PageObject::Elements::OrderedList.new(element, :platform => :selenium)
463
- end
464
-
465
- private
466
-
467
- def add_tagname_if_needed identifier, tag, additional=nil
468
- return identifier if identifier.length < 2 and supported_identifier(identifier, tag, additional)
469
- identifier[:tag_name] = tag
470
- if additional
471
- additional.each do |key, value|
472
- identifier[key] = value
473
- end
474
- end
475
- identifier
476
- end
477
-
478
- def supported_identifier(identifier, tag, additional)
479
- return false if identifier[:index]
480
- return false if identifier[:text] and tag == 'input' and additional[:type] == 'hidden'
481
- return false if identifier[:href] and tag == 'a'
482
- true
483
- end
484
-
485
- end
486
- end