meeane-page-object 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (253) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -7
  3. data/.rspec +2 -2
  4. data/.ruby-gemset +1 -1
  5. data/.ruby-version +1 -1
  6. data/.travis.yml +10 -10
  7. data/ChangeLog +790 -790
  8. data/Gemfile +13 -13
  9. data/Guardfile +20 -20
  10. data/LICENSE +20 -20
  11. data/README.md +1 -1
  12. data/Rakefile +35 -35
  13. data/cucumber.yml +10 -10
  14. data/features/area.feature +35 -35
  15. data/features/async.feature +30 -30
  16. data/features/audio.feature +68 -68
  17. data/features/button.feature +88 -87
  18. data/features/canvas.feature +37 -37
  19. data/features/check_box.feature +55 -55
  20. data/features/div.feature +45 -45
  21. data/features/element.feature +322 -322
  22. data/features/file_field.feature +40 -40
  23. data/features/form.feature +43 -43
  24. data/features/frames.feature +75 -75
  25. data/features/generic_elements.feature +29 -29
  26. data/features/gxt_table_extension.feature +24 -24
  27. data/features/headings.feature +97 -97
  28. data/features/hidden_field.feature +45 -45
  29. data/features/html/async.html +36 -36
  30. data/features/html/double_click.html +12 -12
  31. data/features/html/failure.html +7 -7
  32. data/features/html/frame_1.html +17 -17
  33. data/features/html/frame_2.html +15 -15
  34. data/features/html/frame_3.html +14 -14
  35. data/features/html/frames.html +12 -12
  36. data/features/html/hover.html +11 -11
  37. data/features/html/iframes.html +12 -12
  38. data/features/html/indexed_property.html +51 -51
  39. data/features/html/modal.html +17 -17
  40. data/features/html/modal_1.html +37 -37
  41. data/features/html/modal_2.html +26 -26
  42. data/features/html/multi_elements.html +144 -144
  43. data/features/html/nested_elements.html +77 -77
  44. data/features/html/nested_frame_2.html +11 -11
  45. data/features/html/nested_frame_3.html +14 -14
  46. data/features/html/nested_frames.html +10 -10
  47. data/features/html/static_elements.html +233 -226
  48. data/features/html/success.html +7 -7
  49. data/features/html/sun.html +7 -7
  50. data/features/image.feature +50 -50
  51. data/features/indexed_property.feature +97 -97
  52. data/features/javascript.feature +27 -27
  53. data/features/label.feature +46 -46
  54. data/features/link.feature +52 -52
  55. data/features/list_item.feature +36 -36
  56. data/features/modal_dialog.feature +15 -15
  57. data/features/multi_elements.feature +486 -486
  58. data/features/nested_elements.feature +117 -117
  59. data/features/ordered_list.feature +56 -56
  60. data/features/page_level_actions.feature +90 -90
  61. data/features/paragraph.feature +35 -35
  62. data/features/radio_button.feature +58 -58
  63. data/features/radio_button_collinson.feature +12 -58
  64. data/features/radio_button_group.feature +29 -29
  65. data/features/sample-app/public/jquery-1.3.2.js +4376 -4376
  66. data/features/sample-app/public/jquery.html +30 -30
  67. data/features/sample-app/public/prototype-1.6.0.3.js +4319 -4319
  68. data/features/sample-app/public/prototype.html +35 -35
  69. data/features/sample-app/sample_app.rb +35 -35
  70. data/features/select_list.feature +86 -86
  71. data/features/span.feature +37 -37
  72. data/features/step_definitions/accessor_steps.rb +60 -60
  73. data/features/step_definitions/area_steps.rb +19 -19
  74. data/features/step_definitions/async_steps.rb +83 -83
  75. data/features/step_definitions/audio_steps.rb +27 -27
  76. data/features/step_definitions/button_steps.rb +43 -43
  77. data/features/step_definitions/canvas_steps.rb +15 -15
  78. data/features/step_definitions/check_box_steps.rb +35 -35
  79. data/features/step_definitions/div_steps.rb +19 -19
  80. data/features/step_definitions/element_steps.rb +266 -266
  81. data/features/step_definitions/file_field_steps.rb +19 -19
  82. data/features/step_definitions/form_steps.rb +18 -18
  83. data/features/step_definitions/frames_steps.rb +159 -159
  84. data/features/step_definitions/generic_element_steps.rb +31 -31
  85. data/features/step_definitions/gxt_table_steps.rb +58 -58
  86. data/features/step_definitions/headings_steps.rb +12 -12
  87. data/features/step_definitions/hidden_field_steps.rb +26 -26
  88. data/features/step_definitions/image_steps.rb +27 -27
  89. data/features/step_definitions/indexed_property_steps.rb +128 -128
  90. data/features/step_definitions/javascript_steps.rb +52 -52
  91. data/features/step_definitions/label_steps.rb +19 -19
  92. data/features/step_definitions/link_steps.rb +40 -40
  93. data/features/step_definitions/list_item_steps.rb +19 -19
  94. data/features/step_definitions/modal_dialog_steps.rb +62 -62
  95. data/features/step_definitions/multi_elements_steps.rb +528 -528
  96. data/features/step_definitions/nested_elements_steps.rb +212 -212
  97. data/features/step_definitions/ordered_list_steps.rb +23 -23
  98. data/features/step_definitions/page_level_actions_steps.rb +135 -135
  99. data/features/step_definitions/page_traversal_steps.rb +4 -4
  100. data/features/step_definitions/paragraph_steps.rb +28 -28
  101. data/features/step_definitions/radio_button_collinson_steps.rb +2 -46
  102. data/features/step_definitions/radio_button_group_steps.rb +35 -35
  103. data/features/step_definitions/radio_button_steps.rb +26 -46
  104. data/features/step_definitions/select_list_steps.rb +65 -65
  105. data/features/step_definitions/span_steps.rb +19 -19
  106. data/features/step_definitions/table_cell_steps.rb +14 -14
  107. data/features/step_definitions/table_steps.rb +66 -66
  108. data/features/step_definitions/text_area_steps.rb +34 -34
  109. data/features/step_definitions/text_field_steps.rb +35 -35
  110. data/features/step_definitions/unordered_list_steps.rb +23 -23
  111. data/features/step_definitions/video_steps.rb +45 -45
  112. data/features/support/ajax_text_environment.rb +26 -26
  113. data/features/support/env.rb +8 -8
  114. data/features/support/hooks.rb +8 -8
  115. data/features/support/page.rb +370 -364
  116. data/features/support/persistent_browser.rb +70 -70
  117. data/features/support/targets/firefox14_osx.rb +6 -6
  118. data/features/support/targets/firefox14_windows7.rb +6 -6
  119. data/features/support/url_helper.rb +57 -57
  120. data/features/table.feature +114 -114
  121. data/features/table_cell.feature +45 -45
  122. data/features/text_area.feature +51 -51
  123. data/features/text_field.feature +70 -70
  124. data/features/unordered_list.feature +56 -56
  125. data/features/video.feature +73 -73
  126. data/lib/page-object.rb +408 -408
  127. data/lib/page-object/accessors.rb +1313 -1313
  128. data/lib/page-object/core_ext/string.rb +4 -4
  129. data/lib/page-object/element_locators.rb +21 -21
  130. data/lib/page-object/elements.rb +59 -59
  131. data/lib/page-object/elements/area.rb +31 -31
  132. data/lib/page-object/elements/audio.rb +9 -9
  133. data/lib/page-object/elements/button.rb +35 -35
  134. data/lib/page-object/elements/canvas.rb +23 -23
  135. data/lib/page-object/elements/check_box.rb +37 -37
  136. data/lib/page-object/elements/div.rb +19 -19
  137. data/lib/page-object/elements/element.rb +226 -226
  138. data/lib/page-object/elements/file_field.rb +38 -38
  139. data/lib/page-object/elements/form.rb +36 -36
  140. data/lib/page-object/elements/heading.rb +15 -15
  141. data/lib/page-object/elements/hidden_field.rb +22 -22
  142. data/lib/page-object/elements/image.rb +36 -36
  143. data/lib/page-object/elements/label.rb +36 -36
  144. data/lib/page-object/elements/link.rb +46 -46
  145. data/lib/page-object/elements/list_item.rb +19 -19
  146. data/lib/page-object/elements/media.rb +45 -45
  147. data/lib/page-object/elements/option.rb +10 -10
  148. data/lib/page-object/elements/ordered_list.rb +50 -50
  149. data/lib/page-object/elements/paragraph.rb +9 -9
  150. data/lib/page-object/elements/radio_button.rb +37 -37
  151. data/lib/page-object/elements/select_list.rb +42 -42
  152. data/lib/page-object/elements/span.rb +19 -19
  153. data/lib/page-object/elements/table.rb +68 -68
  154. data/lib/page-object/elements/table_cell.rb +28 -28
  155. data/lib/page-object/elements/table_row.rb +50 -50
  156. data/lib/page-object/elements/text_area.rb +38 -38
  157. data/lib/page-object/elements/text_field.rb +42 -42
  158. data/lib/page-object/elements/unordered_list.rb +51 -51
  159. data/lib/page-object/elements/video.rb +18 -18
  160. data/lib/page-object/indexed_properties.rb +36 -36
  161. data/lib/page-object/javascript/jquery.rb +14 -14
  162. data/lib/page-object/javascript/prototype.rb +14 -14
  163. data/lib/page-object/javascript/yui.rb +18 -18
  164. data/lib/page-object/javascript_framework_facade.rb +78 -78
  165. data/lib/page-object/loads_platform.rb +26 -26
  166. data/lib/page-object/locator_generator.rb +129 -129
  167. data/lib/page-object/nested_elements.rb +17 -17
  168. data/lib/page-object/page_factory.rb +108 -108
  169. data/lib/page-object/page_populator.rb +92 -92
  170. data/lib/page-object/platforms.rb +18 -18
  171. data/lib/page-object/platforms/selenium_webdriver.rb +17 -17
  172. data/lib/page-object/platforms/selenium_webdriver/button.rb +14 -14
  173. data/lib/page-object/platforms/selenium_webdriver/check_box.rb +29 -29
  174. data/lib/page-object/platforms/selenium_webdriver/element.rb +291 -291
  175. data/lib/page-object/platforms/selenium_webdriver/file_field.rb +16 -16
  176. data/lib/page-object/platforms/selenium_webdriver/form.rb +16 -16
  177. data/lib/page-object/platforms/selenium_webdriver/image.rb +28 -28
  178. data/lib/page-object/platforms/selenium_webdriver/label.rb +17 -18
  179. data/lib/page-object/platforms/selenium_webdriver/link.rb +23 -23
  180. data/lib/page-object/platforms/selenium_webdriver/ordered_list.rb +39 -39
  181. data/lib/page-object/platforms/selenium_webdriver/page_object.rb +1136 -1136
  182. data/lib/page-object/platforms/selenium_webdriver/radio_button.rb +22 -22
  183. data/lib/page-object/platforms/selenium_webdriver/select_list.rb +93 -93
  184. data/lib/page-object/platforms/selenium_webdriver/surrogate_selenium_element.rb +42 -42
  185. data/lib/page-object/platforms/selenium_webdriver/table.rb +42 -42
  186. data/lib/page-object/platforms/selenium_webdriver/table_row.rb +43 -43
  187. data/lib/page-object/platforms/selenium_webdriver/text_area.rb +17 -17
  188. data/lib/page-object/platforms/selenium_webdriver/text_field.rb +17 -17
  189. data/lib/page-object/platforms/selenium_webdriver/unordered_list.rb +39 -39
  190. data/lib/page-object/platforms/watir_webdriver.rb +18 -18
  191. data/lib/page-object/platforms/watir_webdriver/check_box.rb +29 -29
  192. data/lib/page-object/platforms/watir_webdriver/element.rb +249 -249
  193. data/lib/page-object/platforms/watir_webdriver/file_field.rb +16 -16
  194. data/lib/page-object/platforms/watir_webdriver/form.rb +16 -16
  195. data/lib/page-object/platforms/watir_webdriver/image.rb +22 -22
  196. data/lib/page-object/platforms/watir_webdriver/label.rb +17 -18
  197. data/lib/page-object/platforms/watir_webdriver/link.rb +15 -15
  198. data/lib/page-object/platforms/watir_webdriver/ordered_list.rb +35 -35
  199. data/lib/page-object/platforms/watir_webdriver/page_object.rb +1029 -1029
  200. data/lib/page-object/platforms/watir_webdriver/radio_button.rb +22 -22
  201. data/lib/page-object/platforms/watir_webdriver/select_list.rb +74 -74
  202. data/lib/page-object/platforms/watir_webdriver/table.rb +38 -38
  203. data/lib/page-object/platforms/watir_webdriver/table_row.rb +37 -37
  204. data/lib/page-object/platforms/watir_webdriver/text_area.rb +23 -23
  205. data/lib/page-object/platforms/watir_webdriver/text_field.rb +16 -16
  206. data/lib/page-object/platforms/watir_webdriver/unordered_list.rb +36 -36
  207. data/lib/page-object/version.rb +4 -4
  208. data/lib/page-object/widgets.rb +133 -133
  209. data/meeane-page-object.gemspec +32 -32
  210. data/spec/page-object/element_locators_spec.rb +1065 -1065
  211. data/spec/page-object/elements/area_spec.rb +45 -45
  212. data/spec/page-object/elements/button_spec.rb +50 -50
  213. data/spec/page-object/elements/canvas_spec.rb +40 -40
  214. data/spec/page-object/elements/check_box_spec.rb +49 -49
  215. data/spec/page-object/elements/div_spec.rb +28 -28
  216. data/spec/page-object/elements/element_spec.rb +114 -114
  217. data/spec/page-object/elements/file_field_spec.rb +39 -39
  218. data/spec/page-object/elements/form_spec.rb +28 -28
  219. data/spec/page-object/elements/heading_spec.rb +48 -48
  220. data/spec/page-object/elements/hidden_field_spec.rb +28 -28
  221. data/spec/page-object/elements/image_spec.rb +66 -66
  222. data/spec/page-object/elements/label_spec.rb +29 -29
  223. data/spec/page-object/elements/link_spec.rb +49 -49
  224. data/spec/page-object/elements/list_item_spec.rb +28 -28
  225. data/spec/page-object/elements/nested_element_spec.rb +254 -254
  226. data/spec/page-object/elements/option_spec.rb +11 -11
  227. data/spec/page-object/elements/ordered_list_spec.rb +94 -94
  228. data/spec/page-object/elements/paragraph_spec.rb +28 -28
  229. data/spec/page-object/elements/select_list_spec.rb +142 -142
  230. data/spec/page-object/elements/selenium/radio_button_spec.rb +44 -44
  231. data/spec/page-object/elements/selenium/text_field_spec.rb +49 -49
  232. data/spec/page-object/elements/selenium_element_spec.rb +172 -172
  233. data/spec/page-object/elements/span_spec.rb +26 -26
  234. data/spec/page-object/elements/table_cell_spec.rb +21 -21
  235. data/spec/page-object/elements/table_row_spec.rb +70 -70
  236. data/spec/page-object/elements/table_spec.rb +98 -98
  237. data/spec/page-object/elements/text_area_spec.rb +39 -39
  238. data/spec/page-object/elements/unordered_list_spec.rb +95 -95
  239. data/spec/page-object/elements/watir_element_spec.rb +142 -142
  240. data/spec/page-object/javascript_framework_facade_spec.rb +61 -61
  241. data/spec/page-object/loads_platform_spec.rb +53 -53
  242. data/spec/page-object/page-object_spec.rb +405 -405
  243. data/spec/page-object/page_factory_spec.rb +256 -256
  244. data/spec/page-object/page_populator_spec.rb +122 -122
  245. data/spec/page-object/platforms/selenium_webdriver/selenium_page_object_spec.rb +68 -68
  246. data/spec/page-object/platforms/selenium_webdriver_spec.rb +28 -28
  247. data/spec/page-object/platforms/watir_webdriver/watir_page_object_spec.rb +29 -29
  248. data/spec/page-object/platforms/watir_webdriver_spec.rb +9 -9
  249. data/spec/page-object/selenium_accessors_spec.rb +589 -589
  250. data/spec/page-object/watir_accessors_spec.rb +1107 -1107
  251. data/spec/page-object/widget_spec.rb +226 -226
  252. data/spec/spec_helper.rb +44 -44
  253. metadata +193 -43
@@ -1,16 +1,16 @@
1
- module PageObject
2
- module Platforms
3
- module WatirWebDriver
4
-
5
- module FileField
6
-
7
- #
8
- # Set the value of the FileField
9
- #
10
- def value=(new_value)
11
- element.set(new_value)
12
- end
13
- end
14
- end
15
- end
16
- end
1
+ module PageObject
2
+ module Platforms
3
+ module WatirWebDriver
4
+
5
+ module FileField
6
+
7
+ #
8
+ # Set the value of the FileField
9
+ #
10
+ def value=(new_value)
11
+ element.set(new_value)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,16 +1,16 @@
1
- module PageObject
2
- module Platforms
3
- module WatirWebDriver
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
1
+ module PageObject
2
+ module Platforms
3
+ module WatirWebDriver
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
@@ -1,22 +1,22 @@
1
- module PageObject
2
- module Platforms
3
- module WatirWebDriver
4
- module Image
5
-
6
- #
7
- # Return the width of the image.
8
- #
9
- def width
10
- element.width
11
- end
12
-
13
- #
14
- # Return the height of the image
15
- #
16
- def height
17
- element.height
18
- end
19
- end
20
- end
21
- end
22
- end
1
+ module PageObject
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module Image
5
+
6
+ #
7
+ # Return the width of the image.
8
+ #
9
+ def width
10
+ element.width
11
+ end
12
+
13
+ #
14
+ # Return the height of the image
15
+ #
16
+ def height
17
+ element.height
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,18 +1,17 @@
1
- module PageObject
2
- module Platforms
3
- module WatirWebDriver
4
- module Label
5
-
6
- #
7
- # choose the label
8
- #
9
- def choose
10
- sleep 0.5
11
- element.click
12
- wait_for_ajax
13
- end
14
-
15
- end
16
- end
17
- end
18
- end
1
+ module PageObject
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module Label
5
+
6
+ #
7
+ # choose the label
8
+ #
9
+ def choose
10
+ element.click
11
+ wait_for_ajax
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,15 +1,15 @@
1
- module PageObject
2
- module Platforms
3
- module WatirWebDriver
4
- module Link
5
-
6
- #
7
- # return the href for the link
8
- #
9
- def href
10
- element.href
11
- end
12
- end
13
- end
14
- end
15
- end
1
+ module PageObject
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module Link
5
+
6
+ #
7
+ # return the href for the link
8
+ #
9
+ def href
10
+ element.href
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,35 +1,35 @@
1
- module PageObject
2
- module Platforms
3
- module WatirWebDriver
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
- Object::PageObject::Elements::ListItem.new(children[idx], :platform => :watir_webdriver)
14
- end
15
-
16
- #
17
- # Return the number of items contained in the ordered list
18
- #
19
- def items
20
- children.size
21
- end
22
-
23
- private
24
-
25
- def children
26
- list_items.find_all { |item| item.parent == element }
27
- end
28
-
29
- def list_items
30
- element.ols(:xpath => child_xpath)
31
- end
32
- end
33
- end
34
- end
35
- end
1
+ module PageObject
2
+ module Platforms
3
+ module WatirWebDriver
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
+ Object::PageObject::Elements::ListItem.new(children[idx], :platform => :watir_webdriver)
14
+ end
15
+
16
+ #
17
+ # Return the number of items contained in the ordered list
18
+ #
19
+ def items
20
+ children.size
21
+ end
22
+
23
+ private
24
+
25
+ def children
26
+ list_items.find_all { |item| item.parent == element }
27
+ end
28
+
29
+ def list_items
30
+ element.ols(:xpath => child_xpath)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,1029 +1,1029 @@
1
- require 'watir-webdriver/extensions/alerts'
2
- require 'page-object/elements'
3
- require 'page-object/core_ext/string'
4
-
5
-
6
- module PageObject
7
- module Platforms
8
- module WatirWebDriver
9
- #
10
- # Watir implementation of the page object platform driver. You should not use the
11
- # class directly. Instead you should include the PageObject module in your page object
12
- # and use the methods dynamically added from the PageObject::Accessors module.
13
- #
14
- class PageObject
15
- attr_reader :browser
16
-
17
- def initialize(browser)
18
- @browser = browser
19
- end
20
-
21
- #
22
- # platform method to navigate to a provided url
23
- # See PageObject#navigate_to
24
- #
25
- def navigate_to(url)
26
- @browser.goto url
27
- end
28
-
29
- #
30
- # platform method to get the current url
31
- # See PageObject#current_url
32
- #
33
- def current_url
34
- @browser.url
35
- end
36
-
37
- #
38
- # platform method to retrieve the text from the current page
39
- # See PageObject#text
40
- #
41
- def text
42
- @browser.text
43
- end
44
-
45
- #
46
- # platform method to retrieve the html for the current page
47
- # See PageObject#html
48
- #
49
- def html
50
- @browser.html
51
- end
52
-
53
- #
54
- # platform method to retrieve the title for the current page
55
- # See PageObject#title
56
- #
57
- def title
58
- @browser.title
59
- end
60
-
61
- #
62
- # platform method to wait for a block to return true
63
- # See PageObject#wait_until
64
- def wait_until(timeout, message = nil, &block)
65
- @browser.wait_until(timeout, message, &block)
66
- end
67
-
68
- #
69
- # platform method to handle an alert popup
70
- # See PageObject#alert
71
- #
72
- def alert(frame=nil, &block)
73
- switch_to_frame(frame)
74
- yield
75
- value = nil
76
- if @browser.alert.exists?
77
- value = @browser.alert.text
78
- @browser.alert.ok
79
- end
80
- switch_to_default_content(frame)
81
- value
82
- end
83
-
84
- #
85
- # platform method to handle a confirm popup
86
- # See PageObject#confirm
87
- #
88
- def confirm(response, frame=nil, &block)
89
- switch_to_frame(frame)
90
- yield
91
- value = nil
92
- if @browser.alert.exists?
93
- value = @browser.alert.text
94
- response ? @browser.alert.ok : @browser.alert.close
95
- end
96
- switch_to_default_content(frame)
97
- value
98
- end
99
-
100
- #
101
- # platform method to handle a prompt popup
102
- # See PageObject#prompt
103
- #
104
- def prompt(answer, frame=nil, &block)
105
- switch_to_frame(frame)
106
- @browser.wd.execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer}; }"
107
- yield
108
- result = @browser.wd.execute_script "return window.__lastWatirPrompt"
109
- switch_to_default_content(frame)
110
- result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
111
- result
112
- end
113
-
114
- #
115
- # platform method to execute javascript on the browser
116
- # See PageObject#execute_script
117
- #
118
- def execute_script(script, *args)
119
- @browser.execute_script(script, *args)
120
- end
121
-
122
- #
123
- # platform method to handle attaching to a running window
124
- # See PageObject#attach_to_window
125
- #
126
- def attach_to_window(identifier, &block)
127
- win_id = {identifier.keys.first => /#{Regexp.escape(identifier.values.first)}/}
128
- @browser.window(win_id).use &block
129
- end
130
-
131
- def element_with_focus
132
- element = browser.execute_script("return document.activeElement")
133
- type = element.type.to_sym if element.tag_name.to_sym == :input
134
- cls = ::PageObject::Elements.element_class_for(element.tag_name, type)
135
- cls.new(element, :platform => :watir_webdriver)
136
- end
137
-
138
- #
139
- # platform method to switch to a frame and execute a block
140
- # See PageObject#in_frame
141
- #
142
- def in_frame(identifier, frame=nil, &block)
143
- frame = [] if frame.nil?
144
- frame << {frame: identifier}
145
- block.call(frame)
146
- end
147
-
148
- #
149
- # platform method to switch to an iframe and execute a block
150
- # See PageObject#in_frame
151
- #
152
- def in_iframe(identifier, frame=nil, &block)
153
- frame = [] if frame.nil?
154
- frame << {iframe: identifier}
155
- block.call(frame)
156
- end
157
-
158
- #
159
- # platform method to refresh the page
160
- # See PageObject#refresh
161
- #
162
- def refresh
163
- @browser.refresh
164
- end
165
-
166
- #
167
- # platform method to go back to the previous page
168
- # See PageObject#back
169
- #
170
- def back
171
- @browser.back
172
- end
173
-
174
- #
175
- # platform method to go forward to the next page
176
- # See PageObject#forward
177
- #
178
- def forward
179
- @browser.forward
180
- end
181
-
182
- #
183
- # platform method to clear the cookies from the browser
184
- # See PageObject#clear_cookies
185
- #
186
- def clear_cookies
187
- @browser.cookies.clear
188
- end
189
-
190
- #
191
- # platform method to save the current screenshot to a file
192
- # See PageObject#save_screenshot
193
- #
194
- def save_screenshot(file_name)
195
- @browser.wd.save_screenshot(file_name)
196
- end
197
-
198
- #
199
- # platform method to get the value stored in a text field
200
- # See PageObject::Accessors#text_field
201
- #
202
- def text_field_value_for(identifier)
203
- process_watir_call("text_field(identifier).value", Elements::TextField, identifier)
204
- end
205
-
206
- #
207
- # platform method to set the value for a text field
208
- # See PageObject::Accessors#text_field
209
- #
210
- def text_field_value_set(identifier, value)
211
- process_watir_call("text_field(identifier).set(value)", Elements::TextField, identifier, value)
212
- end
213
-
214
- #
215
- # platform method to retrieve a text field element
216
- # See PageObject::Accessors#text_field
217
- #
218
- def text_field_for(identifier)
219
- find_watir_element("text_field(identifier)", Elements::TextField, identifier)
220
- end
221
-
222
- #
223
- # platform method to retrieve an array of text field elements
224
- #
225
- def text_fields_for(identifier)
226
- elements = find_watir_elements("text_fields(identifier)", Elements::TextField, identifier)
227
- elements.select {|e| e.element.tag_name == 'input'}
228
- end
229
-
230
- #
231
- # platform method to get the value stored in a hidden field
232
- # See PageObject::Accessors#hidden_field
233
- #
234
- def hidden_field_value_for(identifier)
235
- process_watir_call("hidden(identifier).value", Elements::HiddenField, identifier)
236
- end
237
-
238
- #
239
- # platform method to retrieve a hidden field element
240
- # See PageObject::Accessors#hidden_field
241
- #
242
- def hidden_field_for(identifier)
243
- find_watir_element("hidden(identifier)", Elements::HiddenField, identifier)
244
- end
245
-
246
- #
247
- # platform method to retrieve an array of hidden field elements
248
- #
249
- def hidden_fields_for(identifier)
250
- find_watir_elements("hiddens(identifier)", Elements::HiddenField, identifier)
251
- end
252
-
253
- #
254
- # platform method to set text in a textarea
255
- # See PageObject::Accessors#text_area
256
- #
257
- def text_area_value_set(identifier, value)
258
- process_watir_call("textarea(identifier).set(value)", Elements::TextArea,
259
- identifier, value)
260
- end
261
-
262
- #
263
- # platform method to get the text from a textarea
264
- # See PageObject::Accessors#text_area
265
- #
266
- def text_area_value_for(identifier)
267
- process_watir_call("textarea(identifier).value", Elements::TextArea, identifier)
268
- end
269
-
270
- #
271
- # platform method to get the text area element
272
- # See PageObject::Accessors#text_area
273
- #
274
- def text_area_for(identifier)
275
- find_watir_element("textarea(identifier)", Elements::TextArea, identifier)
276
- end
277
-
278
- #
279
- # platform method to retrieve an array of textarea elements
280
- #
281
- def text_areas_for(identifier)
282
- find_watir_elements("textareas(identifier)", Elements::TextArea, identifier)
283
- end
284
-
285
- #
286
- # platform method to get the currently selected value from a select list
287
- # See PageObject::Accessors#select_list
288
- #
289
- def select_list_value_for(identifier)
290
- process_watir_call("select_list(identifier).options.find {|o| o.selected?}.text",
291
- Elements::SelectList, identifier)
292
- end
293
-
294
- #
295
- # platform method to select a value from a select list
296
- # See PageObject::Accessors#select_list
297
- #
298
- def select_list_value_set(identifier, value)
299
- process_watir_call("select_list(identifier).select(value)", Elements::SelectList,
300
- identifier, value)
301
- end
302
-
303
- #
304
- # platform method to return the select list element
305
- # See PageObject::Accessors#select_list
306
- #
307
- def select_list_for(identifier)
308
- find_watir_element("select_list(identifier)", Elements::SelectList, identifier)
309
- end
310
-
311
- #
312
- # platform method to retrieve an array of select_list elements
313
- #
314
- def select_lists_for(identifier)
315
- find_watir_elements("select_lists(identifier)", Elements::SelectList, identifier)
316
- end
317
-
318
- #
319
- # platform method to click a link
320
- # See PageObject::Accessors#link
321
- #
322
- def click_link_for(identifier)
323
- call = call_for_watir_element(identifier, "link(identifier)")
324
- process_watir_call("#{call}.click if identifier", Elements::Link, identifier)
325
- end
326
-
327
- #
328
- # platform method to return a PageObject::Elements::Link object
329
- # see PageObject::Accessors#link
330
- #
331
- def link_for(identifier)
332
- call = call_for_watir_element(identifier, "link(identifier)")
333
- find_watir_element(call, Elements::Link, identifier)
334
- end
335
-
336
- #
337
- # platform method to retrieve an array of link elements
338
- #
339
- def links_for(identifier)
340
- call = call_for_watir_elements(identifier, "links(identifier)")
341
- find_watir_elements(call, Elements::Link, identifier)
342
- end
343
-
344
- #
345
- # platform method to check a checkbox
346
- # See PageObject::Accessors#checkbox
347
- #
348
- def check_checkbox(identifier)
349
- process_watir_call("checkbox(identifier).set", Elements::CheckBox, identifier)
350
- end
351
-
352
- #
353
- # platform method to uncheck a checkbox
354
- # See PageObject::Accessors#checkbox
355
- #
356
- def uncheck_checkbox(identifier)
357
- process_watir_call("checkbox(identifier).clear", Elements::CheckBox, identifier)
358
- end
359
-
360
- #
361
- # platform method to determine if a checkbox is checked
362
- # See PageObject::Accessors#checkbox
363
- #
364
- def checkbox_checked?(identifier)
365
- process_watir_call("checkbox(identifier).set?", Elements::CheckBox, identifier)
366
- end
367
-
368
- #
369
- # platform method to return a PageObject::Elements::CheckBox element
370
- # See PageObject::Accessors#checkbox
371
- #
372
- def checkbox_for(identifier)
373
- find_watir_element("checkbox(identifier)", Elements::CheckBox, identifier)
374
- end
375
-
376
- #
377
- # platform method to retrieve an array of checkbox elements
378
- #
379
- def checkboxs_for(identifier)
380
- find_watir_elements("checkboxes(identifier)", Elements::CheckBox, identifier)
381
- end
382
-
383
- #
384
- # platform method to select a radio button
385
- # See PageObject::Accessors#radio_button
386
- #
387
- def select_radio(identifier)
388
- process_watir_call("radio(identifier).set", Elements::RadioButton, identifier)
389
- end
390
-
391
- #
392
- # platform method to determine if a radio button is selected
393
- # See PageObject::Accessors#radio_button
394
- #
395
- def radio_selected?(identifier)
396
- process_watir_call("radio(identifier).set?", Elements::RadioButton, identifier)
397
- end
398
-
399
- #
400
- # platform method to return a PageObject::Eements::RadioButton element
401
- # See PageObject::Accessors#radio_button
402
- #
403
- def radio_button_for(identifier)
404
- find_watir_element("radio(identifier)", Elements::RadioButton, identifier)
405
- end
406
-
407
- #
408
- # platform method to retrieve an array of radio button elements
409
- #
410
- def radio_buttons_for(identifier)
411
- find_watir_elements("radios(identifier)", Elements::RadioButton, identifier)
412
- end
413
-
414
- #
415
- # platform method to return the text for a div
416
- # See PageObject::Accessors#div
417
- #
418
- def div_text_for(identifier)
419
- process_watir_call("div(identifier).text", Elements::Div, identifier, nil, 'div')
420
- end
421
-
422
- #
423
- # platform method to return a PageObject::Elements::Div element
424
- # See PageObject::Accessors#div
425
- #
426
- def div_for(identifier)
427
- find_watir_element("div(identifier)", Elements::Div, identifier, 'div')
428
- end
429
-
430
- #
431
- # platform method to retrieve an array of div elements
432
- #
433
- def divs_for(identifier)
434
- find_watir_elements("divs(identifier)", Elements::Div, identifier, 'div')
435
- end
436
-
437
- #
438
- # platform method to return the text for a span
439
- # See PageObject::Accessors#span
440
- #
441
- def span_text_for(identifier)
442
- process_watir_call("span(identifier).text", Elements::Span, identifier, nil, 'span')
443
- end
444
-
445
- #
446
- # platform method to return a PageObject::Elements::Span element
447
- # See PageObject::Accessors#span
448
- #
449
- def span_for(identifier)
450
- find_watir_element("span(identifier)", Elements::Span, identifier, 'span')
451
- end
452
-
453
- #
454
- # platform method to retrieve an array of span elements
455
- #
456
- def spans_for(identifier)
457
- find_watir_elements("spans(identifier)", Elements::Span, identifier, 'span')
458
- end
459
-
460
- #
461
- # platform method to click a button
462
- # See PageObject::Accessors#button
463
- #
464
- def click_button_for(identifier)
465
- call = call_for_watir_element(identifier, "button(identifier)")
466
- process_watir_call("#{call}.click", Elements::Button, identifier)
467
- end
468
-
469
- #
470
- # platform method to retrieve a button element
471
- # See PageObject::Accessors#button
472
- #
473
- def button_for(identifier)
474
- call = call_for_watir_element(identifier, "button(identifier)")
475
- find_watir_element(call, Elements::Button, identifier)
476
- end
477
-
478
- #
479
- # platform method to retrieve an array of button elements
480
- #
481
- def buttons_for(identifier)
482
- call = call_for_watir_elements(identifier, "buttons(identifier)")
483
- find_watir_elements(call, Elements::Button, identifier)
484
- end
485
-
486
- #
487
- # platform method to return the text for a table
488
- # See PageObject::Accessors#table
489
- #
490
- def table_text_for(identifier)
491
- process_watir_call("table(identifier).text", Elements::Table, identifier, nil, 'table')
492
- end
493
-
494
- #
495
- # platform method to retrieve a table element
496
- # See PageObject::Accessors#table
497
- #
498
- def table_for(identifier)
499
- find_watir_element("table(identifier)", Elements::Table, identifier, 'table')
500
- end
501
-
502
- #
503
- # platform method to retrieve an array of table elements
504
- #
505
- def tables_for(identifier)
506
- find_watir_elements("tables(identifier)", Elements::Table, identifier, 'table')
507
- end
508
-
509
- #
510
- # platform method to retrieve the text from a table cell
511
- # See PageObject::Accessors#cell
512
- #
513
- def cell_text_for(identifier)
514
- process_watir_call("td(identifier).text", Elements::TableCell, identifier,
515
- nil, 'td')
516
- end
517
-
518
- #
519
- # platform method to retrieve a table cell element
520
- # See PageObject::Accessors#cell
521
- #
522
- def cell_for(identifier)
523
- find_watir_element("td(identifier)", Elements::TableCell, identifier, 'td')
524
- end
525
-
526
- #
527
- # platform method to retrieve an array of table cell elements
528
- #
529
- def cells_for(identifier)
530
- find_watir_elements("tds(identifier)", Elements::TableCell, identifier, 'td')
531
- end
532
-
533
- #
534
- # platform method to retrieve an image element
535
- # See PageObject::Accessors#image
536
- #
537
- def image_for(identifier)
538
- find_watir_element("image(identifier)", Elements::Image, identifier)
539
- end
540
-
541
- #
542
- # platform method to retrieve an array of image elements
543
- #
544
- def images_for(identifier)
545
- find_watir_elements("images(identifier)", Elements::Image, identifier)
546
- end
547
-
548
- #
549
- # platform method to retrieve a form element
550
- # See PageObject::Accessors#form
551
- #
552
- def form_for(identifier)
553
- find_watir_element("form(identifier)", Elements::Form, identifier)
554
- end
555
-
556
- #
557
- # platform method to retrieve an array of forms
558
- #
559
- def forms_for(identifier)
560
- find_watir_elements("forms(identifier)", Elements::Form, identifier)
561
- end
562
-
563
- #
564
- # platform method to retrieve the text from a list item
565
- # See PageObject::Accessors#list_item
566
- #
567
- def list_item_text_for(identifier)
568
- process_watir_call("li(identifier).text", Elements::ListItem, identifier, nil, 'li')
569
- end
570
-
571
- #
572
- # platform method to retrieve a list item element
573
- # See PageObject::Accessors#list_item
574
- #
575
- def list_item_for(identifier)
576
- find_watir_element("li(identifier)", Elements::ListItem, identifier, 'li')
577
- end
578
-
579
- #
580
- # platform method to retrieve an array of list items
581
- #
582
- def list_items_for(identifier)
583
- find_watir_elements("lis(identifier)", Elements::ListItem, identifier, 'li')
584
- end
585
-
586
- #
587
- # platform method to retrieve the text from an unordered list
588
- # See PageObject::Accessors#unordered_list
589
- #
590
- def unordered_list_text_for(identifier)
591
- process_watir_call("ul(identifier).text", Elements::UnorderedList, identifier, nil, 'ul')
592
- end
593
-
594
- #
595
- # platform method to retrieve an unordered list element
596
- # See PageObject::Accessors#unordered_list
597
- #
598
- def unordered_list_for(identifier)
599
- find_watir_element("ul(identifier)", Elements::UnorderedList, identifier, 'ul')
600
- end
601
-
602
- #
603
- # platform method to retrieve an array of unordered lists
604
- #
605
- def unordered_lists_for(identifier)
606
- find_watir_elements("uls(identifier)", Elements::UnorderedList, identifier, 'ul')
607
- end
608
-
609
- #
610
- # platform method to retrieve the text from an ordered list
611
- # See PageObject::Accessors#ordered_list
612
- #
613
- def ordered_list_text_for(identifier)
614
- process_watir_call("ol(identifier).text", Elements::OrderedList, identifier, nil, 'ol')
615
- end
616
-
617
- #
618
- # platform method to retrieve an ordered list element
619
- # See PageObject::Accessors#ordered_list
620
- #
621
- def ordered_list_for(identifier)
622
- find_watir_element("ol(identifier)", Elements::OrderedList, identifier, 'ol')
623
- end
624
-
625
- #
626
- # platform method to retrieve an array of ordered lists
627
- #
628
- def ordered_lists_for(identifier)
629
- find_watir_elements("ols(identifier)", Elements::OrderedList, identifier, 'ol')
630
- end
631
-
632
- #
633
- # platform method to retrieve the text for a h1
634
- # See PageObject::Accessors#h1
635
- #
636
- def h1_text_for(identifier)
637
- process_watir_call("h1(identifier).text", Elements::Heading, identifier, nil, 'h1')
638
- end
639
-
640
- #
641
- # platform method to retrieve the h1 element
642
- # See PageObject::Accessors#h1
643
- #
644
- def h1_for(identifier)
645
- find_watir_element("h1(identifier)", Elements::Heading, identifier, 'h1')
646
- end
647
-
648
- #
649
- # platform method to retrieve an array of h1s
650
- #
651
- def h1s_for(identifier)
652
- find_watir_elements("h1s(identifier)", Elements::Heading, identifier, 'h1')
653
- end
654
-
655
- #
656
- # platform method to retrieve the text for a h2
657
- # See PageObject::Accessors#h2
658
- #
659
- def h2_text_for(identifier)
660
- process_watir_call("h2(identifier).text", Elements::Heading, identifier, nil, 'h2')
661
- end
662
-
663
- #
664
- # platform method to retrieve the h2 element
665
- # See PageObject::Accessors#h2
666
- #
667
- def h2_for(identifier)
668
- find_watir_element("h2(identifier)", Elements::Heading, identifier, 'h2')
669
- end
670
-
671
- #
672
- # platform method to retrieve an array of h2s
673
- #
674
- def h2s_for(identifier)
675
- find_watir_elements("h2s(identifier)", Elements::Heading, identifier, 'h2')
676
- end
677
-
678
- #
679
- # platform method to retrieve the text for a h3
680
- # See PageObject::Accessors#h3
681
- #
682
- def h3_text_for(identifier)
683
- process_watir_call("h3(identifier).text", Elements::Heading, identifier, nil, 'h3')
684
- end
685
-
686
- #
687
- # platform method to retrieve the h3 element
688
- # See PageObject::Accessors#h3
689
- #
690
- def h3_for(identifier)
691
- find_watir_element("h3(identifier)", Elements::Heading, identifier, 'h3')
692
- end
693
-
694
- #
695
- # platform method to retrieve an array of h3s
696
- #
697
- def h3s_for(identifier)
698
- find_watir_elements("h3s(identifier)", Elements::Heading, identifier, 'h3')
699
- end
700
-
701
- #
702
- # platform method to retrieve the text for a h4
703
- # See PageObject::Accessors#h4
704
- #
705
- def h4_text_for(identifier)
706
- process_watir_call("h4(identifier).text", Elements::Heading, identifier, nil, 'h4')
707
- end
708
-
709
- #
710
- # platform method to retrieve the h4 element
711
- # See PageObject::Accessors#h4
712
- #
713
- def h4_for(identifier)
714
- find_watir_element("h4(identifier)", Elements::Heading, identifier, 'h4')
715
- end
716
-
717
- #
718
- # platform method to retrieve an array of h4s
719
- #
720
- def h4s_for(identifier)
721
- find_watir_elements("h4s(identifier)", Elements::Heading, identifier, 'h4')
722
- end
723
-
724
- #
725
- # platform method to retrieve the text for a h5
726
- # See PageObject::Accessors#h5
727
- #
728
- def h5_text_for(identifier)
729
- process_watir_call("h5(identifier).text", Elements::Heading, identifier, nil, 'h5')
730
- end
731
-
732
- #
733
- # platform method to retrieve the h5 element
734
- # See PageObject::Accessors#h5
735
- #
736
- def h5_for(identifier)
737
- find_watir_element("h5(identifier)", Elements::Heading, identifier, 'h5')
738
- end
739
-
740
- #
741
- # platform method to retrieve an array of h5s
742
- #
743
- def h5s_for(identifier)
744
- find_watir_elements("h5s(identifier)", Elements::Heading, identifier, 'h5')
745
- end
746
-
747
- #
748
- # platform method to retrieve the text for a h6
749
- # See PageObject::Accessors#h6
750
- #
751
- def h6_text_for(identifier)
752
- process_watir_call("h6(identifier).text", Elements::Heading, identifier, nil, 'h6')
753
- end
754
-
755
- #
756
- # platform method to retrieve the h6 element
757
- # See PageObject::Accessors#h6
758
- #
759
- def h6_for(identifier)
760
- find_watir_element("h6(identifier)", Elements::Heading, identifier, 'h6')
761
- end
762
-
763
- #
764
- # platform method to retrieve an array of h6s
765
- #
766
- def h6s_for(identifier)
767
- find_watir_elements("h6s(identifier)", Elements::Heading, identifier, 'h6')
768
- end
769
-
770
- #
771
- # platform method to retrieve the text for a paragraph
772
- # See PageObject::Accessors#paragraph
773
- #
774
- def paragraph_text_for(identifier)
775
- process_watir_call("p(identifier).text", Elements::Paragraph, identifier, nil, 'p')
776
- end
777
-
778
- #
779
- # platform method to retrieve the paragraph element
780
- # See PageObject::Accessors#paragraph
781
- #
782
- def paragraph_for(identifier)
783
- find_watir_element("p(identifier)", Elements::Paragraph, identifier, 'p')
784
- end
785
-
786
- #
787
- # platform method to retrieve an array of paragraph elements
788
- #
789
- def paragraphs_for(identifier)
790
- find_watir_elements("ps(identifier)", Elements::Paragraph, identifier, 'p')
791
- end
792
-
793
- #
794
- # platform method to return the text for a label
795
- # See PageObject::Accessors#label
796
- #
797
- def label_text_for(identifier)
798
- process_watir_call("label(identifier).text", Elements::Label, identifier, nil, 'label')
799
- end
800
-
801
- #
802
- # platform method to return a PageObject::Elements::Label element
803
- # See PageObject::Accessors#label
804
- #
805
- def label_for(identifier)
806
- find_watir_element("label(identifier)", Elements::Label, identifier, 'label')
807
- end
808
-
809
- #
810
- # platform method to return a PageObject::Element::Label element
811
- # See PageObject::Accessors#label
812
- #
813
- def choose_label(identifier)
814
- process_watir_call("label(identifier).click", Elements::Label, identifier, 'label')
815
- end
816
-
817
- #
818
- #
819
- # platform method to retrieve an array of label elements
820
- #
821
- def labels_for(identifier)
822
- find_watir_elements("labels(identifier)", Elements::Label, identifier, 'label')
823
- end
824
-
825
- #
826
- # platform method to set the file on a file_field element
827
- # See PageObject::Accessors#file_field
828
- #
829
- def file_field_value_set(identifier, value)
830
- process_watir_call("file_field(identifier).set(value)", Elements::FileField,
831
- identifier, value)
832
- end
833
-
834
- #
835
- # platform method to retrieve a file_field element
836
- # See PageObject::Accessors#file_field
837
- #
838
- def file_field_for(identifier)
839
- find_watir_element("file_field(identifier)", Elements::FileField, identifier)
840
- end
841
-
842
- #
843
- # platform method to retrieve an array of file field elements
844
- #
845
- def file_fields_for(identifier)
846
- find_watir_elements("file_fields(identifier)", Elements::FileField, identifier)
847
- end
848
-
849
- #
850
- # platform method to click on an area
851
- #
852
- def click_area_for(identifier)
853
- process_watir_call("area(identifier).click", Elements::Area, identifier, nil, 'area')
854
- end
855
-
856
- #
857
- # platform method to retrieve an area element
858
- #
859
- def area_for(identifier)
860
- find_watir_element("area(identifier)", Elements::Area, identifier, 'area')
861
- end
862
-
863
- #
864
- # platform method to retrieve an array of area elements
865
- #
866
- def areas_for(identifier)
867
- find_watir_elements("areas(identifier)", Elements::Area, identifier, 'area')
868
- end
869
-
870
- #
871
- # platform method to retrieve a canvas element
872
- #
873
- def canvas_for(identifier)
874
- find_watir_element("canvas(identifier)", Elements::Canvas, identifier, 'canvas')
875
- end
876
-
877
- #
878
- # platform method to retrieve an array of canvas elements
879
- #
880
- def canvass_for(identifier)
881
- find_watir_elements("canvases(identifier)", Elements::Canvas, identifier, 'canvas')
882
- end
883
-
884
- #
885
- # platform method to retrieve an audio element
886
- #
887
- def audio_for(identifier)
888
- find_watir_element("audio(identifier)", Elements::Audio, identifier, 'audio')
889
- end
890
-
891
- #
892
- # platform method to retrieve an array of audio elements
893
- #
894
- def audios_for(identifier)
895
- find_watir_elements("audios(identifier)", Elements::Audio, identifier, 'audio')
896
- end
897
-
898
- #
899
- # platform method to retrieve a video element
900
- #
901
- def video_for(identifier)
902
- find_watir_element("video(identifier)", Elements::Video, identifier, 'video')
903
- end
904
-
905
- #
906
- # platform method to retrieve an array of video elements
907
- #
908
- def videos_for(identifier)
909
- find_watir_elements("videos(identifier)", Elements::Video, identifier, 'video')
910
- end
911
-
912
- #
913
- # platform method to return a PageObject::Elements::Element element
914
- # See PageObject::Accessors#element
915
- #
916
- def element_for(tag, identifier)
917
- find_watir_element("#{tag.to_s}(identifier)", Elements::Element, identifier, tag.to_s)
918
- end
919
-
920
- #
921
- # platform method to return an array of PageObject::Elements::Element elements
922
- # See PageObject::Accessors#element
923
- #
924
- def elements_for(tag, identifier)
925
- find_watir_elements("#{tag.to_s}s(identifier)", Elements::Element, identifier, tag.to_s)
926
- end
927
-
928
- #
929
- # platform method to return a svg element
930
- #
931
- def svg_for(identifier)
932
- find_watir_element("element(identifier)", Elements::Element, identifier)
933
- end
934
-
935
- #
936
- # platform method to return an array of svg elements
937
- #
938
- def svgs_for(identifier)
939
- find_watir_elements("element(identifier)", Elements::Element, identifier)
940
- end
941
-
942
- private
943
-
944
- def find_watir_elements(the_call, type, identifier, tag_name=nil)
945
- identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
946
- elements = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
947
- switch_to_default_content(frame_identifiers)
948
- elements.map { |element| type.new(element, :platform => :watir_webdriver) }
949
- end
950
-
951
- def find_watir_element(the_call, type, identifier, tag_name=nil)
952
- identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
953
- element = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
954
- switch_to_default_content(frame_identifiers)
955
- type.new(element, :platform => :watir_webdriver)
956
- end
957
-
958
- def process_watir_call(the_call, type, identifier, value=nil, tag_name=nil)
959
- identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
960
- value = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
961
- switch_to_default_content(frame_identifiers)
962
- value
963
- end
964
-
965
- def parse_identifiers(identifier, element, tag_name=nil)
966
- frame_identifiers = identifier.delete(:frame)
967
- identifier = add_tagname_if_needed identifier, tag_name if tag_name
968
- identifier = element.watir_identifier_for identifier
969
- return identifier, frame_identifiers
970
- end
971
-
972
- def add_tagname_if_needed identifier, tag
973
- return identifier if identifier.length < 2 and not identifier[:name]
974
- identifier[:tag_name] = tag if identifier[:name]
975
- identifier
976
- end
977
-
978
- def nested_frames(frame_identifiers)
979
- return if frame_identifiers.nil?
980
- frame_str = ''
981
- frame_identifiers.each do |frame|
982
- type = frame.keys.first
983
- identifier = frame.values.first.map do |key, value|
984
- if value.is_a?(Regexp)
985
- ":#{key} => #{value.inspect}"
986
- elsif value.to_s.is_integer
987
- ":#{key} => #{value}"
988
- else
989
- ":#{key} => '#{value}'"
990
- end
991
- end.join(', ')
992
- frame_str += "#{type.to_s}(#{identifier})."
993
- end
994
- frame_str
995
- end
996
-
997
- def switch_to_default_content(frame_identifiers)
998
- @browser.wd.switch_to.default_content unless frame_identifiers.nil?
999
- end
1000
-
1001
- def css_element
1002
- "element(identifier)"
1003
- end
1004
-
1005
- def css_elements
1006
- "elements(identifier)"
1007
- end
1008
-
1009
- def call_for_watir_element(identifier, call)
1010
- identifier[:css] ? "#{css_element}" : call
1011
- end
1012
-
1013
- def call_for_watir_elements(identifier, call)
1014
- identifier[:css] ? "#{css_elements}" : call
1015
- end
1016
-
1017
- def switch_to_frame(frame_identifiers)
1018
- unless frame_identifiers.nil?
1019
- frame_identifiers.each do |frame|
1020
- frame_id = frame.values.first
1021
- value = frame_id.values.first
1022
- @browser.wd.switch_to.frame(value)
1023
- end
1024
- end
1025
- end
1026
- end
1027
- end
1028
- end
1029
- end
1
+ require 'watir-webdriver/extensions/alerts'
2
+ require 'page-object/elements'
3
+ require 'page-object/core_ext/string'
4
+
5
+
6
+ module PageObject
7
+ module Platforms
8
+ module WatirWebDriver
9
+ #
10
+ # Watir implementation of the page object platform driver. You should not use the
11
+ # class directly. Instead you should include the PageObject module in your page object
12
+ # and use the methods dynamically added from the PageObject::Accessors module.
13
+ #
14
+ class PageObject
15
+ attr_reader :browser
16
+
17
+ def initialize(browser)
18
+ @browser = browser
19
+ end
20
+
21
+ #
22
+ # platform method to navigate to a provided url
23
+ # See PageObject#navigate_to
24
+ #
25
+ def navigate_to(url)
26
+ @browser.goto url
27
+ end
28
+
29
+ #
30
+ # platform method to get the current url
31
+ # See PageObject#current_url
32
+ #
33
+ def current_url
34
+ @browser.url
35
+ end
36
+
37
+ #
38
+ # platform method to retrieve the text from the current page
39
+ # See PageObject#text
40
+ #
41
+ def text
42
+ @browser.text
43
+ end
44
+
45
+ #
46
+ # platform method to retrieve the html for the current page
47
+ # See PageObject#html
48
+ #
49
+ def html
50
+ @browser.html
51
+ end
52
+
53
+ #
54
+ # platform method to retrieve the title for the current page
55
+ # See PageObject#title
56
+ #
57
+ def title
58
+ @browser.title
59
+ end
60
+
61
+ #
62
+ # platform method to wait for a block to return true
63
+ # See PageObject#wait_until
64
+ def wait_until(timeout, message = nil, &block)
65
+ @browser.wait_until(timeout, message, &block)
66
+ end
67
+
68
+ #
69
+ # platform method to handle an alert popup
70
+ # See PageObject#alert
71
+ #
72
+ def alert(frame=nil, &block)
73
+ switch_to_frame(frame)
74
+ yield
75
+ value = nil
76
+ if @browser.alert.exists?
77
+ value = @browser.alert.text
78
+ @browser.alert.ok
79
+ end
80
+ switch_to_default_content(frame)
81
+ value
82
+ end
83
+
84
+ #
85
+ # platform method to handle a confirm popup
86
+ # See PageObject#confirm
87
+ #
88
+ def confirm(response, frame=nil, &block)
89
+ switch_to_frame(frame)
90
+ yield
91
+ value = nil
92
+ if @browser.alert.exists?
93
+ value = @browser.alert.text
94
+ response ? @browser.alert.ok : @browser.alert.close
95
+ end
96
+ switch_to_default_content(frame)
97
+ value
98
+ end
99
+
100
+ #
101
+ # platform method to handle a prompt popup
102
+ # See PageObject#prompt
103
+ #
104
+ def prompt(answer, frame=nil, &block)
105
+ switch_to_frame(frame)
106
+ @browser.wd.execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer}; }"
107
+ yield
108
+ result = @browser.wd.execute_script "return window.__lastWatirPrompt"
109
+ switch_to_default_content(frame)
110
+ result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
111
+ result
112
+ end
113
+
114
+ #
115
+ # platform method to execute javascript on the browser
116
+ # See PageObject#execute_script
117
+ #
118
+ def execute_script(script, *args)
119
+ @browser.execute_script(script, *args)
120
+ end
121
+
122
+ #
123
+ # platform method to handle attaching to a running window
124
+ # See PageObject#attach_to_window
125
+ #
126
+ def attach_to_window(identifier, &block)
127
+ win_id = {identifier.keys.first => /#{Regexp.escape(identifier.values.first)}/}
128
+ @browser.window(win_id).use &block
129
+ end
130
+
131
+ def element_with_focus
132
+ element = browser.execute_script("return document.activeElement")
133
+ type = element.type.to_sym if element.tag_name.to_sym == :input
134
+ cls = ::PageObject::Elements.element_class_for(element.tag_name, type)
135
+ cls.new(element, :platform => :watir_webdriver)
136
+ end
137
+
138
+ #
139
+ # platform method to switch to a frame and execute a block
140
+ # See PageObject#in_frame
141
+ #
142
+ def in_frame(identifier, frame=nil, &block)
143
+ frame = [] if frame.nil?
144
+ frame << {frame: identifier}
145
+ block.call(frame)
146
+ end
147
+
148
+ #
149
+ # platform method to switch to an iframe and execute a block
150
+ # See PageObject#in_frame
151
+ #
152
+ def in_iframe(identifier, frame=nil, &block)
153
+ frame = [] if frame.nil?
154
+ frame << {iframe: identifier}
155
+ block.call(frame)
156
+ end
157
+
158
+ #
159
+ # platform method to refresh the page
160
+ # See PageObject#refresh
161
+ #
162
+ def refresh
163
+ @browser.refresh
164
+ end
165
+
166
+ #
167
+ # platform method to go back to the previous page
168
+ # See PageObject#back
169
+ #
170
+ def back
171
+ @browser.back
172
+ end
173
+
174
+ #
175
+ # platform method to go forward to the next page
176
+ # See PageObject#forward
177
+ #
178
+ def forward
179
+ @browser.forward
180
+ end
181
+
182
+ #
183
+ # platform method to clear the cookies from the browser
184
+ # See PageObject#clear_cookies
185
+ #
186
+ def clear_cookies
187
+ @browser.cookies.clear
188
+ end
189
+
190
+ #
191
+ # platform method to save the current screenshot to a file
192
+ # See PageObject#save_screenshot
193
+ #
194
+ def save_screenshot(file_name)
195
+ @browser.wd.save_screenshot(file_name)
196
+ end
197
+
198
+ #
199
+ # platform method to get the value stored in a text field
200
+ # See PageObject::Accessors#text_field
201
+ #
202
+ def text_field_value_for(identifier)
203
+ process_watir_call("text_field(identifier).value", Elements::TextField, identifier)
204
+ end
205
+
206
+ #
207
+ # platform method to set the value for a text field
208
+ # See PageObject::Accessors#text_field
209
+ #
210
+ def text_field_value_set(identifier, value)
211
+ process_watir_call("text_field(identifier).set(value)", Elements::TextField, identifier, value)
212
+ end
213
+
214
+ #
215
+ # platform method to retrieve a text field element
216
+ # See PageObject::Accessors#text_field
217
+ #
218
+ def text_field_for(identifier)
219
+ find_watir_element("text_field(identifier)", Elements::TextField, identifier)
220
+ end
221
+
222
+ #
223
+ # platform method to retrieve an array of text field elements
224
+ #
225
+ def text_fields_for(identifier)
226
+ elements = find_watir_elements("text_fields(identifier)", Elements::TextField, identifier)
227
+ elements.select {|e| e.element.tag_name == 'input'}
228
+ end
229
+
230
+ #
231
+ # platform method to get the value stored in a hidden field
232
+ # See PageObject::Accessors#hidden_field
233
+ #
234
+ def hidden_field_value_for(identifier)
235
+ process_watir_call("hidden(identifier).value", Elements::HiddenField, identifier)
236
+ end
237
+
238
+ #
239
+ # platform method to retrieve a hidden field element
240
+ # See PageObject::Accessors#hidden_field
241
+ #
242
+ def hidden_field_for(identifier)
243
+ find_watir_element("hidden(identifier)", Elements::HiddenField, identifier)
244
+ end
245
+
246
+ #
247
+ # platform method to retrieve an array of hidden field elements
248
+ #
249
+ def hidden_fields_for(identifier)
250
+ find_watir_elements("hiddens(identifier)", Elements::HiddenField, identifier)
251
+ end
252
+
253
+ #
254
+ # platform method to set text in a textarea
255
+ # See PageObject::Accessors#text_area
256
+ #
257
+ def text_area_value_set(identifier, value)
258
+ process_watir_call("textarea(identifier).set(value)", Elements::TextArea,
259
+ identifier, value)
260
+ end
261
+
262
+ #
263
+ # platform method to get the text from a textarea
264
+ # See PageObject::Accessors#text_area
265
+ #
266
+ def text_area_value_for(identifier)
267
+ process_watir_call("textarea(identifier).value", Elements::TextArea, identifier)
268
+ end
269
+
270
+ #
271
+ # platform method to get the text area element
272
+ # See PageObject::Accessors#text_area
273
+ #
274
+ def text_area_for(identifier)
275
+ find_watir_element("textarea(identifier)", Elements::TextArea, identifier)
276
+ end
277
+
278
+ #
279
+ # platform method to retrieve an array of textarea elements
280
+ #
281
+ def text_areas_for(identifier)
282
+ find_watir_elements("textareas(identifier)", Elements::TextArea, identifier)
283
+ end
284
+
285
+ #
286
+ # platform method to get the currently selected value from a select list
287
+ # See PageObject::Accessors#select_list
288
+ #
289
+ def select_list_value_for(identifier)
290
+ process_watir_call("select_list(identifier).options.find {|o| o.selected?}.text",
291
+ Elements::SelectList, identifier)
292
+ end
293
+
294
+ #
295
+ # platform method to select a value from a select list
296
+ # See PageObject::Accessors#select_list
297
+ #
298
+ def select_list_value_set(identifier, value)
299
+ process_watir_call("select_list(identifier).select(value)", Elements::SelectList,
300
+ identifier, value)
301
+ end
302
+
303
+ #
304
+ # platform method to return the select list element
305
+ # See PageObject::Accessors#select_list
306
+ #
307
+ def select_list_for(identifier)
308
+ find_watir_element("select_list(identifier)", Elements::SelectList, identifier)
309
+ end
310
+
311
+ #
312
+ # platform method to retrieve an array of select_list elements
313
+ #
314
+ def select_lists_for(identifier)
315
+ find_watir_elements("select_lists(identifier)", Elements::SelectList, identifier)
316
+ end
317
+
318
+ #
319
+ # platform method to click a link
320
+ # See PageObject::Accessors#link
321
+ #
322
+ def click_link_for(identifier)
323
+ call = call_for_watir_element(identifier, "link(identifier)")
324
+ process_watir_call("#{call}.click if identifier", Elements::Link, identifier)
325
+ end
326
+
327
+ #
328
+ # platform method to return a PageObject::Elements::Link object
329
+ # see PageObject::Accessors#link
330
+ #
331
+ def link_for(identifier)
332
+ call = call_for_watir_element(identifier, "link(identifier)")
333
+ find_watir_element(call, Elements::Link, identifier)
334
+ end
335
+
336
+ #
337
+ # platform method to retrieve an array of link elements
338
+ #
339
+ def links_for(identifier)
340
+ call = call_for_watir_elements(identifier, "links(identifier)")
341
+ find_watir_elements(call, Elements::Link, identifier)
342
+ end
343
+
344
+ #
345
+ # platform method to check a checkbox
346
+ # See PageObject::Accessors#checkbox
347
+ #
348
+ def check_checkbox(identifier)
349
+ process_watir_call("checkbox(identifier).set", Elements::CheckBox, identifier)
350
+ end
351
+
352
+ #
353
+ # platform method to uncheck a checkbox
354
+ # See PageObject::Accessors#checkbox
355
+ #
356
+ def uncheck_checkbox(identifier)
357
+ process_watir_call("checkbox(identifier).clear", Elements::CheckBox, identifier)
358
+ end
359
+
360
+ #
361
+ # platform method to determine if a checkbox is checked
362
+ # See PageObject::Accessors#checkbox
363
+ #
364
+ def checkbox_checked?(identifier)
365
+ process_watir_call("checkbox(identifier).set?", Elements::CheckBox, identifier)
366
+ end
367
+
368
+ #
369
+ # platform method to return a PageObject::Elements::CheckBox element
370
+ # See PageObject::Accessors#checkbox
371
+ #
372
+ def checkbox_for(identifier)
373
+ find_watir_element("checkbox(identifier)", Elements::CheckBox, identifier)
374
+ end
375
+
376
+ #
377
+ # platform method to retrieve an array of checkbox elements
378
+ #
379
+ def checkboxs_for(identifier)
380
+ find_watir_elements("checkboxes(identifier)", Elements::CheckBox, identifier)
381
+ end
382
+
383
+ #
384
+ # platform method to select a radio button
385
+ # See PageObject::Accessors#radio_button
386
+ #
387
+ def select_radio(identifier)
388
+ process_watir_call("radio(identifier).set", Elements::RadioButton, identifier)
389
+ end
390
+
391
+ #
392
+ # platform method to determine if a radio button is selected
393
+ # See PageObject::Accessors#radio_button
394
+ #
395
+ def radio_selected?(identifier)
396
+ process_watir_call("radio(identifier).set?", Elements::RadioButton, identifier)
397
+ end
398
+
399
+ #
400
+ # platform method to return a PageObject::Eements::RadioButton element
401
+ # See PageObject::Accessors#radio_button
402
+ #
403
+ def radio_button_for(identifier)
404
+ find_watir_element("radio(identifier)", Elements::RadioButton, identifier)
405
+ end
406
+
407
+ #
408
+ # platform method to retrieve an array of radio button elements
409
+ #
410
+ def radio_buttons_for(identifier)
411
+ find_watir_elements("radios(identifier)", Elements::RadioButton, identifier)
412
+ end
413
+
414
+ #
415
+ # platform method to return the text for a div
416
+ # See PageObject::Accessors#div
417
+ #
418
+ def div_text_for(identifier)
419
+ process_watir_call("div(identifier).text", Elements::Div, identifier, nil, 'div')
420
+ end
421
+
422
+ #
423
+ # platform method to return a PageObject::Elements::Div element
424
+ # See PageObject::Accessors#div
425
+ #
426
+ def div_for(identifier)
427
+ find_watir_element("div(identifier)", Elements::Div, identifier, 'div')
428
+ end
429
+
430
+ #
431
+ # platform method to retrieve an array of div elements
432
+ #
433
+ def divs_for(identifier)
434
+ find_watir_elements("divs(identifier)", Elements::Div, identifier, 'div')
435
+ end
436
+
437
+ #
438
+ # platform method to return the text for a span
439
+ # See PageObject::Accessors#span
440
+ #
441
+ def span_text_for(identifier)
442
+ process_watir_call("span(identifier).text", Elements::Span, identifier, nil, 'span')
443
+ end
444
+
445
+ #
446
+ # platform method to return a PageObject::Elements::Span element
447
+ # See PageObject::Accessors#span
448
+ #
449
+ def span_for(identifier)
450
+ find_watir_element("span(identifier)", Elements::Span, identifier, 'span')
451
+ end
452
+
453
+ #
454
+ # platform method to retrieve an array of span elements
455
+ #
456
+ def spans_for(identifier)
457
+ find_watir_elements("spans(identifier)", Elements::Span, identifier, 'span')
458
+ end
459
+
460
+ #
461
+ # platform method to click a button
462
+ # See PageObject::Accessors#button
463
+ #
464
+ def click_button_for(identifier)
465
+ call = call_for_watir_element(identifier, "button(identifier)")
466
+ process_watir_call("#{call}.click", Elements::Button, identifier)
467
+ end
468
+
469
+ #
470
+ # platform method to retrieve a button element
471
+ # See PageObject::Accessors#button
472
+ #
473
+ def button_for(identifier)
474
+ call = call_for_watir_element(identifier, "button(identifier)")
475
+ find_watir_element(call, Elements::Button, identifier)
476
+ end
477
+
478
+ #
479
+ # platform method to retrieve an array of button elements
480
+ #
481
+ def buttons_for(identifier)
482
+ call = call_for_watir_elements(identifier, "buttons(identifier)")
483
+ find_watir_elements(call, Elements::Button, identifier)
484
+ end
485
+
486
+ #
487
+ # platform method to return the text for a table
488
+ # See PageObject::Accessors#table
489
+ #
490
+ def table_text_for(identifier)
491
+ process_watir_call("table(identifier).text", Elements::Table, identifier, nil, 'table')
492
+ end
493
+
494
+ #
495
+ # platform method to retrieve a table element
496
+ # See PageObject::Accessors#table
497
+ #
498
+ def table_for(identifier)
499
+ find_watir_element("table(identifier)", Elements::Table, identifier, 'table')
500
+ end
501
+
502
+ #
503
+ # platform method to retrieve an array of table elements
504
+ #
505
+ def tables_for(identifier)
506
+ find_watir_elements("tables(identifier)", Elements::Table, identifier, 'table')
507
+ end
508
+
509
+ #
510
+ # platform method to retrieve the text from a table cell
511
+ # See PageObject::Accessors#cell
512
+ #
513
+ def cell_text_for(identifier)
514
+ process_watir_call("td(identifier).text", Elements::TableCell, identifier,
515
+ nil, 'td')
516
+ end
517
+
518
+ #
519
+ # platform method to retrieve a table cell element
520
+ # See PageObject::Accessors#cell
521
+ #
522
+ def cell_for(identifier)
523
+ find_watir_element("td(identifier)", Elements::TableCell, identifier, 'td')
524
+ end
525
+
526
+ #
527
+ # platform method to retrieve an array of table cell elements
528
+ #
529
+ def cells_for(identifier)
530
+ find_watir_elements("tds(identifier)", Elements::TableCell, identifier, 'td')
531
+ end
532
+
533
+ #
534
+ # platform method to retrieve an image element
535
+ # See PageObject::Accessors#image
536
+ #
537
+ def image_for(identifier)
538
+ find_watir_element("image(identifier)", Elements::Image, identifier)
539
+ end
540
+
541
+ #
542
+ # platform method to retrieve an array of image elements
543
+ #
544
+ def images_for(identifier)
545
+ find_watir_elements("images(identifier)", Elements::Image, identifier)
546
+ end
547
+
548
+ #
549
+ # platform method to retrieve a form element
550
+ # See PageObject::Accessors#form
551
+ #
552
+ def form_for(identifier)
553
+ find_watir_element("form(identifier)", Elements::Form, identifier)
554
+ end
555
+
556
+ #
557
+ # platform method to retrieve an array of forms
558
+ #
559
+ def forms_for(identifier)
560
+ find_watir_elements("forms(identifier)", Elements::Form, identifier)
561
+ end
562
+
563
+ #
564
+ # platform method to retrieve the text from a list item
565
+ # See PageObject::Accessors#list_item
566
+ #
567
+ def list_item_text_for(identifier)
568
+ process_watir_call("li(identifier).text", Elements::ListItem, identifier, nil, 'li')
569
+ end
570
+
571
+ #
572
+ # platform method to retrieve a list item element
573
+ # See PageObject::Accessors#list_item
574
+ #
575
+ def list_item_for(identifier)
576
+ find_watir_element("li(identifier)", Elements::ListItem, identifier, 'li')
577
+ end
578
+
579
+ #
580
+ # platform method to retrieve an array of list items
581
+ #
582
+ def list_items_for(identifier)
583
+ find_watir_elements("lis(identifier)", Elements::ListItem, identifier, 'li')
584
+ end
585
+
586
+ #
587
+ # platform method to retrieve the text from an unordered list
588
+ # See PageObject::Accessors#unordered_list
589
+ #
590
+ def unordered_list_text_for(identifier)
591
+ process_watir_call("ul(identifier).text", Elements::UnorderedList, identifier, nil, 'ul')
592
+ end
593
+
594
+ #
595
+ # platform method to retrieve an unordered list element
596
+ # See PageObject::Accessors#unordered_list
597
+ #
598
+ def unordered_list_for(identifier)
599
+ find_watir_element("ul(identifier)", Elements::UnorderedList, identifier, 'ul')
600
+ end
601
+
602
+ #
603
+ # platform method to retrieve an array of unordered lists
604
+ #
605
+ def unordered_lists_for(identifier)
606
+ find_watir_elements("uls(identifier)", Elements::UnorderedList, identifier, 'ul')
607
+ end
608
+
609
+ #
610
+ # platform method to retrieve the text from an ordered list
611
+ # See PageObject::Accessors#ordered_list
612
+ #
613
+ def ordered_list_text_for(identifier)
614
+ process_watir_call("ol(identifier).text", Elements::OrderedList, identifier, nil, 'ol')
615
+ end
616
+
617
+ #
618
+ # platform method to retrieve an ordered list element
619
+ # See PageObject::Accessors#ordered_list
620
+ #
621
+ def ordered_list_for(identifier)
622
+ find_watir_element("ol(identifier)", Elements::OrderedList, identifier, 'ol')
623
+ end
624
+
625
+ #
626
+ # platform method to retrieve an array of ordered lists
627
+ #
628
+ def ordered_lists_for(identifier)
629
+ find_watir_elements("ols(identifier)", Elements::OrderedList, identifier, 'ol')
630
+ end
631
+
632
+ #
633
+ # platform method to retrieve the text for a h1
634
+ # See PageObject::Accessors#h1
635
+ #
636
+ def h1_text_for(identifier)
637
+ process_watir_call("h1(identifier).text", Elements::Heading, identifier, nil, 'h1')
638
+ end
639
+
640
+ #
641
+ # platform method to retrieve the h1 element
642
+ # See PageObject::Accessors#h1
643
+ #
644
+ def h1_for(identifier)
645
+ find_watir_element("h1(identifier)", Elements::Heading, identifier, 'h1')
646
+ end
647
+
648
+ #
649
+ # platform method to retrieve an array of h1s
650
+ #
651
+ def h1s_for(identifier)
652
+ find_watir_elements("h1s(identifier)", Elements::Heading, identifier, 'h1')
653
+ end
654
+
655
+ #
656
+ # platform method to retrieve the text for a h2
657
+ # See PageObject::Accessors#h2
658
+ #
659
+ def h2_text_for(identifier)
660
+ process_watir_call("h2(identifier).text", Elements::Heading, identifier, nil, 'h2')
661
+ end
662
+
663
+ #
664
+ # platform method to retrieve the h2 element
665
+ # See PageObject::Accessors#h2
666
+ #
667
+ def h2_for(identifier)
668
+ find_watir_element("h2(identifier)", Elements::Heading, identifier, 'h2')
669
+ end
670
+
671
+ #
672
+ # platform method to retrieve an array of h2s
673
+ #
674
+ def h2s_for(identifier)
675
+ find_watir_elements("h2s(identifier)", Elements::Heading, identifier, 'h2')
676
+ end
677
+
678
+ #
679
+ # platform method to retrieve the text for a h3
680
+ # See PageObject::Accessors#h3
681
+ #
682
+ def h3_text_for(identifier)
683
+ process_watir_call("h3(identifier).text", Elements::Heading, identifier, nil, 'h3')
684
+ end
685
+
686
+ #
687
+ # platform method to retrieve the h3 element
688
+ # See PageObject::Accessors#h3
689
+ #
690
+ def h3_for(identifier)
691
+ find_watir_element("h3(identifier)", Elements::Heading, identifier, 'h3')
692
+ end
693
+
694
+ #
695
+ # platform method to retrieve an array of h3s
696
+ #
697
+ def h3s_for(identifier)
698
+ find_watir_elements("h3s(identifier)", Elements::Heading, identifier, 'h3')
699
+ end
700
+
701
+ #
702
+ # platform method to retrieve the text for a h4
703
+ # See PageObject::Accessors#h4
704
+ #
705
+ def h4_text_for(identifier)
706
+ process_watir_call("h4(identifier).text", Elements::Heading, identifier, nil, 'h4')
707
+ end
708
+
709
+ #
710
+ # platform method to retrieve the h4 element
711
+ # See PageObject::Accessors#h4
712
+ #
713
+ def h4_for(identifier)
714
+ find_watir_element("h4(identifier)", Elements::Heading, identifier, 'h4')
715
+ end
716
+
717
+ #
718
+ # platform method to retrieve an array of h4s
719
+ #
720
+ def h4s_for(identifier)
721
+ find_watir_elements("h4s(identifier)", Elements::Heading, identifier, 'h4')
722
+ end
723
+
724
+ #
725
+ # platform method to retrieve the text for a h5
726
+ # See PageObject::Accessors#h5
727
+ #
728
+ def h5_text_for(identifier)
729
+ process_watir_call("h5(identifier).text", Elements::Heading, identifier, nil, 'h5')
730
+ end
731
+
732
+ #
733
+ # platform method to retrieve the h5 element
734
+ # See PageObject::Accessors#h5
735
+ #
736
+ def h5_for(identifier)
737
+ find_watir_element("h5(identifier)", Elements::Heading, identifier, 'h5')
738
+ end
739
+
740
+ #
741
+ # platform method to retrieve an array of h5s
742
+ #
743
+ def h5s_for(identifier)
744
+ find_watir_elements("h5s(identifier)", Elements::Heading, identifier, 'h5')
745
+ end
746
+
747
+ #
748
+ # platform method to retrieve the text for a h6
749
+ # See PageObject::Accessors#h6
750
+ #
751
+ def h6_text_for(identifier)
752
+ process_watir_call("h6(identifier).text", Elements::Heading, identifier, nil, 'h6')
753
+ end
754
+
755
+ #
756
+ # platform method to retrieve the h6 element
757
+ # See PageObject::Accessors#h6
758
+ #
759
+ def h6_for(identifier)
760
+ find_watir_element("h6(identifier)", Elements::Heading, identifier, 'h6')
761
+ end
762
+
763
+ #
764
+ # platform method to retrieve an array of h6s
765
+ #
766
+ def h6s_for(identifier)
767
+ find_watir_elements("h6s(identifier)", Elements::Heading, identifier, 'h6')
768
+ end
769
+
770
+ #
771
+ # platform method to retrieve the text for a paragraph
772
+ # See PageObject::Accessors#paragraph
773
+ #
774
+ def paragraph_text_for(identifier)
775
+ process_watir_call("p(identifier).text", Elements::Paragraph, identifier, nil, 'p')
776
+ end
777
+
778
+ #
779
+ # platform method to retrieve the paragraph element
780
+ # See PageObject::Accessors#paragraph
781
+ #
782
+ def paragraph_for(identifier)
783
+ find_watir_element("p(identifier)", Elements::Paragraph, identifier, 'p')
784
+ end
785
+
786
+ #
787
+ # platform method to retrieve an array of paragraph elements
788
+ #
789
+ def paragraphs_for(identifier)
790
+ find_watir_elements("ps(identifier)", Elements::Paragraph, identifier, 'p')
791
+ end
792
+
793
+ #
794
+ # platform method to return the text for a label
795
+ # See PageObject::Accessors#label
796
+ #
797
+ def label_text_for(identifier)
798
+ process_watir_call("label(identifier).text", Elements::Label, identifier, nil, 'label')
799
+ end
800
+
801
+ #
802
+ # platform method to return a PageObject::Elements::Label element
803
+ # See PageObject::Accessors#label
804
+ #
805
+ def label_for(identifier)
806
+ find_watir_element("label(identifier)", Elements::Label, identifier, 'label')
807
+ end
808
+
809
+ #
810
+ # platform method to return a PageObject::Element::Label element
811
+ # See PageObject::Accessors#label
812
+ #
813
+ def choose_label(identifier)
814
+ process_watir_call("label(identifier).click", Elements::Label, identifier, 'label')
815
+ end
816
+
817
+ #
818
+ #
819
+ # platform method to retrieve an array of label elements
820
+ #
821
+ def labels_for(identifier)
822
+ find_watir_elements("labels(identifier)", Elements::Label, identifier, 'label')
823
+ end
824
+
825
+ #
826
+ # platform method to set the file on a file_field element
827
+ # See PageObject::Accessors#file_field
828
+ #
829
+ def file_field_value_set(identifier, value)
830
+ process_watir_call("file_field(identifier).set(value)", Elements::FileField,
831
+ identifier, value)
832
+ end
833
+
834
+ #
835
+ # platform method to retrieve a file_field element
836
+ # See PageObject::Accessors#file_field
837
+ #
838
+ def file_field_for(identifier)
839
+ find_watir_element("file_field(identifier)", Elements::FileField, identifier)
840
+ end
841
+
842
+ #
843
+ # platform method to retrieve an array of file field elements
844
+ #
845
+ def file_fields_for(identifier)
846
+ find_watir_elements("file_fields(identifier)", Elements::FileField, identifier)
847
+ end
848
+
849
+ #
850
+ # platform method to click on an area
851
+ #
852
+ def click_area_for(identifier)
853
+ process_watir_call("area(identifier).click", Elements::Area, identifier, nil, 'area')
854
+ end
855
+
856
+ #
857
+ # platform method to retrieve an area element
858
+ #
859
+ def area_for(identifier)
860
+ find_watir_element("area(identifier)", Elements::Area, identifier, 'area')
861
+ end
862
+
863
+ #
864
+ # platform method to retrieve an array of area elements
865
+ #
866
+ def areas_for(identifier)
867
+ find_watir_elements("areas(identifier)", Elements::Area, identifier, 'area')
868
+ end
869
+
870
+ #
871
+ # platform method to retrieve a canvas element
872
+ #
873
+ def canvas_for(identifier)
874
+ find_watir_element("canvas(identifier)", Elements::Canvas, identifier, 'canvas')
875
+ end
876
+
877
+ #
878
+ # platform method to retrieve an array of canvas elements
879
+ #
880
+ def canvass_for(identifier)
881
+ find_watir_elements("canvases(identifier)", Elements::Canvas, identifier, 'canvas')
882
+ end
883
+
884
+ #
885
+ # platform method to retrieve an audio element
886
+ #
887
+ def audio_for(identifier)
888
+ find_watir_element("audio(identifier)", Elements::Audio, identifier, 'audio')
889
+ end
890
+
891
+ #
892
+ # platform method to retrieve an array of audio elements
893
+ #
894
+ def audios_for(identifier)
895
+ find_watir_elements("audios(identifier)", Elements::Audio, identifier, 'audio')
896
+ end
897
+
898
+ #
899
+ # platform method to retrieve a video element
900
+ #
901
+ def video_for(identifier)
902
+ find_watir_element("video(identifier)", Elements::Video, identifier, 'video')
903
+ end
904
+
905
+ #
906
+ # platform method to retrieve an array of video elements
907
+ #
908
+ def videos_for(identifier)
909
+ find_watir_elements("videos(identifier)", Elements::Video, identifier, 'video')
910
+ end
911
+
912
+ #
913
+ # platform method to return a PageObject::Elements::Element element
914
+ # See PageObject::Accessors#element
915
+ #
916
+ def element_for(tag, identifier)
917
+ find_watir_element("#{tag.to_s}(identifier)", Elements::Element, identifier, tag.to_s)
918
+ end
919
+
920
+ #
921
+ # platform method to return an array of PageObject::Elements::Element elements
922
+ # See PageObject::Accessors#element
923
+ #
924
+ def elements_for(tag, identifier)
925
+ find_watir_elements("#{tag.to_s}s(identifier)", Elements::Element, identifier, tag.to_s)
926
+ end
927
+
928
+ #
929
+ # platform method to return a svg element
930
+ #
931
+ def svg_for(identifier)
932
+ find_watir_element("element(identifier)", Elements::Element, identifier)
933
+ end
934
+
935
+ #
936
+ # platform method to return an array of svg elements
937
+ #
938
+ def svgs_for(identifier)
939
+ find_watir_elements("element(identifier)", Elements::Element, identifier)
940
+ end
941
+
942
+ private
943
+
944
+ def find_watir_elements(the_call, type, identifier, tag_name=nil)
945
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
946
+ elements = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
947
+ switch_to_default_content(frame_identifiers)
948
+ elements.map { |element| type.new(element, :platform => :watir_webdriver) }
949
+ end
950
+
951
+ def find_watir_element(the_call, type, identifier, tag_name=nil)
952
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
953
+ element = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
954
+ switch_to_default_content(frame_identifiers)
955
+ type.new(element, :platform => :watir_webdriver)
956
+ end
957
+
958
+ def process_watir_call(the_call, type, identifier, value=nil, tag_name=nil)
959
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
960
+ value = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
961
+ switch_to_default_content(frame_identifiers)
962
+ value
963
+ end
964
+
965
+ def parse_identifiers(identifier, element, tag_name=nil)
966
+ frame_identifiers = identifier.delete(:frame)
967
+ identifier = add_tagname_if_needed identifier, tag_name if tag_name
968
+ identifier = element.watir_identifier_for identifier
969
+ return identifier, frame_identifiers
970
+ end
971
+
972
+ def add_tagname_if_needed identifier, tag
973
+ return identifier if identifier.length < 2 and not identifier[:name]
974
+ identifier[:tag_name] = tag if identifier[:name]
975
+ identifier
976
+ end
977
+
978
+ def nested_frames(frame_identifiers)
979
+ return if frame_identifiers.nil?
980
+ frame_str = ''
981
+ frame_identifiers.each do |frame|
982
+ type = frame.keys.first
983
+ identifier = frame.values.first.map do |key, value|
984
+ if value.is_a?(Regexp)
985
+ ":#{key} => #{value.inspect}"
986
+ elsif value.to_s.is_integer
987
+ ":#{key} => #{value}"
988
+ else
989
+ ":#{key} => '#{value}'"
990
+ end
991
+ end.join(', ')
992
+ frame_str += "#{type.to_s}(#{identifier})."
993
+ end
994
+ frame_str
995
+ end
996
+
997
+ def switch_to_default_content(frame_identifiers)
998
+ @browser.wd.switch_to.default_content unless frame_identifiers.nil?
999
+ end
1000
+
1001
+ def css_element
1002
+ "element(identifier)"
1003
+ end
1004
+
1005
+ def css_elements
1006
+ "elements(identifier)"
1007
+ end
1008
+
1009
+ def call_for_watir_element(identifier, call)
1010
+ identifier[:css] ? "#{css_element}" : call
1011
+ end
1012
+
1013
+ def call_for_watir_elements(identifier, call)
1014
+ identifier[:css] ? "#{css_elements}" : call
1015
+ end
1016
+
1017
+ def switch_to_frame(frame_identifiers)
1018
+ unless frame_identifiers.nil?
1019
+ frame_identifiers.each do |frame|
1020
+ frame_id = frame.values.first
1021
+ value = frame_id.values.first
1022
+ @browser.wd.switch_to.frame(value)
1023
+ end
1024
+ end
1025
+ end
1026
+ end
1027
+ end
1028
+ end
1029
+ end