page-object-lds 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +10 -0
  7. data/ChangeLog +799 -0
  8. data/Gemfile +13 -0
  9. data/Guardfile +20 -0
  10. data/LICENSE +20 -0
  11. data/README.md +111 -0
  12. data/Rakefile +35 -0
  13. data/cucumber.yml +10 -0
  14. data/features/area.feature +35 -0
  15. data/features/async.feature +30 -0
  16. data/features/audio.feature +68 -0
  17. data/features/bold.feature +21 -0
  18. data/features/button.feature +88 -0
  19. data/features/canvas.feature +37 -0
  20. data/features/check_box.feature +55 -0
  21. data/features/div.feature +45 -0
  22. data/features/element.feature +322 -0
  23. data/features/file_field.feature +40 -0
  24. data/features/form.feature +43 -0
  25. data/features/frames.feature +75 -0
  26. data/features/generic_elements.feature +29 -0
  27. data/features/gxt_table_extension.feature +24 -0
  28. data/features/headings.feature +97 -0
  29. data/features/hidden_field.feature +45 -0
  30. data/features/html/04-Death_Becomes_Fur.mp4 +0 -0
  31. data/features/html/04-Death_Becomes_Fur.oga +0 -0
  32. data/features/html/async.html +36 -0
  33. data/features/html/double_click.html +13 -0
  34. data/features/html/failure.html +8 -0
  35. data/features/html/frame_1.html +18 -0
  36. data/features/html/frame_2.html +16 -0
  37. data/features/html/frame_3.html +14 -0
  38. data/features/html/frames.html +12 -0
  39. data/features/html/hover.html +12 -0
  40. data/features/html/iframes.html +12 -0
  41. data/features/html/images/circle.png +0 -0
  42. data/features/html/images/img_pulpit.jpg +0 -0
  43. data/features/html/images/submit.gif +0 -0
  44. data/features/html/indexed_property.html +52 -0
  45. data/features/html/modal.html +17 -0
  46. data/features/html/modal_1.html +38 -0
  47. data/features/html/modal_2.html +27 -0
  48. data/features/html/movie.mp4 +0 -0
  49. data/features/html/movie.ogg +0 -0
  50. data/features/html/multi_elements.html +144 -0
  51. data/features/html/nested_elements.html +77 -0
  52. data/features/html/nested_frame_1.html +1 -0
  53. data/features/html/nested_frame_2.html +11 -0
  54. data/features/html/nested_frame_3.html +14 -0
  55. data/features/html/nested_frames.html +10 -0
  56. data/features/html/planets.gif +0 -0
  57. data/features/html/static_elements.html +205 -0
  58. data/features/html/success.html +8 -0
  59. data/features/html/sun.gif +0 -0
  60. data/features/html/sun.html +7 -0
  61. data/features/image.feature +50 -0
  62. data/features/indexed_property.feature +98 -0
  63. data/features/javascript.feature +28 -0
  64. data/features/label.feature +46 -0
  65. data/features/link.feature +52 -0
  66. data/features/list_item.feature +36 -0
  67. data/features/modal_dialog.feature +15 -0
  68. data/features/multi_elements.feature +492 -0
  69. data/features/nested_elements.feature +117 -0
  70. data/features/ordered_list.feature +56 -0
  71. data/features/page_level_actions.feature +90 -0
  72. data/features/paragraph.feature +35 -0
  73. data/features/radio_button.feature +58 -0
  74. data/features/radio_button_group.feature +29 -0
  75. data/features/sample-app/public/jquery-1.3.2.js +4376 -0
  76. data/features/sample-app/public/jquery.html +30 -0
  77. data/features/sample-app/public/prototype-1.6.0.3.js +4320 -0
  78. data/features/sample-app/public/prototype.html +35 -0
  79. data/features/sample-app/sample_app.rb +35 -0
  80. data/features/select_list.feature +86 -0
  81. data/features/span.feature +37 -0
  82. data/features/step_definitions/accessor_steps.rb +60 -0
  83. data/features/step_definitions/area_steps.rb +19 -0
  84. data/features/step_definitions/async_steps.rb +83 -0
  85. data/features/step_definitions/audio_steps.rb +27 -0
  86. data/features/step_definitions/bold_steps.rb +12 -0
  87. data/features/step_definitions/button_steps.rb +43 -0
  88. data/features/step_definitions/canvas_steps.rb +15 -0
  89. data/features/step_definitions/check_box_steps.rb +35 -0
  90. data/features/step_definitions/div_steps.rb +19 -0
  91. data/features/step_definitions/element_steps.rb +266 -0
  92. data/features/step_definitions/file_field_steps.rb +19 -0
  93. data/features/step_definitions/form_steps.rb +19 -0
  94. data/features/step_definitions/frames_steps.rb +159 -0
  95. data/features/step_definitions/generic_element_steps.rb +31 -0
  96. data/features/step_definitions/gxt_table_steps.rb +58 -0
  97. data/features/step_definitions/headings_steps.rb +12 -0
  98. data/features/step_definitions/hidden_field_steps.rb +27 -0
  99. data/features/step_definitions/image_steps.rb +27 -0
  100. data/features/step_definitions/indexed_property_steps.rb +129 -0
  101. data/features/step_definitions/javascript_steps.rb +53 -0
  102. data/features/step_definitions/label_steps.rb +19 -0
  103. data/features/step_definitions/link_steps.rb +40 -0
  104. data/features/step_definitions/list_item_steps.rb +19 -0
  105. data/features/step_definitions/modal_dialog_steps.rb +62 -0
  106. data/features/step_definitions/multi_elements_steps.rb +541 -0
  107. data/features/step_definitions/nested_elements_steps.rb +212 -0
  108. data/features/step_definitions/ordered_list_steps.rb +23 -0
  109. data/features/step_definitions/page_level_actions_steps.rb +135 -0
  110. data/features/step_definitions/page_traversal_steps.rb +4 -0
  111. data/features/step_definitions/paragraph_steps.rb +28 -0
  112. data/features/step_definitions/radio_button_group_steps.rb +36 -0
  113. data/features/step_definitions/radio_button_steps.rb +27 -0
  114. data/features/step_definitions/select_list_steps.rb +65 -0
  115. data/features/step_definitions/span_steps.rb +19 -0
  116. data/features/step_definitions/table_cell_steps.rb +15 -0
  117. data/features/step_definitions/table_steps.rb +70 -0
  118. data/features/step_definitions/text_area_steps.rb +35 -0
  119. data/features/step_definitions/text_field_steps.rb +35 -0
  120. data/features/step_definitions/unordered_list_steps.rb +23 -0
  121. data/features/step_definitions/video_steps.rb +45 -0
  122. data/features/support/ajax_text_environment.rb +26 -0
  123. data/features/support/env.rb +8 -0
  124. data/features/support/hooks.rb +8 -0
  125. data/features/support/page.rb +373 -0
  126. data/features/support/persistent_browser.rb +70 -0
  127. data/features/support/targets/firefox14_osx.rb +6 -0
  128. data/features/support/targets/firefox14_windows7.rb +6 -0
  129. data/features/support/url_helper.rb +57 -0
  130. data/features/table.feature +122 -0
  131. data/features/table_cell.feature +45 -0
  132. data/features/text_area.feature +51 -0
  133. data/features/text_field.feature +70 -0
  134. data/features/unordered_list.feature +56 -0
  135. data/features/video.feature +73 -0
  136. data/lib/page-object-lds.rb +421 -0
  137. data/lib/page-object/accessors.rb +1334 -0
  138. data/lib/page-object/core_ext/string.rb +5 -0
  139. data/lib/page-object/element_locators.rb +21 -0
  140. data/lib/page-object/elements/area.rb +31 -0
  141. data/lib/page-object/elements/audio.rb +9 -0
  142. data/lib/page-object/elements/bold.rb +11 -0
  143. data/lib/page-object/elements/button.rb +35 -0
  144. data/lib/page-object/elements/canvas.rb +23 -0
  145. data/lib/page-object/elements/check_box.rb +40 -0
  146. data/lib/page-object/elements/div.rb +19 -0
  147. data/lib/page-object/elements/element.rb +225 -0
  148. data/lib/page-object/elements/file_field.rb +41 -0
  149. data/lib/page-object/elements/form.rb +39 -0
  150. data/lib/page-object/elements/heading.rb +15 -0
  151. data/lib/page-object/elements/hidden_field.rb +22 -0
  152. data/lib/page-object/elements/image.rb +39 -0
  153. data/lib/page-object/elements/label.rb +19 -0
  154. data/lib/page-object/elements/link.rb +49 -0
  155. data/lib/page-object/elements/list_item.rb +19 -0
  156. data/lib/page-object/elements/media.rb +45 -0
  157. data/lib/page-object/elements/option.rb +10 -0
  158. data/lib/page-object/elements/ordered_list.rb +53 -0
  159. data/lib/page-object/elements/paragraph.rb +9 -0
  160. data/lib/page-object/elements/radio_button.rb +40 -0
  161. data/lib/page-object/elements/select_list.rb +45 -0
  162. data/lib/page-object/elements/span.rb +19 -0
  163. data/lib/page-object/elements/table.rb +82 -0
  164. data/lib/page-object/elements/table_cell.rb +28 -0
  165. data/lib/page-object/elements/table_row.rb +53 -0
  166. data/lib/page-object/elements/text_area.rb +41 -0
  167. data/lib/page-object/elements/text_field.rb +45 -0
  168. data/lib/page-object/elements/unordered_list.rb +54 -0
  169. data/lib/page-object/elements/video.rb +18 -0
  170. data/lib/page-object/indexed_properties.rb +36 -0
  171. data/lib/page-object/javascript/angularjs.rb +14 -0
  172. data/lib/page-object/javascript/jquery.rb +14 -0
  173. data/lib/page-object/javascript/prototype.rb +14 -0
  174. data/lib/page-object/javascript/yui.rb +19 -0
  175. data/lib/page-object/javascript_framework_facade.rb +80 -0
  176. data/lib/page-object/loads_platform.rb +26 -0
  177. data/lib/page-object/locator_generator.rb +130 -0
  178. data/lib/page-object/nested_elements.rb +17 -0
  179. data/lib/page-object/page_factory.rb +108 -0
  180. data/lib/page-object/page_populator.rb +83 -0
  181. data/lib/page-object/platforms.rb +19 -0
  182. data/lib/page-object/platforms/lds_watir_webdriver.rb +17 -0
  183. data/lib/page-object/platforms/lds_watir_webdriver/check_box.rb +29 -0
  184. data/lib/page-object/platforms/lds_watir_webdriver/element.rb +249 -0
  185. data/lib/page-object/platforms/lds_watir_webdriver/file_field.rb +16 -0
  186. data/lib/page-object/platforms/lds_watir_webdriver/form.rb +16 -0
  187. data/lib/page-object/platforms/lds_watir_webdriver/image.rb +22 -0
  188. data/lib/page-object/platforms/lds_watir_webdriver/link.rb +15 -0
  189. data/lib/page-object/platforms/lds_watir_webdriver/ordered_list.rb +35 -0
  190. data/lib/page-object/platforms/lds_watir_webdriver/page_object.rb +1044 -0
  191. data/lib/page-object/platforms/lds_watir_webdriver/radio_button.rb +22 -0
  192. data/lib/page-object/platforms/lds_watir_webdriver/select_list.rb +74 -0
  193. data/lib/page-object/platforms/lds_watir_webdriver/table.rb +38 -0
  194. data/lib/page-object/platforms/lds_watir_webdriver/table_row.rb +37 -0
  195. data/lib/page-object/platforms/lds_watir_webdriver/text_area.rb +23 -0
  196. data/lib/page-object/platforms/lds_watir_webdriver/text_field.rb +16 -0
  197. data/lib/page-object/platforms/lds_watir_webdriver/unordered_list.rb +36 -0
  198. data/lib/page-object/platforms/selenium_webdriver.rb +17 -0
  199. data/lib/page-object/platforms/selenium_webdriver/button.rb +15 -0
  200. data/lib/page-object/platforms/selenium_webdriver/check_box.rb +29 -0
  201. data/lib/page-object/platforms/selenium_webdriver/element.rb +291 -0
  202. data/lib/page-object/platforms/selenium_webdriver/file_field.rb +16 -0
  203. data/lib/page-object/platforms/selenium_webdriver/form.rb +16 -0
  204. data/lib/page-object/platforms/selenium_webdriver/image.rb +28 -0
  205. data/lib/page-object/platforms/selenium_webdriver/link.rb +23 -0
  206. data/lib/page-object/platforms/selenium_webdriver/ordered_list.rb +39 -0
  207. data/lib/page-object/platforms/selenium_webdriver/page_object.rb +1162 -0
  208. data/lib/page-object/platforms/selenium_webdriver/radio_button.rb +22 -0
  209. data/lib/page-object/platforms/selenium_webdriver/select_list.rb +93 -0
  210. data/lib/page-object/platforms/selenium_webdriver/surrogate_selenium_element.rb +42 -0
  211. data/lib/page-object/platforms/selenium_webdriver/table.rb +42 -0
  212. data/lib/page-object/platforms/selenium_webdriver/table_row.rb +43 -0
  213. data/lib/page-object/platforms/selenium_webdriver/text_area.rb +17 -0
  214. data/lib/page-object/platforms/selenium_webdriver/text_field.rb +17 -0
  215. data/lib/page-object/platforms/selenium_webdriver/unordered_list.rb +39 -0
  216. data/lib/page-object/platforms/watir_webdriver.rb +17 -0
  217. data/lib/page-object/platforms/watir_webdriver/check_box.rb +29 -0
  218. data/lib/page-object/platforms/watir_webdriver/element.rb +249 -0
  219. data/lib/page-object/platforms/watir_webdriver/file_field.rb +16 -0
  220. data/lib/page-object/platforms/watir_webdriver/form.rb +16 -0
  221. data/lib/page-object/platforms/watir_webdriver/image.rb +22 -0
  222. data/lib/page-object/platforms/watir_webdriver/link.rb +15 -0
  223. data/lib/page-object/platforms/watir_webdriver/ordered_list.rb +35 -0
  224. data/lib/page-object/platforms/watir_webdriver/page_object.rb +1044 -0
  225. data/lib/page-object/platforms/watir_webdriver/radio_button.rb +22 -0
  226. data/lib/page-object/platforms/watir_webdriver/select_list.rb +74 -0
  227. data/lib/page-object/platforms/watir_webdriver/table.rb +38 -0
  228. data/lib/page-object/platforms/watir_webdriver/table_row.rb +37 -0
  229. data/lib/page-object/platforms/watir_webdriver/text_area.rb +23 -0
  230. data/lib/page-object/platforms/watir_webdriver/text_field.rb +16 -0
  231. data/lib/page-object/platforms/watir_webdriver/unordered_list.rb +36 -0
  232. data/lib/page-object/version.rb +4 -0
  233. data/lib/page-object/widgets.rb +134 -0
  234. data/page-object-lds.gemspec +33 -0
  235. data/pageobject.gems +1 -0
  236. data/spec/page-object/accessors_spec.rb +40 -0
  237. data/spec/page-object/element_locators_spec.rb +1100 -0
  238. data/spec/page-object/elements/area_spec.rb +45 -0
  239. data/spec/page-object/elements/bold_spec.rb +29 -0
  240. data/spec/page-object/elements/button_spec.rb +50 -0
  241. data/spec/page-object/elements/canvas_spec.rb +40 -0
  242. data/spec/page-object/elements/check_box_spec.rb +49 -0
  243. data/spec/page-object/elements/div_spec.rb +28 -0
  244. data/spec/page-object/elements/element_spec.rb +114 -0
  245. data/spec/page-object/elements/file_field_spec.rb +39 -0
  246. data/spec/page-object/elements/form_spec.rb +28 -0
  247. data/spec/page-object/elements/heading_spec.rb +48 -0
  248. data/spec/page-object/elements/hidden_field_spec.rb +28 -0
  249. data/spec/page-object/elements/image_spec.rb +66 -0
  250. data/spec/page-object/elements/label_spec.rb +29 -0
  251. data/spec/page-object/elements/link_spec.rb +49 -0
  252. data/spec/page-object/elements/list_item_spec.rb +29 -0
  253. data/spec/page-object/elements/nested_element_spec.rb +254 -0
  254. data/spec/page-object/elements/option_spec.rb +11 -0
  255. data/spec/page-object/elements/ordered_list_spec.rb +94 -0
  256. data/spec/page-object/elements/paragraph_spec.rb +27 -0
  257. data/spec/page-object/elements/select_list_spec.rb +142 -0
  258. data/spec/page-object/elements/selenium/radio_button_spec.rb +44 -0
  259. data/spec/page-object/elements/selenium/text_field_spec.rb +49 -0
  260. data/spec/page-object/elements/selenium_element_spec.rb +172 -0
  261. data/spec/page-object/elements/span_spec.rb +26 -0
  262. data/spec/page-object/elements/table_cell_spec.rb +21 -0
  263. data/spec/page-object/elements/table_row_spec.rb +70 -0
  264. data/spec/page-object/elements/table_spec.rb +98 -0
  265. data/spec/page-object/elements/text_area_spec.rb +39 -0
  266. data/spec/page-object/elements/unordered_list_spec.rb +94 -0
  267. data/spec/page-object/elements/watir_element_spec.rb +141 -0
  268. data/spec/page-object/javascript_framework_facade_spec.rb +61 -0
  269. data/spec/page-object/loads_platform_spec.rb +53 -0
  270. data/spec/page-object/page-object_spec.rb +413 -0
  271. data/spec/page-object/page_factory_spec.rb +238 -0
  272. data/spec/page-object/page_populator_spec.rb +122 -0
  273. data/spec/page-object/platforms/selenium_webdriver/selenium_page_object_spec.rb +68 -0
  274. data/spec/page-object/platforms/selenium_webdriver_spec.rb +29 -0
  275. data/spec/page-object/platforms/watir_webdriver/watir_page_object_spec.rb +29 -0
  276. data/spec/page-object/platforms/watir_webdriver_spec.rb +9 -0
  277. data/spec/page-object/selenium_accessors_spec.rb +609 -0
  278. data/spec/page-object/watir_accessors_spec.rb +1134 -0
  279. data/spec/page-object/widget_spec.rb +226 -0
  280. data/spec/spec_helper.rb +44 -0
  281. metadata +430 -0
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +1,1044 @@
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
+ #
811
+ # platform method to retrieve an array of label elements
812
+ #
813
+ def labels_for(identifier)
814
+ find_watir_elements("labels(identifier)", Elements::Label, identifier, 'label')
815
+ end
816
+
817
+ #
818
+ # platform method to set the file on a file_field element
819
+ # See PageObject::Accessors#file_field
820
+ #
821
+ def file_field_value_set(identifier, value)
822
+ process_watir_call("file_field(identifier).set(value)", Elements::FileField,
823
+ identifier, value)
824
+ end
825
+
826
+ #
827
+ # platform method to retrieve a file_field element
828
+ # See PageObject::Accessors#file_field
829
+ #
830
+ def file_field_for(identifier)
831
+ find_watir_element("file_field(identifier)", Elements::FileField, identifier)
832
+ end
833
+
834
+ #
835
+ # platform method to retrieve an array of file field elements
836
+ #
837
+ def file_fields_for(identifier)
838
+ find_watir_elements("file_fields(identifier)", Elements::FileField, identifier)
839
+ end
840
+
841
+ #
842
+ # platform method to click on an area
843
+ #
844
+ def click_area_for(identifier)
845
+ process_watir_call("area(identifier).click", Elements::Area, identifier, nil, 'area')
846
+ end
847
+
848
+ #
849
+ # platform method to retrieve an area element
850
+ #
851
+ def area_for(identifier)
852
+ find_watir_element("area(identifier)", Elements::Area, identifier, 'area')
853
+ end
854
+
855
+ #
856
+ # platform method to retrieve an array of area elements
857
+ #
858
+ def areas_for(identifier)
859
+ find_watir_elements("areas(identifier)", Elements::Area, identifier, 'area')
860
+ end
861
+
862
+ #
863
+ # platform method to retrieve a canvas element
864
+ #
865
+ def canvas_for(identifier)
866
+ find_watir_element("canvas(identifier)", Elements::Canvas, identifier, 'canvas')
867
+ end
868
+
869
+ #
870
+ # platform method to retrieve an array of canvas elements
871
+ #
872
+ def canvass_for(identifier)
873
+ find_watir_elements("canvases(identifier)", Elements::Canvas, identifier, 'canvas')
874
+ end
875
+
876
+ #
877
+ # platform method to retrieve an audio element
878
+ #
879
+ def audio_for(identifier)
880
+ find_watir_element("audio(identifier)", Elements::Audio, identifier, 'audio')
881
+ end
882
+
883
+ #
884
+ # platform method to retrieve an array of audio elements
885
+ #
886
+ def audios_for(identifier)
887
+ find_watir_elements("audios(identifier)", Elements::Audio, identifier, 'audio')
888
+ end
889
+
890
+ #
891
+ # platform method to retrieve a video element
892
+ #
893
+ def video_for(identifier)
894
+ find_watir_element("video(identifier)", Elements::Video, identifier, 'video')
895
+ end
896
+
897
+ #
898
+ # platform method to retrieve an array of video elements
899
+ #
900
+ def videos_for(identifier)
901
+ find_watir_elements("videos(identifier)", Elements::Video, identifier, 'video')
902
+ end
903
+
904
+ #
905
+ # platform method to return a PageObject::Elements::Element element
906
+ # See PageObject::Accessors#element
907
+ #
908
+ def element_for(tag, identifier)
909
+ find_watir_element("#{tag.to_s}(identifier)", Elements::Element, identifier, tag.to_s)
910
+ end
911
+
912
+ #
913
+ # platform method to return an array of PageObject::Elements::Element elements
914
+ # See PageObject::Accessors#element
915
+ #
916
+ def elements_for(tag, identifier)
917
+ find_watir_elements("#{tag.to_s}s(identifier)", Elements::Element, identifier, tag.to_s)
918
+ end
919
+
920
+ #
921
+ # platform method to return a svg element
922
+ #
923
+ def svg_for(identifier)
924
+ find_watir_element("element(identifier)", Elements::Element, identifier)
925
+ end
926
+
927
+ #
928
+ # platform method to return an array of svg elements
929
+ #
930
+ def svgs_for(identifier)
931
+ find_watir_elements("element(identifier)", Elements::Element, identifier)
932
+ end
933
+
934
+ #
935
+ # platform method to retrieve the text for a b
936
+ # See PageObject::Accessors#b
937
+ #
938
+ def b_text_for(identifier)
939
+ process_watir_call("b(identifier).text", Elements::Bold, identifier, nil, 'b')
940
+ end
941
+
942
+ #
943
+ # platform method to retrieve the b element
944
+ # See PageObject::Accessors#h1
945
+ #
946
+ def b_for(identifier)
947
+ find_watir_element("b(identifier)", Elements::Bold, identifier, 'b')
948
+ end
949
+
950
+ #
951
+ # platform method to retrieve an array of bs
952
+ #
953
+ def bs_for(identifier)
954
+ find_watir_elements("bs(identifier)", Elements::Bold, identifier, 'b')
955
+ end
956
+
957
+ private
958
+
959
+ def find_watir_elements(the_call, type, identifier, tag_name=nil)
960
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
961
+ elements = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
962
+ switch_to_default_content(frame_identifiers)
963
+ elements.map { |element| type.new(element, :platform => :watir_webdriver) }
964
+ end
965
+
966
+ def find_watir_element(the_call, type, identifier, tag_name=nil)
967
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
968
+ element = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
969
+ switch_to_default_content(frame_identifiers)
970
+ type.new(element, :platform => :watir_webdriver)
971
+ end
972
+
973
+ def process_watir_call(the_call, type, identifier, value=nil, tag_name=nil)
974
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
975
+ value = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
976
+ switch_to_default_content(frame_identifiers)
977
+ value
978
+ end
979
+
980
+ def parse_identifiers(identifier, element, tag_name=nil)
981
+ frame_identifiers = identifier.delete(:frame)
982
+ identifier = add_tagname_if_needed identifier, tag_name if tag_name
983
+ identifier = element.watir_identifier_for identifier
984
+ return identifier, frame_identifiers
985
+ end
986
+
987
+ def add_tagname_if_needed identifier, tag
988
+ return identifier if identifier.length < 2 and not identifier[:name]
989
+ identifier[:tag_name] = tag if identifier[:name]
990
+ identifier
991
+ end
992
+
993
+ def nested_frames(frame_identifiers)
994
+ return if frame_identifiers.nil?
995
+ frame_str = ''
996
+ frame_identifiers.each do |frame|
997
+ type = frame.keys.first
998
+ identifier = frame.values.first.map do |key, value|
999
+ if value.is_a?(Regexp)
1000
+ ":#{key} => #{value.inspect}"
1001
+ elsif value.to_s.is_integer
1002
+ ":#{key} => #{value}"
1003
+ else
1004
+ ":#{key} => '#{value}'"
1005
+ end
1006
+ end.join(', ')
1007
+ frame_str += "#{type.to_s}(#{identifier})."
1008
+ end
1009
+ frame_str
1010
+ end
1011
+
1012
+ def switch_to_default_content(frame_identifiers)
1013
+ @browser.wd.switch_to.default_content unless frame_identifiers.nil?
1014
+ end
1015
+
1016
+ def css_element
1017
+ "element(identifier)"
1018
+ end
1019
+
1020
+ def css_elements
1021
+ "elements(identifier)"
1022
+ end
1023
+
1024
+ def call_for_watir_element(identifier, call)
1025
+ identifier[:css] ? "#{css_element}" : call
1026
+ end
1027
+
1028
+ def call_for_watir_elements(identifier, call)
1029
+ identifier[:css] ? "#{css_elements}" : call
1030
+ end
1031
+
1032
+ def switch_to_frame(frame_identifiers)
1033
+ unless frame_identifiers.nil?
1034
+ frame_identifiers.each do |frame|
1035
+ frame_id = frame.values.first
1036
+ value = frame_id.values.first
1037
+ @browser.wd.switch_to.frame(value)
1038
+ end
1039
+ end
1040
+ end
1041
+ end
1042
+ end
1043
+ end
1044
+ end