page-object 0.2 → 0.2.1

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