page-object 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +5 -5
  2. data/.coveralls.yml +1 -1
  3. data/.gitignore +8 -8
  4. data/.rspec +2 -2
  5. data/.ruby-gemset +1 -1
  6. data/.ruby-version +1 -1
  7. data/.travis.yml +17 -17
  8. data/ChangeLog +923 -888
  9. data/Gemfile +13 -13
  10. data/Guardfile +20 -20
  11. data/LICENSE +20 -20
  12. data/README.md +114 -114
  13. data/Rakefile +29 -29
  14. data/cucumber.yml +8 -8
  15. data/lib/page-object.rb +431 -420
  16. data/lib/page-object/accessors.rb +1201 -1175
  17. data/lib/page-object/element_locators.rb +21 -21
  18. data/lib/page-object/elements.rb +62 -61
  19. data/lib/page-object/elements/area.rb +9 -9
  20. data/lib/page-object/elements/audio.rb +9 -9
  21. data/lib/page-object/elements/bold.rb +9 -9
  22. data/lib/page-object/elements/button.rb +12 -12
  23. data/lib/page-object/elements/canvas.rb +10 -10
  24. data/lib/page-object/elements/check_box.rb +9 -9
  25. data/lib/page-object/elements/date_field.rb +10 -0
  26. data/lib/page-object/elements/div.rb +9 -9
  27. data/lib/page-object/elements/element.rb +212 -159
  28. data/lib/page-object/elements/file_field.rb +9 -9
  29. data/lib/page-object/elements/form.rb +9 -9
  30. data/lib/page-object/elements/heading.rb +14 -14
  31. data/lib/page-object/elements/hidden_field.rb +9 -9
  32. data/lib/page-object/elements/image.rb +10 -10
  33. data/lib/page-object/elements/italic.rb +9 -9
  34. data/lib/page-object/elements/label.rb +9 -9
  35. data/lib/page-object/elements/link.rb +9 -9
  36. data/lib/page-object/elements/list_item.rb +9 -9
  37. data/lib/page-object/elements/media.rb +11 -11
  38. data/lib/page-object/elements/option.rb +9 -9
  39. data/lib/page-object/elements/ordered_list.rb +43 -45
  40. data/lib/page-object/elements/paragraph.rb +9 -9
  41. data/lib/page-object/elements/radio_button.rb +9 -9
  42. data/lib/page-object/elements/select_list.rb +42 -42
  43. data/lib/page-object/elements/span.rb +9 -9
  44. data/lib/page-object/elements/table.rb +85 -68
  45. data/lib/page-object/elements/table_cell.rb +10 -10
  46. data/lib/page-object/elements/table_row.rb +52 -52
  47. data/lib/page-object/elements/text_area.rb +9 -9
  48. data/lib/page-object/elements/text_field.rb +10 -10
  49. data/lib/page-object/elements/unordered_list.rb +42 -44
  50. data/lib/page-object/elements/video.rb +9 -9
  51. data/lib/page-object/indexed_properties.rb +41 -41
  52. data/lib/page-object/javascript/angularjs.rb +14 -14
  53. data/lib/page-object/javascript/jquery.rb +14 -14
  54. data/lib/page-object/javascript/prototype.rb +14 -14
  55. data/lib/page-object/javascript/yui.rb +18 -18
  56. data/lib/page-object/javascript_framework_facade.rb +80 -80
  57. data/lib/page-object/locator_generator.rb +183 -182
  58. data/lib/page-object/nested_elements.rb +17 -17
  59. data/lib/page-object/page_factory.rb +108 -108
  60. data/lib/page-object/page_populator.rb +105 -95
  61. data/lib/page-object/platforms/watir.rb +50 -50
  62. data/lib/page-object/platforms/watir/page_object.rb +1155 -1124
  63. data/lib/page-object/section_collection.rb +16 -16
  64. data/lib/page-object/version.rb +4 -4
  65. data/lib/page-object/widgets.rb +98 -98
  66. data/page-object.gemspec +32 -32
  67. metadata +12 -12
@@ -1,50 +1,50 @@
1
- module PageObject
2
- module Platforms
3
- module Watir
4
-
5
- def self.create_page_object(browser)
6
- browser = selenium_browser(browser) unless watir?(browser)
7
- return Watir::PageObject.new(browser)
8
- end
9
-
10
- def self.is_for?(browser)
11
- require 'watir'
12
- watir?(browser) || selenium?(browser)
13
- end
14
-
15
- def self.browser_for root
16
- return watir_browser(root) if watir?(root)
17
- return selenium_browser(root) if selenium?(root)
18
- nil
19
- end
20
-
21
- def self.root_element_for root
22
- Elements::Element.new(root) if is_for?(root)
23
- end
24
-
25
- def self.browser_root_for browser
26
- browser.element
27
- end
28
-
29
- private
30
-
31
- def self.watir_browser(root)
32
- return root if root.is_a?(::Watir::Browser)
33
- root.browser
34
- end
35
-
36
- def self.selenium_browser(root)
37
- return ::Watir::Browser.new(root) if root.is_a?(::Selenium::WebDriver::Driver)
38
- ::Watir::Browser.new(Selenium::WebDriver::Driver.new(root.send(:bridge)))
39
- end
40
-
41
- def self.watir?(browser)
42
- browser.is_a?(::Watir::Browser) || browser.is_a?(::Watir::HTMLElement)
43
- end
44
-
45
- def self.selenium?(browser)
46
- browser.is_a?(::Selenium::WebDriver::Driver) || browser.is_a?(::Selenium::WebDriver::Element)
47
- end
48
- end
49
- end
50
- end
1
+ module PageObject
2
+ module Platforms
3
+ module Watir
4
+
5
+ def self.create_page_object(browser)
6
+ browser = selenium_browser(browser) unless watir?(browser)
7
+ return Watir::PageObject.new(browser)
8
+ end
9
+
10
+ def self.is_for?(browser)
11
+ require 'watir'
12
+ watir?(browser) || selenium?(browser)
13
+ end
14
+
15
+ def self.browser_for root
16
+ return watir_browser(root) if watir?(root)
17
+ return selenium_browser(root) if selenium?(root)
18
+ nil
19
+ end
20
+
21
+ def self.root_element_for root
22
+ Elements::Element.new(root) if is_for?(root)
23
+ end
24
+
25
+ def self.browser_root_for browser
26
+ browser.element
27
+ end
28
+
29
+ private
30
+
31
+ def self.watir_browser(root)
32
+ return root if root.is_a?(::Watir::Browser)
33
+ root.browser
34
+ end
35
+
36
+ def self.selenium_browser(root)
37
+ return ::Watir::Browser.new(root) if root.is_a?(::Selenium::WebDriver::Driver)
38
+ ::Watir::Browser.new(Selenium::WebDriver::Driver.new(root.send(:bridge)))
39
+ end
40
+
41
+ def self.watir?(browser)
42
+ browser.is_a?(::Watir::Browser) || browser.is_a?(::Watir::HTMLElement)
43
+ end
44
+
45
+ def self.selenium?(browser)
46
+ browser.is_a?(::Selenium::WebDriver::Driver) || browser.is_a?(::Selenium::WebDriver::Element)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,1124 +1,1155 @@
1
- require 'page-object/elements'
2
-
3
-
4
- module PageObject
5
- module Platforms
6
- module Watir
7
-
8
- #
9
- # Watir implementation of the page object platform driver. You should not use the
10
- # class directly. Instead you should include the PageObject module in your page object
11
- # and use the methods dynamically added from the PageObject::Accessors module.
12
- #
13
- class PageObject
14
- attr_reader :browser
15
-
16
- def self.define_widget_accessors(widget_tag, widget_class, base_element_tag)
17
- define_widget_singular_accessor(base_element_tag, widget_class, widget_tag)
18
- define_widget_multiple_accessor(base_element_tag, widget_class, widget_tag)
19
- end
20
-
21
- def initialize(browser)
22
- @browser = browser
23
- end
24
-
25
- #
26
- # platform method to navigate to a provided url
27
- # See PageObject#navigate_to
28
- #
29
- def navigate_to(url)
30
- @browser.goto url
31
- end
32
-
33
- #
34
- # platform method to get the current url
35
- # See PageObject#current_url
36
- #
37
- def current_url
38
- @browser.url
39
- end
40
-
41
- #
42
- # platform method to retrieve the text from the current page
43
- # See PageObject#text
44
- #
45
- def text
46
- @browser.text
47
- end
48
-
49
- #
50
- # platform method to retrieve the html for the current page
51
- # See PageObject#html
52
- #
53
- def html
54
- @browser.html
55
- end
56
-
57
- #
58
- # platform method to retrieve the title for the current page
59
- # See PageObject#title
60
- #
61
- def title
62
- @browser.title
63
- end
64
-
65
- #
66
- # platform method to wait for a block to return true
67
- # See PageObject#wait_until
68
- def wait_until(timeout, message = nil, &block)
69
- @browser.wait_until(timeout: timeout, message: message, &block)
70
- end
71
-
72
- #
73
- # platform method to handle an alert popup
74
- # See PageObject#alert
75
- #
76
- def alert(frame=nil, &block)
77
- switch_to_frame(frame)
78
- yield
79
- value = nil
80
- if @browser.alert.exists?
81
- value = @browser.alert.text
82
- @browser.alert.ok
83
- end
84
- switch_to_default_content(frame)
85
- value
86
- end
87
-
88
- #
89
- # platform method to handle a confirm popup
90
- # See PageObject#confirm
91
- #
92
- def confirm(response, frame=nil, &block)
93
- switch_to_frame(frame)
94
- yield
95
- value = nil
96
- if @browser.alert.exists?
97
- value = @browser.alert.text
98
- response ? @browser.alert.ok : @browser.alert.close
99
- end
100
- switch_to_default_content(frame)
101
- value
102
- end
103
-
104
- #
105
- # platform method to handle a prompt popup
106
- # See PageObject#prompt
107
- #
108
- def prompt(answer, frame=nil, &block)
109
- switch_to_frame(frame)
110
- @browser.wd.execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer}; }"
111
- yield
112
- result = @browser.wd.execute_script "return window.__lastWatirPrompt"
113
- switch_to_default_content(frame)
114
- result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
115
- result
116
- end
117
-
118
- #
119
- # platform method to execute javascript on the browser
120
- # See PageObject#execute_script
121
- #
122
- def execute_script(script, *args)
123
- @browser.execute_script(script, *args)
124
- end
125
-
126
- #
127
- # platform method to handle attaching to a running window
128
- # See PageObject#attach_to_window
129
- #
130
- def attach_to_window(identifier, &block)
131
- win_id = {identifier.keys.first => /#{Regexp.escape(identifier.values.first)}/}
132
- @browser.window(win_id).use &block
133
- end
134
-
135
- def element_with_focus
136
- element = browser.execute_script("return document.activeElement")
137
- type = element.type.to_sym if element.tag_name.to_sym == :input
138
- cls = ::PageObject::Elements.element_class_for(element.tag_name, type)
139
- cls.new(element)
140
- end
141
-
142
- #
143
- # platform method to switch to a frame and execute a block
144
- # See PageObject#in_frame
145
- #
146
- def in_frame(identifier, frame=nil, &block)
147
- frame = [] if frame.nil?
148
- frame << {frame: identifier}
149
- block.call(frame)
150
- end
151
-
152
- #
153
- # platform method to switch to an iframe and execute a block
154
- # See PageObject#in_frame
155
- #
156
- def in_iframe(identifier, frame=nil, &block)
157
- frame = [] if frame.nil?
158
- frame << {iframe: identifier}
159
- block.call(frame)
160
- end
161
-
162
- #
163
- # platform method to refresh the page
164
- # See PageObject#refresh
165
- #
166
- def refresh
167
- @browser.refresh
168
- end
169
-
170
- #
171
- # platform method to go back to the previous page
172
- # See PageObject#back
173
- #
174
- def back
175
- @browser.back
176
- end
177
-
178
- #
179
- # platform method to go forward to the next page
180
- # See PageObject#forward
181
- #
182
- def forward
183
- @browser.forward
184
- end
185
-
186
- #
187
- # platform method to clear the cookies from the browser
188
- # See PageObject#clear_cookies
189
- #
190
- def clear_cookies
191
- @browser.cookies.clear
192
- end
193
-
194
- #
195
- # platform method to save the current screenshot to a file
196
- # See PageObject#save_screenshot
197
- #
198
- def save_screenshot(file_name)
199
- @browser.wd.save_screenshot(file_name)
200
- end
201
-
202
- #
203
- # platform method to get the value stored in a text field
204
- # See PageObject::Accessors#text_field
205
- #
206
- def text_field_value_for(identifier)
207
- process_watir_call("text_field(identifier).value", Elements::TextField, identifier)
208
- end
209
-
210
- #
211
- # platform method to set the value for a text field
212
- # See PageObject::Accessors#text_field
213
- #
214
- def text_field_value_set(identifier, value)
215
- process_watir_call("text_field(identifier).set(value)", Elements::TextField, identifier, value)
216
- end
217
-
218
- #
219
- # platform method to retrieve a text field element
220
- # See PageObject::Accessors#text_field
221
- #
222
- def text_field_for(identifier)
223
- find_watir_element("text_field(identifier)", Elements::TextField, identifier)
224
- end
225
-
226
- #
227
- # platform method to retrieve an array of text field elements
228
- #
229
- def text_fields_for(identifier)
230
- elements = find_watir_elements("text_fields(identifier)", Elements::TextField, identifier)
231
- elements.select { |e| e.element.tag_name == 'input' }
232
- end
233
-
234
- #
235
- # platform method to get the value stored in a hidden field
236
- # See PageObject::Accessors#hidden_field
237
- #
238
- def hidden_field_value_for(identifier)
239
- process_watir_call("hidden(identifier).value", Elements::HiddenField, identifier)
240
- end
241
-
242
- #
243
- # platform method to retrieve a hidden field element
244
- # See PageObject::Accessors#hidden_field
245
- #
246
- def hidden_field_for(identifier)
247
- find_watir_element("hidden(identifier)", Elements::HiddenField, identifier)
248
- end
249
-
250
- #
251
- # platform method to retrieve an array of hidden field elements
252
- #
253
- def hidden_fields_for(identifier)
254
- find_watir_elements("hiddens(identifier)", Elements::HiddenField, identifier)
255
- end
256
-
257
- #
258
- # platform method to set text in a textarea
259
- # See PageObject::Accessors#text_area
260
- #
261
- def text_area_value_set(identifier, value)
262
- process_watir_call("textarea(identifier).set(value)", Elements::TextArea,
263
- identifier, value)
264
- end
265
-
266
- #
267
- # platform method to get the text from a textarea
268
- # See PageObject::Accessors#text_area
269
- #
270
- def text_area_value_for(identifier)
271
- process_watir_call("textarea(identifier).value", Elements::TextArea, identifier)
272
- end
273
-
274
- #
275
- # platform method to get the text area element
276
- # See PageObject::Accessors#text_area
277
- #
278
- def text_area_for(identifier)
279
- find_watir_element("textarea(identifier)", Elements::TextArea, identifier)
280
- end
281
-
282
- #
283
- # platform method to retrieve an array of textarea elements
284
- #
285
- def text_areas_for(identifier)
286
- find_watir_elements("textareas(identifier)", Elements::TextArea, identifier)
287
- end
288
-
289
- #
290
- # platform method to get the currently selected value from a select list
291
- # See PageObject::Accessors#select_list
292
- #
293
- def select_list_value_for(identifier)
294
- options = find_watir_elements("select_list(identifier).selected_options",
295
- Elements::SelectList, identifier)
296
- return nil if options.empty?
297
- options.first.text
298
- end
299
-
300
- #
301
- # platform method to select a value from a select list
302
- # See PageObject::Accessors#select_list
303
- #
304
- def select_list_value_set(identifier, value)
305
- process_watir_call("select_list(identifier).select(value)", Elements::SelectList,
306
- identifier, value)
307
- end
308
-
309
- #
310
- # platform method to return the select list element
311
- # See PageObject::Accessors#select_list
312
- #
313
- def select_list_for(identifier)
314
- find_watir_element("select_list(identifier)", Elements::SelectList, identifier)
315
- end
316
-
317
- #
318
- # platform method to retrieve an array of select_list elements
319
- #
320
- def select_lists_for(identifier)
321
- find_watir_elements("select_lists(identifier)", Elements::SelectList, identifier)
322
- end
323
-
324
- #
325
- # platform method to click a link
326
- # See PageObject::Accessors#link
327
- #
328
- def click_link_for(identifier)
329
- call = "link(identifier)"
330
- process_watir_call("#{call}.click if identifier", Elements::Link, identifier)
331
- end
332
-
333
- #
334
- # platform method to return a PageObject::Elements::Link object
335
- # see PageObject::Accessors#link
336
- #
337
- def link_for(identifier)
338
- call = "link(identifier)"
339
- find_watir_element(call, Elements::Link, identifier)
340
- end
341
-
342
- #
343
- # platform method to retrieve an array of link elements
344
- #
345
- def links_for(identifier)
346
- call = "links(identifier)"
347
- find_watir_elements(call, Elements::Link, identifier)
348
- end
349
-
350
- #
351
- # platform method to check a checkbox
352
- # See PageObject::Accessors#checkbox
353
- #
354
- def check_checkbox(identifier)
355
- process_watir_call("checkbox(identifier).set", Elements::CheckBox, identifier)
356
- end
357
-
358
- #
359
- # platform method to uncheck a checkbox
360
- # See PageObject::Accessors#checkbox
361
- #
362
- def uncheck_checkbox(identifier)
363
- process_watir_call("checkbox(identifier).clear", Elements::CheckBox, identifier)
364
- end
365
-
366
- #
367
- # platform method to determine if a checkbox is checked
368
- # See PageObject::Accessors#checkbox
369
- #
370
- def checkbox_checked?(identifier)
371
- process_watir_call("checkbox(identifier).set?", Elements::CheckBox, identifier)
372
- end
373
-
374
- #
375
- # platform method to return a PageObject::Elements::CheckBox element
376
- # See PageObject::Accessors#checkbox
377
- #
378
- def checkbox_for(identifier)
379
- find_watir_element("checkbox(identifier)", Elements::CheckBox, identifier)
380
- end
381
-
382
- #
383
- # platform method to retrieve an array of checkbox elements
384
- #
385
- def checkboxs_for(identifier)
386
- find_watir_elements("checkboxes(identifier)", Elements::CheckBox, identifier)
387
- end
388
-
389
- #
390
- # platform method to select a radio button
391
- # See PageObject::Accessors#radio_button
392
- #
393
- def select_radio(identifier)
394
- process_watir_call("radio(identifier).set", Elements::RadioButton, identifier)
395
- end
396
-
397
- #
398
- # platform method to determine if a radio button is selected
399
- # See PageObject::Accessors#radio_button
400
- #
401
- def radio_selected?(identifier)
402
- process_watir_call("radio(identifier).set?", Elements::RadioButton, identifier)
403
- end
404
-
405
- #
406
- # platform method to return a PageObject::Eements::RadioButton element
407
- # See PageObject::Accessors#radio_button
408
- #
409
- def radio_button_for(identifier)
410
- find_watir_element("radio(identifier)", Elements::RadioButton, identifier)
411
- end
412
-
413
- #
414
- # platform method to retrieve an array of radio button elements
415
- #
416
- def radio_buttons_for(identifier)
417
- find_watir_elements("radios(identifier)", Elements::RadioButton, identifier)
418
- end
419
-
420
- #
421
- # platform method to return the text for a div
422
- # See PageObject::Accessors#div
423
- #
424
- def div_text_for(identifier)
425
- process_watir_call("div(identifier).text", Elements::Div, identifier, nil, 'div')
426
- end
427
-
428
- #
429
- # platform method to return a PageObject::Elements::Div element
430
- # See PageObject::Accessors#div
431
- #
432
- def div_for(identifier)
433
- find_watir_element("div(identifier)", Elements::Div, identifier, 'div')
434
- end
435
-
436
- #
437
- # platform method to retrieve an array of div elements
438
- #
439
- def divs_for(identifier)
440
- find_watir_elements("divs(identifier)", Elements::Div, identifier, 'div')
441
- end
442
-
443
- #
444
- # platform method to return the text for a span
445
- # See PageObject::Accessors#span
446
- #
447
- def span_text_for(identifier)
448
- process_watir_call("span(identifier).text", Elements::Span, identifier, nil, 'span')
449
- end
450
-
451
- #
452
- # platform method to return a PageObject::Elements::Span element
453
- # See PageObject::Accessors#span
454
- #
455
- def span_for(identifier)
456
- find_watir_element("span(identifier)", Elements::Span, identifier, 'span')
457
- end
458
-
459
- #
460
- # platform method to retrieve an array of span elements
461
- #
462
- def spans_for(identifier)
463
- find_watir_elements("spans(identifier)", Elements::Span, identifier, 'span')
464
- end
465
-
466
- #
467
- # platform method to click a button
468
- # See PageObject::Accessors#button
469
- #
470
- def click_button_for(identifier)
471
- call = "button(identifier)"
472
- process_watir_call("#{call}.click", Elements::Button, identifier)
473
- end
474
-
475
- #
476
- # platform method to retrieve a button element
477
- # See PageObject::Accessors#button
478
- #
479
- def button_for(identifier)
480
- call = "button(identifier)"
481
- find_watir_element(call, Elements::Button, identifier)
482
- end
483
-
484
- #
485
- # platform method to retrieve an array of button elements
486
- #
487
- def buttons_for(identifier)
488
- call = "buttons(identifier)"
489
- find_watir_elements(call, Elements::Button, identifier)
490
- end
491
-
492
- #
493
- # platform method to return the text for a table
494
- # See PageObject::Accessors#table
495
- #
496
- def table_text_for(identifier)
497
- process_watir_call("table(identifier).text", Elements::Table, identifier, nil, 'table')
498
- end
499
-
500
- #
501
- # platform method to retrieve a table element
502
- # See PageObject::Accessors#table
503
- #
504
- def table_for(identifier)
505
- find_watir_element("table(identifier)", Elements::Table, identifier, 'table')
506
- end
507
-
508
- #
509
- # platform method to retrieve an array of table elements
510
- #
511
- def tables_for(identifier)
512
- find_watir_elements("tables(identifier)", Elements::Table, identifier, 'table')
513
- end
514
-
515
- #
516
- # platform method to retrieve the text from a table cell
517
- # See PageObject::Accessors#cell
518
- #
519
- def cell_text_for(identifier)
520
- process_watir_call("td(identifier).text", Elements::TableCell, identifier,
521
- nil, 'td')
522
- end
523
-
524
- #
525
- # platform method to retrieve a table cell element
526
- # See PageObject::Accessors#cell
527
- #
528
- def cell_for(identifier)
529
- find_watir_element("td(identifier)", Elements::TableCell, identifier, 'td')
530
- end
531
-
532
- #
533
- # platform method to retrieve an array of table cell elements
534
- #
535
- def cells_for(identifier)
536
- find_watir_elements("tds(identifier)", Elements::TableCell, identifier, 'td')
537
- end
538
-
539
- #
540
- # platform method to retrieve the text from a table row
541
- # See PageObject::Accessors#row
542
- #
543
- def row_text_for(identifier)
544
- process_watir_call("tr(identifier).text", Elements::TableRow, identifier,
545
- nil, 'tr')
546
- end
547
-
548
- #
549
- # platform method to retrieve a table row element
550
- # See PageObject::Accessors#row
551
- #
552
- def row_for(identifier)
553
- find_watir_element("tr(identifier)", Elements::TableRow, identifier, 'tr')
554
- end
555
-
556
- #
557
- # platform method to retrieve an array of table row elements
558
- #
559
- def rows_for(identifier)
560
- find_watir_elements("trs(identifier)", Elements::TableRow, identifier, 'tr')
561
- end
562
-
563
- #
564
- # platform method to retrieve load status of an image element
565
- # See PageObject::Accessors#image
566
- #
567
- def image_loaded_for(identifier)
568
- process_watir_call("image(identifier).loaded?", Elements::Image, identifier)
569
- end
570
-
571
- #
572
- # platform method to retrieve an image element
573
- # See PageObject::Accessors#image
574
- #
575
- def image_for(identifier)
576
- find_watir_element("image(identifier)", Elements::Image, identifier)
577
- end
578
-
579
- #
580
- # platform method to retrieve an array of image elements
581
- #
582
- def images_for(identifier)
583
- find_watir_elements("images(identifier)", Elements::Image, identifier)
584
- end
585
-
586
- #
587
- # platform method to retrieve a form element
588
- # See PageObject::Accessors#form
589
- #
590
- def form_for(identifier)
591
- find_watir_element("form(identifier)", Elements::Form, identifier)
592
- end
593
-
594
- #
595
- # platform method to retrieve an array of forms
596
- #
597
- def forms_for(identifier)
598
- find_watir_elements("forms(identifier)", Elements::Form, identifier)
599
- end
600
-
601
- #
602
- # platform method to retrieve the text from a list item
603
- # See PageObject::Accessors#list_item
604
- #
605
- def list_item_text_for(identifier)
606
- process_watir_call("li(identifier).text", Elements::ListItem, identifier, nil, 'li')
607
- end
608
-
609
- #
610
- # platform method to retrieve a list item element
611
- # See PageObject::Accessors#list_item
612
- #
613
- def list_item_for(identifier)
614
- find_watir_element("li(identifier)", Elements::ListItem, identifier, 'li')
615
- end
616
-
617
- #
618
- # platform method to retrieve an array of list items
619
- #
620
- def list_items_for(identifier)
621
- find_watir_elements("lis(identifier)", Elements::ListItem, identifier, 'li')
622
- end
623
-
624
- #
625
- # platform method to retrieve the text from an unordered list
626
- # See PageObject::Accessors#unordered_list
627
- #
628
- def unordered_list_text_for(identifier)
629
- process_watir_call("ul(identifier).text", Elements::UnorderedList, identifier, nil, 'ul')
630
- end
631
-
632
- #
633
- # platform method to retrieve an unordered list element
634
- # See PageObject::Accessors#unordered_list
635
- #
636
- def unordered_list_for(identifier)
637
- find_watir_element("ul(identifier)", Elements::UnorderedList, identifier, 'ul')
638
- end
639
-
640
- #
641
- # platform method to retrieve an array of unordered lists
642
- #
643
- def unordered_lists_for(identifier)
644
- find_watir_elements("uls(identifier)", Elements::UnorderedList, identifier, 'ul')
645
- end
646
-
647
- #
648
- # platform method to retrieve the text from an ordered list
649
- # See PageObject::Accessors#ordered_list
650
- #
651
- def ordered_list_text_for(identifier)
652
- process_watir_call("ol(identifier).text", Elements::OrderedList, identifier, nil, 'ol')
653
- end
654
-
655
- #
656
- # platform method to retrieve an ordered list element
657
- # See PageObject::Accessors#ordered_list
658
- #
659
- def ordered_list_for(identifier)
660
- find_watir_element("ol(identifier)", Elements::OrderedList, identifier, 'ol')
661
- end
662
-
663
- #
664
- # platform method to retrieve an array of ordered lists
665
- #
666
- def ordered_lists_for(identifier)
667
- find_watir_elements("ols(identifier)", Elements::OrderedList, identifier, 'ol')
668
- end
669
-
670
- #
671
- # platform method to retrieve the text for a h1
672
- # See PageObject::Accessors#h1
673
- #
674
- def h1_text_for(identifier)
675
- process_watir_call("h1(identifier).text", Elements::Heading, identifier, nil, 'h1')
676
- end
677
-
678
- #
679
- # platform method to retrieve the h1 element
680
- # See PageObject::Accessors#h1
681
- #
682
- def h1_for(identifier)
683
- find_watir_element("h1(identifier)", Elements::Heading, identifier, 'h1')
684
- end
685
-
686
- #
687
- # platform method to retrieve an array of h1s
688
- #
689
- def h1s_for(identifier)
690
- find_watir_elements("h1s(identifier)", Elements::Heading, identifier, 'h1')
691
- end
692
-
693
- #
694
- # platform method to retrieve the text for a h2
695
- # See PageObject::Accessors#h2
696
- #
697
- def h2_text_for(identifier)
698
- process_watir_call("h2(identifier).text", Elements::Heading, identifier, nil, 'h2')
699
- end
700
-
701
- #
702
- # platform method to retrieve the h2 element
703
- # See PageObject::Accessors#h2
704
- #
705
- def h2_for(identifier)
706
- find_watir_element("h2(identifier)", Elements::Heading, identifier, 'h2')
707
- end
708
-
709
- #
710
- # platform method to retrieve an array of h2s
711
- #
712
- def h2s_for(identifier)
713
- find_watir_elements("h2s(identifier)", Elements::Heading, identifier, 'h2')
714
- end
715
-
716
- #
717
- # platform method to retrieve the text for a h3
718
- # See PageObject::Accessors#h3
719
- #
720
- def h3_text_for(identifier)
721
- process_watir_call("h3(identifier).text", Elements::Heading, identifier, nil, 'h3')
722
- end
723
-
724
- #
725
- # platform method to retrieve the h3 element
726
- # See PageObject::Accessors#h3
727
- #
728
- def h3_for(identifier)
729
- find_watir_element("h3(identifier)", Elements::Heading, identifier, 'h3')
730
- end
731
-
732
- #
733
- # platform method to retrieve an array of h3s
734
- #
735
- def h3s_for(identifier)
736
- find_watir_elements("h3s(identifier)", Elements::Heading, identifier, 'h3')
737
- end
738
-
739
- #
740
- # platform method to retrieve the text for a h4
741
- # See PageObject::Accessors#h4
742
- #
743
- def h4_text_for(identifier)
744
- process_watir_call("h4(identifier).text", Elements::Heading, identifier, nil, 'h4')
745
- end
746
-
747
- #
748
- # platform method to retrieve the h4 element
749
- # See PageObject::Accessors#h4
750
- #
751
- def h4_for(identifier)
752
- find_watir_element("h4(identifier)", Elements::Heading, identifier, 'h4')
753
- end
754
-
755
- #
756
- # platform method to retrieve an array of h4s
757
- #
758
- def h4s_for(identifier)
759
- find_watir_elements("h4s(identifier)", Elements::Heading, identifier, 'h4')
760
- end
761
-
762
- #
763
- # platform method to retrieve the text for a h5
764
- # See PageObject::Accessors#h5
765
- #
766
- def h5_text_for(identifier)
767
- process_watir_call("h5(identifier).text", Elements::Heading, identifier, nil, 'h5')
768
- end
769
-
770
- #
771
- # platform method to retrieve the h5 element
772
- # See PageObject::Accessors#h5
773
- #
774
- def h5_for(identifier)
775
- find_watir_element("h5(identifier)", Elements::Heading, identifier, 'h5')
776
- end
777
-
778
- #
779
- # platform method to retrieve an array of h5s
780
- #
781
- def h5s_for(identifier)
782
- find_watir_elements("h5s(identifier)", Elements::Heading, identifier, 'h5')
783
- end
784
-
785
- #
786
- # platform method to retrieve the text for a h6
787
- # See PageObject::Accessors#h6
788
- #
789
- def h6_text_for(identifier)
790
- process_watir_call("h6(identifier).text", Elements::Heading, identifier, nil, 'h6')
791
- end
792
-
793
- #
794
- # platform method to retrieve the h6 element
795
- # See PageObject::Accessors#h6
796
- #
797
- def h6_for(identifier)
798
- find_watir_element("h6(identifier)", Elements::Heading, identifier, 'h6')
799
- end
800
-
801
- #
802
- # platform method to retrieve an array of h6s
803
- #
804
- def h6s_for(identifier)
805
- find_watir_elements("h6s(identifier)", Elements::Heading, identifier, 'h6')
806
- end
807
-
808
- #
809
- # platform method to retrieve the text for a paragraph
810
- # See PageObject::Accessors#paragraph
811
- #
812
- def paragraph_text_for(identifier)
813
- process_watir_call("p(identifier).text", Elements::Paragraph, identifier, nil, 'p')
814
- end
815
-
816
- #
817
- # platform method to retrieve the paragraph element
818
- # See PageObject::Accessors#paragraph
819
- #
820
- def paragraph_for(identifier)
821
- find_watir_element("p(identifier)", Elements::Paragraph, identifier, 'p')
822
- end
823
-
824
- #
825
- # platform method to retrieve an array of paragraph elements
826
- #
827
- def paragraphs_for(identifier)
828
- find_watir_elements("ps(identifier)", Elements::Paragraph, identifier, 'p')
829
- end
830
-
831
- #
832
- # platform method to return the text for a label
833
- # See PageObject::Accessors#label
834
- #
835
- def label_text_for(identifier)
836
- process_watir_call("label(identifier).text", Elements::Label, identifier, nil, 'label')
837
- end
838
-
839
- #
840
- # platform method to return a PageObject::Elements::Label element
841
- # See PageObject::Accessors#label
842
- #
843
- def label_for(identifier)
844
- find_watir_element("label(identifier)", Elements::Label, identifier, 'label')
845
- end
846
-
847
- #
848
- #
849
- # platform method to retrieve an array of label elements
850
- #
851
- def labels_for(identifier)
852
- find_watir_elements("labels(identifier)", Elements::Label, identifier, 'label')
853
- end
854
-
855
- #
856
- # platform method to set the file on a file_field element
857
- # See PageObject::Accessors#file_field
858
- #
859
- def file_field_value_set(identifier, value)
860
- process_watir_call("file_field(identifier).set(value)", Elements::FileField,
861
- identifier, value)
862
- end
863
-
864
- #
865
- # platform method to retrieve a file_field element
866
- # See PageObject::Accessors#file_field
867
- #
868
- def file_field_for(identifier)
869
- find_watir_element("file_field(identifier)", Elements::FileField, identifier)
870
- end
871
-
872
- #
873
- # platform method to retrieve an array of file field elements
874
- #
875
- def file_fields_for(identifier)
876
- find_watir_elements("file_fields(identifier)", Elements::FileField, identifier)
877
- end
878
-
879
- #
880
- # platform method to click on an area
881
- #
882
- def click_area_for(identifier)
883
- process_watir_call("area(identifier).click", Elements::Area, identifier, nil, 'area')
884
- end
885
-
886
- #
887
- # platform method to retrieve an area element
888
- #
889
- def area_for(identifier)
890
- find_watir_element("area(identifier)", Elements::Area, identifier, 'area')
891
- end
892
-
893
- #
894
- # platform method to retrieve an array of area elements
895
- #
896
- def areas_for(identifier)
897
- find_watir_elements("areas(identifier)", Elements::Area, identifier, 'area')
898
- end
899
-
900
- #
901
- # platform method to retrieve a canvas element
902
- #
903
- def canvas_for(identifier)
904
- find_watir_element("canvas(identifier)", Elements::Canvas, identifier, 'canvas')
905
- end
906
-
907
- #
908
- # platform method to retrieve an array of canvas elements
909
- #
910
- def canvass_for(identifier)
911
- find_watir_elements("canvases(identifier)", Elements::Canvas, identifier, 'canvas')
912
- end
913
-
914
- #
915
- # platform method to retrieve an audio element
916
- #
917
- def audio_for(identifier)
918
- find_watir_element("audio(identifier)", Elements::Audio, identifier, 'audio')
919
- end
920
-
921
- #
922
- # platform method to retrieve an array of audio elements
923
- #
924
- def audios_for(identifier)
925
- find_watir_elements("audios(identifier)", Elements::Audio, identifier, 'audio')
926
- end
927
-
928
- #
929
- # platform method to retrieve a video element
930
- #
931
- def video_for(identifier)
932
- find_watir_element("video(identifier)", Elements::Video, identifier, 'video')
933
- end
934
-
935
- #
936
- # platform method to retrieve an array of video elements
937
- #
938
- def videos_for(identifier)
939
- find_watir_elements("videos(identifier)", Elements::Video, identifier, 'video')
940
- end
941
-
942
- #
943
- # platform method to return a PageObject::Elements::Element element
944
- # See PageObject::Accessors#element
945
- #
946
- def element_for(tag, identifier)
947
- find_watir_element("#{tag.to_s}(identifier)", Elements::Element, identifier, tag.to_s)
948
- end
949
-
950
- #
951
- # platform method to return an array of PageObject::Elements::Element elements
952
- # See PageObject::Accessors#element
953
- #
954
- def elements_for(tag, identifier)
955
- find_watir_elements("#{tag.to_s}s(identifier)", Elements::Element, identifier, tag.to_s)
956
- end
957
-
958
- #
959
- # platform method to return a PageObject rooted at an element
960
- # See PageObject::Accessors#page_section
961
- #
962
- def page_for(identifier, page_class)
963
- find_watir_page(identifier, page_class)
964
- end
965
-
966
- #
967
- # platform method to return a collection of PageObjects rooted at elements
968
- # See PageObject::Accessors#page_sections
969
- #
970
- def pages_for(identifier, page_class)
971
- SectionCollection[*find_watir_pages(identifier, page_class)]
972
- end
973
-
974
- #
975
- # platform method to return a svg element
976
- #
977
- def svg_for(identifier)
978
- find_watir_element("element(identifier)", Elements::Element, identifier)
979
- end
980
-
981
- #
982
- # platform method to return an array of svg elements
983
- #
984
- def svgs_for(identifier)
985
- find_watir_elements("element(identifier)", Elements::Element, identifier)
986
- end
987
-
988
- #
989
- # platform method to retrieve the text for a b
990
- # See PageObject::Accessors#b
991
- #
992
- def b_text_for(identifier)
993
- process_watir_call("b(identifier).text", Elements::Bold, identifier, nil, 'b')
994
- end
995
-
996
- #
997
- # platform method to retrieve the b element
998
- # See PageObject::Accessors#b
999
- #
1000
- def b_for(identifier)
1001
- find_watir_element("b(identifier)", Elements::Bold, identifier, 'b')
1002
- end
1003
-
1004
- #
1005
- # platform method to retrieve an array of bs
1006
- #
1007
- def bs_for(identifier)
1008
- find_watir_elements("bs(identifier)", Elements::Bold, identifier, 'b')
1009
- end
1010
-
1011
- #
1012
- # platform method to retrieve the text for a i
1013
- # See PageObject::Accessors#i
1014
- #
1015
- def i_text_for(identifier)
1016
- process_watir_call("i(identifier).text", Elements::Italic, identifier, nil, 'i')
1017
- end
1018
-
1019
- #
1020
- # platform method to retrieve the i element
1021
- # See PageObject::Accessors#i
1022
- #
1023
- def i_for(identifier)
1024
- find_watir_element("i(identifier)", Elements::Italic, identifier, 'i')
1025
- end
1026
-
1027
- #
1028
- # platform method to retrieve an array of is
1029
- #
1030
- def is_for(identifier)
1031
- find_watir_elements("is(identifier)", Elements::Italic, identifier, 'i')
1032
- end
1033
-
1034
- private
1035
-
1036
- def find_watir_elements(the_call, type, identifier, tag_name=nil)
1037
- identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
1038
- elements = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
1039
- switch_to_default_content(frame_identifiers)
1040
- elements.map { |element| type.new(element) }
1041
- end
1042
-
1043
- def find_watir_element(the_call, type, identifier, tag_name=nil)
1044
- identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
1045
- element = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
1046
- switch_to_default_content(frame_identifiers)
1047
- type.new(element)
1048
- end
1049
-
1050
- def find_watir_pages(identifier, page_class)
1051
- identifier, frame_identifiers = parse_identifiers(identifier, Elements::Element, 'element')
1052
- elements = @browser.instance_eval "#{nested_frames(frame_identifiers)}elements(identifier)"
1053
- switch_to_default_content(frame_identifiers)
1054
- elements.map { |element| page_class.new(element) }
1055
- end
1056
-
1057
- def find_watir_page(identifier, page_class)
1058
- identifier, frame_identifiers = parse_identifiers(identifier, Elements::Element, 'element')
1059
- element = @browser.instance_eval "#{nested_frames(frame_identifiers)}element(identifier)"
1060
- switch_to_default_content(frame_identifiers)
1061
- page_class.new(element)
1062
- end
1063
-
1064
- def process_watir_call(the_call, type, identifier, value=nil, tag_name=nil)
1065
- identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
1066
- value = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
1067
- switch_to_default_content(frame_identifiers)
1068
- value
1069
- end
1070
-
1071
- def parse_identifiers(identifier, element, tag_name=nil)
1072
- new_identifiers = identifier.dup
1073
- frame_identifiers = new_identifiers.delete(:frame)
1074
- return new_identifiers, frame_identifiers
1075
- end
1076
-
1077
- def nested_frames(frame_identifiers)
1078
- return if frame_identifiers.nil?
1079
- frame_str = ''
1080
- frame_identifiers.each do |frame|
1081
- type = frame.keys.first
1082
- identifier = frame.values.first.map do |key, value|
1083
- if value.is_a?(Regexp)
1084
- ":#{key} => #{value.inspect}"
1085
- elsif value.is_a? Integer
1086
- ":#{key} => #{value}"
1087
- else
1088
- ":#{key} => '#{value}'"
1089
- end
1090
- end.join(', ')
1091
- frame_str += "#{type.to_s}(#{identifier})."
1092
- end
1093
- frame_str
1094
- end
1095
-
1096
- def switch_to_default_content(frame_identifiers)
1097
- @browser.browser.wd.switch_to.default_content unless frame_identifiers.nil?
1098
- end
1099
-
1100
- def switch_to_frame(frame_identifiers)
1101
- unless frame_identifiers.nil?
1102
- frame_identifiers.each do |frame|
1103
- frame_id = frame.values.first
1104
- value = frame_id.values.first
1105
- @browser.wd.switch_to.frame(value)
1106
- end
1107
- end
1108
- end
1109
-
1110
- def self.define_widget_multiple_accessor(base_element_tag, widget_class, widget_tag)
1111
- send(:define_method, "#{widget_tag}s_for") do |identifier|
1112
- find_watir_elements("#{base_element_tag}s(identifier)", widget_class, identifier, base_element_tag)
1113
- end
1114
- end
1115
-
1116
- def self.define_widget_singular_accessor(base_element_tag, widget_class, widget_tag)
1117
- send(:define_method, "#{widget_tag}_for") do |identifier|
1118
- find_watir_element("#{base_element_tag}(identifier)", widget_class, identifier, base_element_tag)
1119
- end
1120
- end
1121
- end
1122
- end
1123
- end
1124
- end
1
+ require 'page-object/elements'
2
+
3
+
4
+ module PageObject
5
+ module Platforms
6
+ module Watir
7
+
8
+ #
9
+ # Watir implementation of the page object platform driver. You should not use the
10
+ # class directly. Instead you should include the PageObject module in your page object
11
+ # and use the methods dynamically added from the PageObject::Accessors module.
12
+ #
13
+ class PageObject
14
+ attr_reader :browser
15
+
16
+ def self.define_widget_accessors(widget_tag, widget_class, base_element_tag)
17
+ define_widget_singular_accessor(base_element_tag, widget_class, widget_tag)
18
+ define_widget_multiple_accessor(base_element_tag, widget_class, widget_tag)
19
+ end
20
+
21
+ def initialize(browser)
22
+ @browser = browser
23
+ end
24
+
25
+ #
26
+ # platform method to navigate to a provided url
27
+ # See PageObject#navigate_to
28
+ #
29
+ def navigate_to(url)
30
+ @browser.goto url
31
+ end
32
+
33
+ #
34
+ # platform method to get the current url
35
+ # See PageObject#current_url
36
+ #
37
+ def current_url
38
+ @browser.url
39
+ end
40
+
41
+ #
42
+ # platform method to retrieve the text from the current page
43
+ # See PageObject#text
44
+ #
45
+ def text
46
+ @browser.text
47
+ end
48
+
49
+ #
50
+ # platform method to retrieve the html for the current page
51
+ # See PageObject#html
52
+ #
53
+ def html
54
+ @browser.html
55
+ end
56
+
57
+ #
58
+ # platform method to retrieve the title for the current page
59
+ # See PageObject#title
60
+ #
61
+ def title
62
+ @browser.title
63
+ end
64
+
65
+ #
66
+ # platform method to wait for a block to return true
67
+ # See PageObject#wait_until
68
+ def wait_until(timeout, message = nil, &block)
69
+ @browser.wait_until(timeout: timeout, message: message, &block)
70
+ end
71
+
72
+ #
73
+ # platform method to handle an alert popup
74
+ # See PageObject#alert
75
+ #
76
+ def alert(frame=nil, &block)
77
+ switch_to_frame(frame)
78
+ yield
79
+ value = nil
80
+ if @browser.alert.exists?
81
+ value = @browser.alert.text
82
+ @browser.alert.ok
83
+ end
84
+ switch_to_default_content(frame)
85
+ value
86
+ end
87
+
88
+ #
89
+ # platform method to handle a confirm popup
90
+ # See PageObject#confirm
91
+ #
92
+ def confirm(response, frame=nil, &block)
93
+ switch_to_frame(frame)
94
+ yield
95
+ value = nil
96
+ if @browser.alert.exists?
97
+ value = @browser.alert.text
98
+ response ? @browser.alert.ok : @browser.alert.close
99
+ end
100
+ switch_to_default_content(frame)
101
+ value
102
+ end
103
+
104
+ #
105
+ # platform method to handle a prompt popup
106
+ # See PageObject#prompt
107
+ #
108
+ def prompt(answer, frame=nil, &block)
109
+ switch_to_frame(frame)
110
+ @browser.wd.execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer}; }"
111
+ yield
112
+ result = @browser.wd.execute_script "return window.__lastWatirPrompt"
113
+ switch_to_default_content(frame)
114
+ result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
115
+ result
116
+ end
117
+
118
+ #
119
+ # platform method to execute javascript on the browser
120
+ # See PageObject#execute_script
121
+ #
122
+ def execute_script(script, *args)
123
+ @browser.execute_script(script, *args)
124
+ end
125
+
126
+ #
127
+ # platform method to handle attaching to a running window
128
+ # See PageObject#attach_to_window
129
+ #
130
+ def attach_to_window(identifier, &block)
131
+ win_id = {identifier.keys.first => /#{Regexp.escape(identifier.values.first)}/}
132
+ @browser.window(win_id).use &block
133
+ end
134
+
135
+ def element_with_focus
136
+ element = browser.execute_script("return document.activeElement")
137
+ type = element.type.to_sym if element.tag_name.to_sym == :input
138
+ cls = ::PageObject::Elements.element_class_for(element.tag_name, type)
139
+ cls.new(element)
140
+ end
141
+
142
+ #
143
+ # platform method to switch to a frame and execute a block
144
+ # See PageObject#in_frame
145
+ #
146
+ def in_frame(identifier, frame=nil, &block)
147
+ frame = [] if frame.nil?
148
+ frame << {frame: identifier}
149
+ block.call(frame)
150
+ end
151
+
152
+ #
153
+ # platform method to switch to an iframe and execute a block
154
+ # See PageObject#in_frame
155
+ #
156
+ def in_iframe(identifier, frame=nil, &block)
157
+ frame = [] if frame.nil?
158
+ frame << {iframe: identifier}
159
+ block.call(frame)
160
+ end
161
+
162
+ #
163
+ # platform method to refresh the page
164
+ # See PageObject#refresh
165
+ #
166
+ def refresh
167
+ @browser.refresh
168
+ end
169
+
170
+ #
171
+ # platform method to go back to the previous page
172
+ # See PageObject#back
173
+ #
174
+ def back
175
+ @browser.back
176
+ end
177
+
178
+ #
179
+ # platform method to go forward to the next page
180
+ # See PageObject#forward
181
+ #
182
+ def forward
183
+ @browser.forward
184
+ end
185
+
186
+ #
187
+ # platform method to clear the cookies from the browser
188
+ # See PageObject#clear_cookies
189
+ #
190
+ def clear_cookies
191
+ @browser.cookies.clear
192
+ end
193
+
194
+ #
195
+ # platform method to save the current screenshot to a file
196
+ # See PageObject#save_screenshot
197
+ #
198
+ def save_screenshot(file_name)
199
+ @browser.wd.save_screenshot(file_name)
200
+ end
201
+
202
+ #
203
+ # platform method to get the value stored in a text field
204
+ # See PageObject::Accessors#text_field
205
+ #
206
+ def text_field_value_for(identifier)
207
+ process_watir_call("text_field(identifier).value", Elements::TextField, identifier)
208
+ end
209
+
210
+ #
211
+ # platform method to set the value for a text field
212
+ # See PageObject::Accessors#text_field
213
+ #
214
+ def text_field_value_set(identifier, value)
215
+ process_watir_call("text_field(identifier).set(value)", Elements::TextField, identifier, value)
216
+ end
217
+
218
+ #
219
+ # platform method to retrieve a text field element
220
+ # See PageObject::Accessors#text_field
221
+ #
222
+ def text_field_for(identifier)
223
+ find_watir_element("text_field(identifier)", Elements::TextField, identifier)
224
+ end
225
+
226
+ #
227
+ # platform method to retrieve an array of text field elements
228
+ #
229
+ def text_fields_for(identifier)
230
+ elements = find_watir_elements("text_fields(identifier)", Elements::TextField, identifier)
231
+ elements.select { |e| e.element.tag_name == 'input' }
232
+ end
233
+
234
+ #
235
+ # platform method to get the value stored in a date field
236
+ # See PageObject::Accessors#date_field
237
+ #
238
+ def date_field_value_for(identifier)
239
+ process_watir_call("date_field(identifier).value", Elements::DateField, identifier)
240
+ end
241
+
242
+ #
243
+ # platform method to set the value for a date field
244
+ # See PageObject::Accessors#date_field
245
+ #
246
+ def date_field_value_set(identifier, value)
247
+ process_watir_call("date_field(identifier).set(value)", Elements::DateField, identifier, value)
248
+ end
249
+
250
+ #
251
+ # platform method to retrieve a date field element
252
+ # See PageObject::Accessors#date_field
253
+ #
254
+ def date_field_for(identifier)
255
+ find_watir_element("date_field(identifier)", Elements::DateField, identifier)
256
+ end
257
+
258
+ #
259
+ # platform method to retrieve an array of date field elements
260
+ #
261
+ def date_fields_for(identifier)
262
+ find_watir_elements("date_fields(identifier)", Elements::DateField, identifier)
263
+ end
264
+
265
+ #
266
+ # platform method to get the value stored in a hidden field
267
+ # See PageObject::Accessors#hidden_field
268
+ #
269
+ def hidden_field_value_for(identifier)
270
+ process_watir_call("hidden(identifier).value", Elements::HiddenField, identifier)
271
+ end
272
+
273
+ #
274
+ # platform method to retrieve a hidden field element
275
+ # See PageObject::Accessors#hidden_field
276
+ #
277
+ def hidden_field_for(identifier)
278
+ find_watir_element("hidden(identifier)", Elements::HiddenField, identifier)
279
+ end
280
+
281
+ #
282
+ # platform method to retrieve an array of hidden field elements
283
+ #
284
+ def hidden_fields_for(identifier)
285
+ find_watir_elements("hiddens(identifier)", Elements::HiddenField, identifier)
286
+ end
287
+
288
+ #
289
+ # platform method to set text in a textarea
290
+ # See PageObject::Accessors#text_area
291
+ #
292
+ def text_area_value_set(identifier, value)
293
+ process_watir_call("textarea(identifier).set(value)", Elements::TextArea,
294
+ identifier, value)
295
+ end
296
+
297
+ #
298
+ # platform method to get the text from a textarea
299
+ # See PageObject::Accessors#text_area
300
+ #
301
+ def text_area_value_for(identifier)
302
+ process_watir_call("textarea(identifier).value", Elements::TextArea, identifier)
303
+ end
304
+
305
+ #
306
+ # platform method to get the text area element
307
+ # See PageObject::Accessors#text_area
308
+ #
309
+ def text_area_for(identifier)
310
+ find_watir_element("textarea(identifier)", Elements::TextArea, identifier)
311
+ end
312
+
313
+ #
314
+ # platform method to retrieve an array of textarea elements
315
+ #
316
+ def text_areas_for(identifier)
317
+ find_watir_elements("textareas(identifier)", Elements::TextArea, identifier)
318
+ end
319
+
320
+ #
321
+ # platform method to get the currently selected value from a select list
322
+ # See PageObject::Accessors#select_list
323
+ #
324
+ def select_list_value_for(identifier)
325
+ options = find_watir_elements("select_list(identifier).selected_options",
326
+ Elements::SelectList, identifier)
327
+ return nil if options.empty?
328
+ options.first.text
329
+ end
330
+
331
+ #
332
+ # platform method to select a value from a select list
333
+ # See PageObject::Accessors#select_list
334
+ #
335
+ def select_list_value_set(identifier, value)
336
+ process_watir_call("select_list(identifier).select(value)", Elements::SelectList,
337
+ identifier, value)
338
+ end
339
+
340
+ #
341
+ # platform method to return the select list element
342
+ # See PageObject::Accessors#select_list
343
+ #
344
+ def select_list_for(identifier)
345
+ find_watir_element("select_list(identifier)", Elements::SelectList, identifier)
346
+ end
347
+
348
+ #
349
+ # platform method to retrieve an array of select_list elements
350
+ #
351
+ def select_lists_for(identifier)
352
+ find_watir_elements("select_lists(identifier)", Elements::SelectList, identifier)
353
+ end
354
+
355
+ #
356
+ # platform method to click a link
357
+ # See PageObject::Accessors#link
358
+ #
359
+ def click_link_for(identifier)
360
+ call = "link(identifier)"
361
+ process_watir_call("#{call}.click if identifier", Elements::Link, identifier)
362
+ end
363
+
364
+ #
365
+ # platform method to return a PageObject::Elements::Link object
366
+ # see PageObject::Accessors#link
367
+ #
368
+ def link_for(identifier)
369
+ call = "link(identifier)"
370
+ find_watir_element(call, Elements::Link, identifier)
371
+ end
372
+
373
+ #
374
+ # platform method to retrieve an array of link elements
375
+ #
376
+ def links_for(identifier)
377
+ call = "links(identifier)"
378
+ find_watir_elements(call, Elements::Link, identifier)
379
+ end
380
+
381
+ #
382
+ # platform method to check a checkbox
383
+ # See PageObject::Accessors#checkbox
384
+ #
385
+ def check_checkbox(identifier)
386
+ process_watir_call("checkbox(identifier).set", Elements::CheckBox, identifier)
387
+ end
388
+
389
+ #
390
+ # platform method to uncheck a checkbox
391
+ # See PageObject::Accessors#checkbox
392
+ #
393
+ def uncheck_checkbox(identifier)
394
+ process_watir_call("checkbox(identifier).clear", Elements::CheckBox, identifier)
395
+ end
396
+
397
+ #
398
+ # platform method to determine if a checkbox is checked
399
+ # See PageObject::Accessors#checkbox
400
+ #
401
+ def checkbox_checked?(identifier)
402
+ process_watir_call("checkbox(identifier).set?", Elements::CheckBox, identifier)
403
+ end
404
+
405
+ #
406
+ # platform method to return a PageObject::Elements::CheckBox element
407
+ # See PageObject::Accessors#checkbox
408
+ #
409
+ def checkbox_for(identifier)
410
+ find_watir_element("checkbox(identifier)", Elements::CheckBox, identifier)
411
+ end
412
+
413
+ #
414
+ # platform method to retrieve an array of checkbox elements
415
+ #
416
+ def checkboxs_for(identifier)
417
+ find_watir_elements("checkboxes(identifier)", Elements::CheckBox, identifier)
418
+ end
419
+
420
+ #
421
+ # platform method to select a radio button
422
+ # See PageObject::Accessors#radio_button
423
+ #
424
+ def select_radio(identifier)
425
+ process_watir_call("radio(identifier).set", Elements::RadioButton, identifier)
426
+ end
427
+
428
+ #
429
+ # platform method to determine if a radio button is selected
430
+ # See PageObject::Accessors#radio_button
431
+ #
432
+ def radio_selected?(identifier)
433
+ process_watir_call("radio(identifier).set?", Elements::RadioButton, identifier)
434
+ end
435
+
436
+ #
437
+ # platform method to return a PageObject::Eements::RadioButton element
438
+ # See PageObject::Accessors#radio_button
439
+ #
440
+ def radio_button_for(identifier)
441
+ find_watir_element("radio(identifier)", Elements::RadioButton, identifier)
442
+ end
443
+
444
+ #
445
+ # platform method to retrieve an array of radio button elements
446
+ #
447
+ def radio_buttons_for(identifier)
448
+ find_watir_elements("radios(identifier)", Elements::RadioButton, identifier)
449
+ end
450
+
451
+ #
452
+ # platform method to return the text for a div
453
+ # See PageObject::Accessors#div
454
+ #
455
+ def div_text_for(identifier)
456
+ process_watir_call("div(identifier).text", Elements::Div, identifier, nil, 'div')
457
+ end
458
+
459
+ #
460
+ # platform method to return a PageObject::Elements::Div element
461
+ # See PageObject::Accessors#div
462
+ #
463
+ def div_for(identifier)
464
+ find_watir_element("div(identifier)", Elements::Div, identifier, 'div')
465
+ end
466
+
467
+ #
468
+ # platform method to retrieve an array of div elements
469
+ #
470
+ def divs_for(identifier)
471
+ find_watir_elements("divs(identifier)", Elements::Div, identifier, 'div')
472
+ end
473
+
474
+ #
475
+ # platform method to return the text for a span
476
+ # See PageObject::Accessors#span
477
+ #
478
+ def span_text_for(identifier)
479
+ process_watir_call("span(identifier).text", Elements::Span, identifier, nil, 'span')
480
+ end
481
+
482
+ #
483
+ # platform method to return a PageObject::Elements::Span element
484
+ # See PageObject::Accessors#span
485
+ #
486
+ def span_for(identifier)
487
+ find_watir_element("span(identifier)", Elements::Span, identifier, 'span')
488
+ end
489
+
490
+ #
491
+ # platform method to retrieve an array of span elements
492
+ #
493
+ def spans_for(identifier)
494
+ find_watir_elements("spans(identifier)", Elements::Span, identifier, 'span')
495
+ end
496
+
497
+ #
498
+ # platform method to click a button
499
+ # See PageObject::Accessors#button
500
+ #
501
+ def click_button_for(identifier)
502
+ call = "button(identifier)"
503
+ process_watir_call("#{call}.click", Elements::Button, identifier)
504
+ end
505
+
506
+ #
507
+ # platform method to retrieve a button element
508
+ # See PageObject::Accessors#button
509
+ #
510
+ def button_for(identifier)
511
+ call = "button(identifier)"
512
+ find_watir_element(call, Elements::Button, identifier)
513
+ end
514
+
515
+ #
516
+ # platform method to retrieve an array of button elements
517
+ #
518
+ def buttons_for(identifier)
519
+ call = "buttons(identifier)"
520
+ find_watir_elements(call, Elements::Button, identifier)
521
+ end
522
+
523
+ #
524
+ # platform method to return the text for a table
525
+ # See PageObject::Accessors#table
526
+ #
527
+ def table_text_for(identifier)
528
+ process_watir_call("table(identifier).text", Elements::Table, identifier, nil, 'table')
529
+ end
530
+
531
+ #
532
+ # platform method to retrieve a table element
533
+ # See PageObject::Accessors#table
534
+ #
535
+ def table_for(identifier)
536
+ find_watir_element("table(identifier)", Elements::Table, identifier, 'table')
537
+ end
538
+
539
+ #
540
+ # platform method to retrieve an array of table elements
541
+ #
542
+ def tables_for(identifier)
543
+ find_watir_elements("tables(identifier)", Elements::Table, identifier, 'table')
544
+ end
545
+
546
+ #
547
+ # platform method to retrieve the text from a table cell
548
+ # See PageObject::Accessors#cell
549
+ #
550
+ def cell_text_for(identifier)
551
+ process_watir_call("td(identifier).text", Elements::TableCell, identifier,
552
+ nil, 'td')
553
+ end
554
+
555
+ #
556
+ # platform method to retrieve a table cell element
557
+ # See PageObject::Accessors#cell
558
+ #
559
+ def cell_for(identifier)
560
+ find_watir_element("td(identifier)", Elements::TableCell, identifier, 'td')
561
+ end
562
+
563
+ #
564
+ # platform method to retrieve an array of table cell elements
565
+ #
566
+ def cells_for(identifier)
567
+ find_watir_elements("tds(identifier)", Elements::TableCell, identifier, 'td')
568
+ end
569
+
570
+ #
571
+ # platform method to retrieve the text from a table row
572
+ # See PageObject::Accessors#row
573
+ #
574
+ def row_text_for(identifier)
575
+ process_watir_call("tr(identifier).text", Elements::TableRow, identifier,
576
+ nil, 'tr')
577
+ end
578
+
579
+ #
580
+ # platform method to retrieve a table row element
581
+ # See PageObject::Accessors#row
582
+ #
583
+ def row_for(identifier)
584
+ find_watir_element("tr(identifier)", Elements::TableRow, identifier, 'tr')
585
+ end
586
+
587
+ #
588
+ # platform method to retrieve an array of table row elements
589
+ #
590
+ def rows_for(identifier)
591
+ find_watir_elements("trs(identifier)", Elements::TableRow, identifier, 'tr')
592
+ end
593
+
594
+ #
595
+ # platform method to retrieve load status of an image element
596
+ # See PageObject::Accessors#image
597
+ #
598
+ def image_loaded_for(identifier)
599
+ process_watir_call("image(identifier).loaded?", Elements::Image, identifier)
600
+ end
601
+
602
+ #
603
+ # platform method to retrieve an image element
604
+ # See PageObject::Accessors#image
605
+ #
606
+ def image_for(identifier)
607
+ find_watir_element("image(identifier)", Elements::Image, identifier)
608
+ end
609
+
610
+ #
611
+ # platform method to retrieve an array of image elements
612
+ #
613
+ def images_for(identifier)
614
+ find_watir_elements("images(identifier)", Elements::Image, identifier)
615
+ end
616
+
617
+ #
618
+ # platform method to retrieve a form element
619
+ # See PageObject::Accessors#form
620
+ #
621
+ def form_for(identifier)
622
+ find_watir_element("form(identifier)", Elements::Form, identifier)
623
+ end
624
+
625
+ #
626
+ # platform method to retrieve an array of forms
627
+ #
628
+ def forms_for(identifier)
629
+ find_watir_elements("forms(identifier)", Elements::Form, identifier)
630
+ end
631
+
632
+ #
633
+ # platform method to retrieve the text from a list item
634
+ # See PageObject::Accessors#list_item
635
+ #
636
+ def list_item_text_for(identifier)
637
+ process_watir_call("li(identifier).text", Elements::ListItem, identifier, nil, 'li')
638
+ end
639
+
640
+ #
641
+ # platform method to retrieve a list item element
642
+ # See PageObject::Accessors#list_item
643
+ #
644
+ def list_item_for(identifier)
645
+ find_watir_element("li(identifier)", Elements::ListItem, identifier, 'li')
646
+ end
647
+
648
+ #
649
+ # platform method to retrieve an array of list items
650
+ #
651
+ def list_items_for(identifier)
652
+ find_watir_elements("lis(identifier)", Elements::ListItem, identifier, 'li')
653
+ end
654
+
655
+ #
656
+ # platform method to retrieve the text from an unordered list
657
+ # See PageObject::Accessors#unordered_list
658
+ #
659
+ def unordered_list_text_for(identifier)
660
+ process_watir_call("ul(identifier).text", Elements::UnorderedList, identifier, nil, 'ul')
661
+ end
662
+
663
+ #
664
+ # platform method to retrieve an unordered list element
665
+ # See PageObject::Accessors#unordered_list
666
+ #
667
+ def unordered_list_for(identifier)
668
+ find_watir_element("ul(identifier)", Elements::UnorderedList, identifier, 'ul')
669
+ end
670
+
671
+ #
672
+ # platform method to retrieve an array of unordered lists
673
+ #
674
+ def unordered_lists_for(identifier)
675
+ find_watir_elements("uls(identifier)", Elements::UnorderedList, identifier, 'ul')
676
+ end
677
+
678
+ #
679
+ # platform method to retrieve the text from an ordered list
680
+ # See PageObject::Accessors#ordered_list
681
+ #
682
+ def ordered_list_text_for(identifier)
683
+ process_watir_call("ol(identifier).text", Elements::OrderedList, identifier, nil, 'ol')
684
+ end
685
+
686
+ #
687
+ # platform method to retrieve an ordered list element
688
+ # See PageObject::Accessors#ordered_list
689
+ #
690
+ def ordered_list_for(identifier)
691
+ find_watir_element("ol(identifier)", Elements::OrderedList, identifier, 'ol')
692
+ end
693
+
694
+ #
695
+ # platform method to retrieve an array of ordered lists
696
+ #
697
+ def ordered_lists_for(identifier)
698
+ find_watir_elements("ols(identifier)", Elements::OrderedList, identifier, 'ol')
699
+ end
700
+
701
+ #
702
+ # platform method to retrieve the text for a h1
703
+ # See PageObject::Accessors#h1
704
+ #
705
+ def h1_text_for(identifier)
706
+ process_watir_call("h1(identifier).text", Elements::Heading, identifier, nil, 'h1')
707
+ end
708
+
709
+ #
710
+ # platform method to retrieve the h1 element
711
+ # See PageObject::Accessors#h1
712
+ #
713
+ def h1_for(identifier)
714
+ find_watir_element("h1(identifier)", Elements::Heading, identifier, 'h1')
715
+ end
716
+
717
+ #
718
+ # platform method to retrieve an array of h1s
719
+ #
720
+ def h1s_for(identifier)
721
+ find_watir_elements("h1s(identifier)", Elements::Heading, identifier, 'h1')
722
+ end
723
+
724
+ #
725
+ # platform method to retrieve the text for a h2
726
+ # See PageObject::Accessors#h2
727
+ #
728
+ def h2_text_for(identifier)
729
+ process_watir_call("h2(identifier).text", Elements::Heading, identifier, nil, 'h2')
730
+ end
731
+
732
+ #
733
+ # platform method to retrieve the h2 element
734
+ # See PageObject::Accessors#h2
735
+ #
736
+ def h2_for(identifier)
737
+ find_watir_element("h2(identifier)", Elements::Heading, identifier, 'h2')
738
+ end
739
+
740
+ #
741
+ # platform method to retrieve an array of h2s
742
+ #
743
+ def h2s_for(identifier)
744
+ find_watir_elements("h2s(identifier)", Elements::Heading, identifier, 'h2')
745
+ end
746
+
747
+ #
748
+ # platform method to retrieve the text for a h3
749
+ # See PageObject::Accessors#h3
750
+ #
751
+ def h3_text_for(identifier)
752
+ process_watir_call("h3(identifier).text", Elements::Heading, identifier, nil, 'h3')
753
+ end
754
+
755
+ #
756
+ # platform method to retrieve the h3 element
757
+ # See PageObject::Accessors#h3
758
+ #
759
+ def h3_for(identifier)
760
+ find_watir_element("h3(identifier)", Elements::Heading, identifier, 'h3')
761
+ end
762
+
763
+ #
764
+ # platform method to retrieve an array of h3s
765
+ #
766
+ def h3s_for(identifier)
767
+ find_watir_elements("h3s(identifier)", Elements::Heading, identifier, 'h3')
768
+ end
769
+
770
+ #
771
+ # platform method to retrieve the text for a h4
772
+ # See PageObject::Accessors#h4
773
+ #
774
+ def h4_text_for(identifier)
775
+ process_watir_call("h4(identifier).text", Elements::Heading, identifier, nil, 'h4')
776
+ end
777
+
778
+ #
779
+ # platform method to retrieve the h4 element
780
+ # See PageObject::Accessors#h4
781
+ #
782
+ def h4_for(identifier)
783
+ find_watir_element("h4(identifier)", Elements::Heading, identifier, 'h4')
784
+ end
785
+
786
+ #
787
+ # platform method to retrieve an array of h4s
788
+ #
789
+ def h4s_for(identifier)
790
+ find_watir_elements("h4s(identifier)", Elements::Heading, identifier, 'h4')
791
+ end
792
+
793
+ #
794
+ # platform method to retrieve the text for a h5
795
+ # See PageObject::Accessors#h5
796
+ #
797
+ def h5_text_for(identifier)
798
+ process_watir_call("h5(identifier).text", Elements::Heading, identifier, nil, 'h5')
799
+ end
800
+
801
+ #
802
+ # platform method to retrieve the h5 element
803
+ # See PageObject::Accessors#h5
804
+ #
805
+ def h5_for(identifier)
806
+ find_watir_element("h5(identifier)", Elements::Heading, identifier, 'h5')
807
+ end
808
+
809
+ #
810
+ # platform method to retrieve an array of h5s
811
+ #
812
+ def h5s_for(identifier)
813
+ find_watir_elements("h5s(identifier)", Elements::Heading, identifier, 'h5')
814
+ end
815
+
816
+ #
817
+ # platform method to retrieve the text for a h6
818
+ # See PageObject::Accessors#h6
819
+ #
820
+ def h6_text_for(identifier)
821
+ process_watir_call("h6(identifier).text", Elements::Heading, identifier, nil, 'h6')
822
+ end
823
+
824
+ #
825
+ # platform method to retrieve the h6 element
826
+ # See PageObject::Accessors#h6
827
+ #
828
+ def h6_for(identifier)
829
+ find_watir_element("h6(identifier)", Elements::Heading, identifier, 'h6')
830
+ end
831
+
832
+ #
833
+ # platform method to retrieve an array of h6s
834
+ #
835
+ def h6s_for(identifier)
836
+ find_watir_elements("h6s(identifier)", Elements::Heading, identifier, 'h6')
837
+ end
838
+
839
+ #
840
+ # platform method to retrieve the text for a paragraph
841
+ # See PageObject::Accessors#paragraph
842
+ #
843
+ def paragraph_text_for(identifier)
844
+ process_watir_call("p(identifier).text", Elements::Paragraph, identifier, nil, 'p')
845
+ end
846
+
847
+ #
848
+ # platform method to retrieve the paragraph element
849
+ # See PageObject::Accessors#paragraph
850
+ #
851
+ def paragraph_for(identifier)
852
+ find_watir_element("p(identifier)", Elements::Paragraph, identifier, 'p')
853
+ end
854
+
855
+ #
856
+ # platform method to retrieve an array of paragraph elements
857
+ #
858
+ def paragraphs_for(identifier)
859
+ find_watir_elements("ps(identifier)", Elements::Paragraph, identifier, 'p')
860
+ end
861
+
862
+ #
863
+ # platform method to return the text for a label
864
+ # See PageObject::Accessors#label
865
+ #
866
+ def label_text_for(identifier)
867
+ process_watir_call("label(identifier).text", Elements::Label, identifier, nil, 'label')
868
+ end
869
+
870
+ #
871
+ # platform method to return a PageObject::Elements::Label element
872
+ # See PageObject::Accessors#label
873
+ #
874
+ def label_for(identifier)
875
+ find_watir_element("label(identifier)", Elements::Label, identifier, 'label')
876
+ end
877
+
878
+ #
879
+ #
880
+ # platform method to retrieve an array of label elements
881
+ #
882
+ def labels_for(identifier)
883
+ find_watir_elements("labels(identifier)", Elements::Label, identifier, 'label')
884
+ end
885
+
886
+ #
887
+ # platform method to set the file on a file_field element
888
+ # See PageObject::Accessors#file_field
889
+ #
890
+ def file_field_value_set(identifier, value)
891
+ process_watir_call("file_field(identifier).set(value)", Elements::FileField,
892
+ identifier, value)
893
+ end
894
+
895
+ #
896
+ # platform method to retrieve a file_field element
897
+ # See PageObject::Accessors#file_field
898
+ #
899
+ def file_field_for(identifier)
900
+ find_watir_element("file_field(identifier)", Elements::FileField, identifier)
901
+ end
902
+
903
+ #
904
+ # platform method to retrieve an array of file field elements
905
+ #
906
+ def file_fields_for(identifier)
907
+ find_watir_elements("file_fields(identifier)", Elements::FileField, identifier)
908
+ end
909
+
910
+ #
911
+ # platform method to click on an area
912
+ #
913
+ def click_area_for(identifier)
914
+ process_watir_call("area(identifier).click", Elements::Area, identifier, nil, 'area')
915
+ end
916
+
917
+ #
918
+ # platform method to retrieve an area element
919
+ #
920
+ def area_for(identifier)
921
+ find_watir_element("area(identifier)", Elements::Area, identifier, 'area')
922
+ end
923
+
924
+ #
925
+ # platform method to retrieve an array of area elements
926
+ #
927
+ def areas_for(identifier)
928
+ find_watir_elements("areas(identifier)", Elements::Area, identifier, 'area')
929
+ end
930
+
931
+ #
932
+ # platform method to retrieve a canvas element
933
+ #
934
+ def canvas_for(identifier)
935
+ find_watir_element("canvas(identifier)", Elements::Canvas, identifier, 'canvas')
936
+ end
937
+
938
+ #
939
+ # platform method to retrieve an array of canvas elements
940
+ #
941
+ def canvass_for(identifier)
942
+ find_watir_elements("canvases(identifier)", Elements::Canvas, identifier, 'canvas')
943
+ end
944
+
945
+ #
946
+ # platform method to retrieve an audio element
947
+ #
948
+ def audio_for(identifier)
949
+ find_watir_element("audio(identifier)", Elements::Audio, identifier, 'audio')
950
+ end
951
+
952
+ #
953
+ # platform method to retrieve an array of audio elements
954
+ #
955
+ def audios_for(identifier)
956
+ find_watir_elements("audios(identifier)", Elements::Audio, identifier, 'audio')
957
+ end
958
+
959
+ #
960
+ # platform method to retrieve a video element
961
+ #
962
+ def video_for(identifier)
963
+ find_watir_element("video(identifier)", Elements::Video, identifier, 'video')
964
+ end
965
+
966
+ #
967
+ # platform method to retrieve an array of video elements
968
+ #
969
+ def videos_for(identifier)
970
+ find_watir_elements("videos(identifier)", Elements::Video, identifier, 'video')
971
+ end
972
+
973
+ #
974
+ # platform method to return a PageObject::Elements::Element element
975
+ # See PageObject::Accessors#element
976
+ #
977
+ def element_for(tag, identifier)
978
+ find_watir_element("#{tag.to_s}(identifier)", Elements::Element, identifier, tag.to_s)
979
+ end
980
+
981
+ #
982
+ # platform method to return an array of PageObject::Elements::Element elements
983
+ # See PageObject::Accessors#element
984
+ #
985
+ def elements_for(tag, identifier)
986
+ find_watir_elements("#{tag.to_s}s(identifier)", Elements::Element, identifier, tag.to_s)
987
+ end
988
+
989
+ #
990
+ # platform method to return a PageObject rooted at an element
991
+ # See PageObject::Accessors#page_section
992
+ #
993
+ def page_for(identifier, page_class)
994
+ find_watir_page(identifier, page_class)
995
+ end
996
+
997
+ #
998
+ # platform method to return a collection of PageObjects rooted at elements
999
+ # See PageObject::Accessors#page_sections
1000
+ #
1001
+ def pages_for(identifier, page_class)
1002
+ SectionCollection[*find_watir_pages(identifier, page_class)]
1003
+ end
1004
+
1005
+ #
1006
+ # platform method to return a svg element
1007
+ #
1008
+ def svg_for(identifier)
1009
+ find_watir_element("element(identifier)", Elements::Element, identifier)
1010
+ end
1011
+
1012
+ #
1013
+ # platform method to return an array of svg elements
1014
+ #
1015
+ def svgs_for(identifier)
1016
+ find_watir_elements("element(identifier)", Elements::Element, identifier)
1017
+ end
1018
+
1019
+ #
1020
+ # platform method to retrieve the text for a b
1021
+ # See PageObject::Accessors#b
1022
+ #
1023
+ def b_text_for(identifier)
1024
+ process_watir_call("b(identifier).text", Elements::Bold, identifier, nil, 'b')
1025
+ end
1026
+
1027
+ #
1028
+ # platform method to retrieve the b element
1029
+ # See PageObject::Accessors#b
1030
+ #
1031
+ def b_for(identifier)
1032
+ find_watir_element("b(identifier)", Elements::Bold, identifier, 'b')
1033
+ end
1034
+
1035
+ #
1036
+ # platform method to retrieve an array of bs
1037
+ #
1038
+ def bs_for(identifier)
1039
+ find_watir_elements("bs(identifier)", Elements::Bold, identifier, 'b')
1040
+ end
1041
+
1042
+ #
1043
+ # platform method to retrieve the text for a i
1044
+ # See PageObject::Accessors#i
1045
+ #
1046
+ def i_text_for(identifier)
1047
+ process_watir_call("i(identifier).text", Elements::Italic, identifier, nil, 'i')
1048
+ end
1049
+
1050
+ #
1051
+ # platform method to retrieve the i element
1052
+ # See PageObject::Accessors#i
1053
+ #
1054
+ def i_for(identifier)
1055
+ find_watir_element("i(identifier)", Elements::Italic, identifier, 'i')
1056
+ end
1057
+
1058
+ #
1059
+ # platform method to retrieve an array of is
1060
+ #
1061
+ def is_for(identifier)
1062
+ find_watir_elements("is(identifier)", Elements::Italic, identifier, 'i')
1063
+ end
1064
+
1065
+ private
1066
+
1067
+ def find_watir_elements(the_call, type, identifier, tag_name=nil)
1068
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
1069
+ elements = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
1070
+ switch_to_default_content(frame_identifiers)
1071
+ elements.map { |element| type.new(element) }
1072
+ end
1073
+
1074
+ def find_watir_element(the_call, type, identifier, tag_name=nil)
1075
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
1076
+ element = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
1077
+ switch_to_default_content(frame_identifiers)
1078
+ type.new(element)
1079
+ end
1080
+
1081
+ def find_watir_pages(identifier, page_class)
1082
+ identifier, frame_identifiers = parse_identifiers(identifier, Elements::Element, 'element')
1083
+ elements = @browser.instance_eval "#{nested_frames(frame_identifiers)}elements(identifier)"
1084
+ switch_to_default_content(frame_identifiers)
1085
+ elements.map { |element| page_class.new(element) }
1086
+ end
1087
+
1088
+ def find_watir_page(identifier, page_class)
1089
+ identifier, frame_identifiers = parse_identifiers(identifier, Elements::Element, 'element')
1090
+ element = @browser.instance_eval "#{nested_frames(frame_identifiers)}element(identifier)"
1091
+ switch_to_default_content(frame_identifiers)
1092
+ page_class.new(element)
1093
+ end
1094
+
1095
+ def process_watir_call(the_call, type, identifier, value=nil, tag_name=nil)
1096
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
1097
+ value = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
1098
+ switch_to_default_content(frame_identifiers)
1099
+ value
1100
+ end
1101
+
1102
+ def parse_identifiers(identifier, element, tag_name=nil)
1103
+ new_identifiers = identifier.dup
1104
+ frame_identifiers = new_identifiers.delete(:frame)
1105
+ return new_identifiers, frame_identifiers
1106
+ end
1107
+
1108
+ def nested_frames(frame_identifiers)
1109
+ return if frame_identifiers.nil?
1110
+ frame_str = ''
1111
+ frame_identifiers.each do |frame|
1112
+ type = frame.keys.first
1113
+ identifier = frame.values.first.map do |key, value|
1114
+ if value.is_a?(Regexp)
1115
+ ":#{key} => #{value.inspect}"
1116
+ elsif value.is_a?(Integer) || value.is_a?(TrueClass) || value.is_a?(FalseClass)
1117
+ ":#{key} => #{value}"
1118
+ else
1119
+ ":#{key} => '#{value}'"
1120
+ end
1121
+ end.join(', ')
1122
+ frame_str += "#{type.to_s}(#{identifier})."
1123
+ end
1124
+ frame_str
1125
+ end
1126
+
1127
+ def switch_to_default_content(frame_identifiers)
1128
+ @browser.browser.wd.switch_to.default_content unless frame_identifiers.nil?
1129
+ end
1130
+
1131
+ def switch_to_frame(frame_identifiers)
1132
+ unless frame_identifiers.nil?
1133
+ frame_identifiers.each do |frame|
1134
+ frame_id = frame.values.first
1135
+ value = frame_id.values.first
1136
+ @browser.wd.switch_to.frame(value)
1137
+ end
1138
+ end
1139
+ end
1140
+
1141
+ def self.define_widget_multiple_accessor(base_element_tag, widget_class, widget_tag)
1142
+ send(:define_method, "#{widget_tag}s_for") do |identifier|
1143
+ find_watir_elements("#{base_element_tag}s(identifier)", widget_class, identifier, base_element_tag)
1144
+ end
1145
+ end
1146
+
1147
+ def self.define_widget_singular_accessor(base_element_tag, widget_class, widget_tag)
1148
+ send(:define_method, "#{widget_tag}_for") do |identifier|
1149
+ find_watir_element("#{base_element_tag}(identifier)", widget_class, identifier, base_element_tag)
1150
+ end
1151
+ end
1152
+ end
1153
+ end
1154
+ end
1155
+ end