page-object-lds 0.0.1

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