page_object 1.1.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 (272) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +7 -0
  7. data/ChangeLog +809 -0
  8. data/Gemfile +14 -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 +98 -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 +55 -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 +207 -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 +117 -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/section.feature +132 -0
  81. data/features/select_list.feature +86 -0
  82. data/features/span.feature +37 -0
  83. data/features/step_definitions/accessor_steps.rb +64 -0
  84. data/features/step_definitions/area_steps.rb +19 -0
  85. data/features/step_definitions/async_steps.rb +83 -0
  86. data/features/step_definitions/audio_steps.rb +27 -0
  87. data/features/step_definitions/bold_steps.rb +12 -0
  88. data/features/step_definitions/button_steps.rb +48 -0
  89. data/features/step_definitions/canvas_steps.rb +15 -0
  90. data/features/step_definitions/check_box_steps.rb +35 -0
  91. data/features/step_definitions/div_steps.rb +19 -0
  92. data/features/step_definitions/element_steps.rb +266 -0
  93. data/features/step_definitions/file_field_steps.rb +19 -0
  94. data/features/step_definitions/form_steps.rb +19 -0
  95. data/features/step_definitions/frames_steps.rb +159 -0
  96. data/features/step_definitions/generic_element_steps.rb +31 -0
  97. data/features/step_definitions/gxt_table_steps.rb +58 -0
  98. data/features/step_definitions/headings_steps.rb +12 -0
  99. data/features/step_definitions/hidden_field_steps.rb +27 -0
  100. data/features/step_definitions/image_steps.rb +27 -0
  101. data/features/step_definitions/indexed_property_steps.rb +163 -0
  102. data/features/step_definitions/javascript_steps.rb +53 -0
  103. data/features/step_definitions/label_steps.rb +19 -0
  104. data/features/step_definitions/link_steps.rb +40 -0
  105. data/features/step_definitions/list_item_steps.rb +19 -0
  106. data/features/step_definitions/modal_dialog_steps.rb +62 -0
  107. data/features/step_definitions/multi_elements_steps.rb +541 -0
  108. data/features/step_definitions/nested_elements_steps.rb +212 -0
  109. data/features/step_definitions/ordered_list_steps.rb +23 -0
  110. data/features/step_definitions/page_level_actions_steps.rb +135 -0
  111. data/features/step_definitions/page_traversal_steps.rb +4 -0
  112. data/features/step_definitions/paragraph_steps.rb +28 -0
  113. data/features/step_definitions/radio_button_group_steps.rb +36 -0
  114. data/features/step_definitions/radio_button_steps.rb +27 -0
  115. data/features/step_definitions/section_steps.rb +268 -0
  116. data/features/step_definitions/select_list_steps.rb +65 -0
  117. data/features/step_definitions/span_steps.rb +19 -0
  118. data/features/step_definitions/table_cell_steps.rb +15 -0
  119. data/features/step_definitions/table_row_steps.rb +23 -0
  120. data/features/step_definitions/table_steps.rb +70 -0
  121. data/features/step_definitions/text_area_steps.rb +35 -0
  122. data/features/step_definitions/text_field_steps.rb +35 -0
  123. data/features/step_definitions/unordered_list_steps.rb +23 -0
  124. data/features/step_definitions/video_steps.rb +45 -0
  125. data/features/support/ajax_text_environment.rb +26 -0
  126. data/features/support/env.rb +8 -0
  127. data/features/support/hooks.rb +8 -0
  128. data/features/support/page.rb +382 -0
  129. data/features/support/persistent_browser.rb +70 -0
  130. data/features/support/targets/firefox14_osx.rb +6 -0
  131. data/features/support/targets/firefox14_windows7.rb +6 -0
  132. data/features/support/url_helper.rb +57 -0
  133. data/features/table.feature +122 -0
  134. data/features/table_cell.feature +45 -0
  135. data/features/table_row.feature +43 -0
  136. data/features/text_area.feature +51 -0
  137. data/features/text_field.feature +70 -0
  138. data/features/unordered_list.feature +56 -0
  139. data/features/video.feature +73 -0
  140. data/lib/page-object.rb +421 -0
  141. data/lib/page-object/accessors.rb +1412 -0
  142. data/lib/page-object/core_ext/string.rb +5 -0
  143. data/lib/page-object/element_locators.rb +21 -0
  144. data/lib/page-object/elements.rb +60 -0
  145. data/lib/page-object/elements/area.rb +31 -0
  146. data/lib/page-object/elements/audio.rb +9 -0
  147. data/lib/page-object/elements/bold.rb +11 -0
  148. data/lib/page-object/elements/button.rb +35 -0
  149. data/lib/page-object/elements/canvas.rb +23 -0
  150. data/lib/page-object/elements/check_box.rb +37 -0
  151. data/lib/page-object/elements/div.rb +19 -0
  152. data/lib/page-object/elements/element.rb +226 -0
  153. data/lib/page-object/elements/file_field.rb +38 -0
  154. data/lib/page-object/elements/form.rb +36 -0
  155. data/lib/page-object/elements/heading.rb +15 -0
  156. data/lib/page-object/elements/hidden_field.rb +22 -0
  157. data/lib/page-object/elements/image.rb +36 -0
  158. data/lib/page-object/elements/label.rb +19 -0
  159. data/lib/page-object/elements/link.rb +46 -0
  160. data/lib/page-object/elements/list_item.rb +19 -0
  161. data/lib/page-object/elements/media.rb +45 -0
  162. data/lib/page-object/elements/option.rb +10 -0
  163. data/lib/page-object/elements/ordered_list.rb +50 -0
  164. data/lib/page-object/elements/paragraph.rb +9 -0
  165. data/lib/page-object/elements/radio_button.rb +37 -0
  166. data/lib/page-object/elements/select_list.rb +42 -0
  167. data/lib/page-object/elements/span.rb +19 -0
  168. data/lib/page-object/elements/table.rb +79 -0
  169. data/lib/page-object/elements/table_cell.rb +28 -0
  170. data/lib/page-object/elements/table_row.rb +50 -0
  171. data/lib/page-object/elements/text_area.rb +38 -0
  172. data/lib/page-object/elements/text_field.rb +42 -0
  173. data/lib/page-object/elements/unordered_list.rb +51 -0
  174. data/lib/page-object/elements/video.rb +18 -0
  175. data/lib/page-object/indexed_properties.rb +40 -0
  176. data/lib/page-object/javascript/angularjs.rb +14 -0
  177. data/lib/page-object/javascript/jquery.rb +14 -0
  178. data/lib/page-object/javascript/prototype.rb +14 -0
  179. data/lib/page-object/javascript/yui.rb +19 -0
  180. data/lib/page-object/javascript_framework_facade.rb +80 -0
  181. data/lib/page-object/loads_platform.rb +45 -0
  182. data/lib/page-object/locator_generator.rb +131 -0
  183. data/lib/page-object/nested_elements.rb +17 -0
  184. data/lib/page-object/page_factory.rb +108 -0
  185. data/lib/page-object/page_populator.rb +83 -0
  186. data/lib/page-object/platforms.rb +18 -0
  187. data/lib/page-object/platforms/selenium_webdriver.rb +30 -0
  188. data/lib/page-object/platforms/selenium_webdriver/button.rb +15 -0
  189. data/lib/page-object/platforms/selenium_webdriver/check_box.rb +29 -0
  190. data/lib/page-object/platforms/selenium_webdriver/element.rb +291 -0
  191. data/lib/page-object/platforms/selenium_webdriver/file_field.rb +16 -0
  192. data/lib/page-object/platforms/selenium_webdriver/form.rb +16 -0
  193. data/lib/page-object/platforms/selenium_webdriver/image.rb +28 -0
  194. data/lib/page-object/platforms/selenium_webdriver/link.rb +23 -0
  195. data/lib/page-object/platforms/selenium_webdriver/ordered_list.rb +39 -0
  196. data/lib/page-object/platforms/selenium_webdriver/page_object.rb +1237 -0
  197. data/lib/page-object/platforms/selenium_webdriver/radio_button.rb +22 -0
  198. data/lib/page-object/platforms/selenium_webdriver/select_list.rb +93 -0
  199. data/lib/page-object/platforms/selenium_webdriver/surrogate_selenium_element.rb +42 -0
  200. data/lib/page-object/platforms/selenium_webdriver/table.rb +42 -0
  201. data/lib/page-object/platforms/selenium_webdriver/table_row.rb +43 -0
  202. data/lib/page-object/platforms/selenium_webdriver/text_area.rb +17 -0
  203. data/lib/page-object/platforms/selenium_webdriver/text_field.rb +17 -0
  204. data/lib/page-object/platforms/selenium_webdriver/unordered_list.rb +39 -0
  205. data/lib/page-object/platforms/watir_webdriver.rb +30 -0
  206. data/lib/page-object/platforms/watir_webdriver/check_box.rb +29 -0
  207. data/lib/page-object/platforms/watir_webdriver/element.rb +249 -0
  208. data/lib/page-object/platforms/watir_webdriver/file_field.rb +16 -0
  209. data/lib/page-object/platforms/watir_webdriver/form.rb +16 -0
  210. data/lib/page-object/platforms/watir_webdriver/image.rb +22 -0
  211. data/lib/page-object/platforms/watir_webdriver/link.rb +15 -0
  212. data/lib/page-object/platforms/watir_webdriver/ordered_list.rb +35 -0
  213. data/lib/page-object/platforms/watir_webdriver/page_object.rb +1082 -0
  214. data/lib/page-object/platforms/watir_webdriver/radio_button.rb +22 -0
  215. data/lib/page-object/platforms/watir_webdriver/select_list.rb +74 -0
  216. data/lib/page-object/platforms/watir_webdriver/table.rb +38 -0
  217. data/lib/page-object/platforms/watir_webdriver/table_row.rb +37 -0
  218. data/lib/page-object/platforms/watir_webdriver/text_area.rb +23 -0
  219. data/lib/page-object/platforms/watir_webdriver/text_field.rb +16 -0
  220. data/lib/page-object/platforms/watir_webdriver/unordered_list.rb +36 -0
  221. data/lib/page-object/sections.rb +29 -0
  222. data/lib/page-object/version.rb +4 -0
  223. data/lib/page-object/widgets.rb +133 -0
  224. data/page_object.gemspec +31 -0
  225. data/pageobject.gems +1 -0
  226. data/spec/page-object/accessors_spec.rb +40 -0
  227. data/spec/page-object/element_locators_spec.rb +1122 -0
  228. data/spec/page-object/elements/area_spec.rb +45 -0
  229. data/spec/page-object/elements/bold_spec.rb +29 -0
  230. data/spec/page-object/elements/button_spec.rb +64 -0
  231. data/spec/page-object/elements/canvas_spec.rb +40 -0
  232. data/spec/page-object/elements/check_box_spec.rb +49 -0
  233. data/spec/page-object/elements/div_spec.rb +28 -0
  234. data/spec/page-object/elements/element_spec.rb +114 -0
  235. data/spec/page-object/elements/file_field_spec.rb +39 -0
  236. data/spec/page-object/elements/form_spec.rb +28 -0
  237. data/spec/page-object/elements/heading_spec.rb +48 -0
  238. data/spec/page-object/elements/hidden_field_spec.rb +28 -0
  239. data/spec/page-object/elements/image_spec.rb +66 -0
  240. data/spec/page-object/elements/label_spec.rb +29 -0
  241. data/spec/page-object/elements/link_spec.rb +49 -0
  242. data/spec/page-object/elements/list_item_spec.rb +29 -0
  243. data/spec/page-object/elements/nested_element_spec.rb +254 -0
  244. data/spec/page-object/elements/option_spec.rb +11 -0
  245. data/spec/page-object/elements/ordered_list_spec.rb +94 -0
  246. data/spec/page-object/elements/paragraph_spec.rb +27 -0
  247. data/spec/page-object/elements/select_list_spec.rb +142 -0
  248. data/spec/page-object/elements/selenium/radio_button_spec.rb +44 -0
  249. data/spec/page-object/elements/selenium/text_field_spec.rb +49 -0
  250. data/spec/page-object/elements/selenium_element_spec.rb +177 -0
  251. data/spec/page-object/elements/span_spec.rb +26 -0
  252. data/spec/page-object/elements/table_cell_spec.rb +21 -0
  253. data/spec/page-object/elements/table_row_spec.rb +70 -0
  254. data/spec/page-object/elements/table_spec.rb +98 -0
  255. data/spec/page-object/elements/text_area_spec.rb +39 -0
  256. data/spec/page-object/elements/unordered_list_spec.rb +94 -0
  257. data/spec/page-object/elements/watir_element_spec.rb +145 -0
  258. data/spec/page-object/javascript_framework_facade_spec.rb +61 -0
  259. data/spec/page-object/loads_platform_spec.rb +53 -0
  260. data/spec/page-object/page-object_spec.rb +407 -0
  261. data/spec/page-object/page_factory_spec.rb +238 -0
  262. data/spec/page-object/page_populator_spec.rb +122 -0
  263. data/spec/page-object/page_section_spec.rb +73 -0
  264. data/spec/page-object/platforms/selenium_webdriver/selenium_page_object_spec.rb +68 -0
  265. data/spec/page-object/platforms/selenium_webdriver_spec.rb +29 -0
  266. data/spec/page-object/platforms/watir_webdriver/watir_page_object_spec.rb +29 -0
  267. data/spec/page-object/platforms/watir_webdriver_spec.rb +9 -0
  268. data/spec/page-object/selenium_accessors_spec.rb +609 -0
  269. data/spec/page-object/watir_accessors_spec.rb +1134 -0
  270. data/spec/page-object/widget_spec.rb +226 -0
  271. data/spec/spec_helper.rb +47 -0
  272. metadata +601 -0
@@ -0,0 +1,1237 @@
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 the text from a table row
580
+ # See PageObject::Accessors#row
581
+ #
582
+ def row_text_for(identifier)
583
+ process_selenium_call(identifier, Elements::TableRow, 'tr') do |how, what|
584
+ @browser.find_element(how, what).text
585
+ end
586
+ end
587
+
588
+ #
589
+ # platform method to retrieve a table row element
590
+ # See PageObject::Accessors#row
591
+ #
592
+ def row_for(identifier)
593
+ find_selenium_element(identifier, Elements::TableRow, 'tr')
594
+ end
595
+
596
+ #
597
+ # platform method to retrieve all table row elements
598
+ #
599
+ def rows_for(identifier)
600
+ find_selenium_elements(identifier, Elements::TableRow, 'tr')
601
+ end
602
+
603
+ #
604
+ # platform method to retrieve an image element
605
+ # See PageObject::Accessors#image
606
+ #
607
+ def image_for(identifier)
608
+ find_selenium_element(identifier, Elements::Image, 'img')
609
+ end
610
+
611
+ #
612
+ # platform method to retrieve all image elements
613
+ #
614
+ def images_for(identifier)
615
+ find_selenium_elements(identifier, Elements::Image, 'img')
616
+ end
617
+
618
+ #
619
+ # platform method to retrieve a form element
620
+ # See PageObject::Accessors#form
621
+ #
622
+ def form_for(identifier)
623
+ find_selenium_element(identifier, Elements::Form, 'form')
624
+ end
625
+
626
+ #
627
+ # platform method to retrieve all forms
628
+ #
629
+ def forms_for(identifier)
630
+ find_selenium_elements(identifier, Elements::Form, 'form')
631
+ end
632
+
633
+ #
634
+ # platform method to retrieve the text from a list item
635
+ # See PageObject::Accessors#list_item
636
+ #
637
+ def list_item_text_for(identifier)
638
+ process_selenium_call(identifier, Elements::ListItem, 'li') do |how, what|
639
+ @browser.find_element(how, what).text
640
+ end
641
+ end
642
+
643
+ #
644
+ # platform method to retrieve a list item element
645
+ # See PageObject::Accessors#list_item
646
+ #
647
+ def list_item_for(identifier)
648
+ find_selenium_element(identifier, Elements::ListItem, 'li')
649
+ end
650
+
651
+ #
652
+ # platform method to retrieve all list items
653
+ #
654
+ def list_items_for(identifier)
655
+ find_selenium_elements(identifier, Elements::ListItem, 'li')
656
+ end
657
+
658
+ #
659
+ # platform method to retrieve the text from an unordered list
660
+ # See PageObject::Accessors#unordered_list
661
+ #
662
+ def unordered_list_text_for(identifier)
663
+ process_selenium_call(identifier, Elements::UnorderedList, 'ul') do |how, what|
664
+ @browser.find_element(how, what).text
665
+ end
666
+ end
667
+
668
+ #
669
+ # platform method to retrieve an unordered list element
670
+ # See PageObject::Accessors#unordered_list
671
+ #
672
+ def unordered_list_for(identifier)
673
+ find_selenium_element(identifier, Elements::UnorderedList, 'ul')
674
+ end
675
+
676
+ #
677
+ # platform method to retrieve all unordered lists
678
+ #
679
+ def unordered_lists_for(identifier)
680
+ find_selenium_elements(identifier, Elements::UnorderedList, 'ul')
681
+ end
682
+
683
+ #
684
+ # platform method to retrieve the text from an ordered list
685
+ # See PageObject::Accessors#ordered_list
686
+ #
687
+ def ordered_list_text_for(identifier)
688
+ process_selenium_call(identifier, Elements::OrderedList, 'ol') do |how, what|
689
+ @browser.find_element(how, what).text
690
+ end
691
+ end
692
+
693
+ #
694
+ # platform method to retrieve an ordered list element
695
+ # See PageObject::Accessors#ordered_list
696
+ #
697
+ def ordered_list_for(identifier)
698
+ find_selenium_element(identifier, Elements::OrderedList, 'ol')
699
+ end
700
+
701
+ #
702
+ # platform method to retrieve all ordered lists
703
+ #
704
+ def ordered_lists_for(identifier)
705
+ find_selenium_elements(identifier, Elements::OrderedList, 'ol')
706
+ end
707
+
708
+ #
709
+ # platform method to retrieve the text from a h1
710
+ # See PageObject::Accessors#h1
711
+ #
712
+ def h1_text_for(identifier)
713
+ process_selenium_call(identifier, Elements::Heading, 'h1') do |how, what|
714
+ @browser.find_element(how, what).text
715
+ end
716
+ end
717
+
718
+ #
719
+ # platform method to retrieve the h1 element
720
+ # See PageObject::Accessors#h1
721
+ #
722
+ def h1_for(identifier)
723
+ find_selenium_element(identifier, Elements::Heading, 'h1')
724
+ end
725
+
726
+ #
727
+ # platform method to retrieve all h1 elements
728
+ #
729
+ def h1s_for(identifier)
730
+ find_selenium_elements(identifier, Elements::Heading, 'h1')
731
+ end
732
+
733
+ #
734
+ # platform method to retrieve the text from a h2
735
+ # See PageObject::Accessors#h2
736
+ #
737
+ def h2_text_for(identifier)
738
+ process_selenium_call(identifier, Elements::Heading, 'h2') do |how, what|
739
+ @browser.find_element(how, what).text
740
+ end
741
+ end
742
+
743
+ #
744
+ # platform method to retrieve the h2 element
745
+ # See PageObject::Accessors#h2
746
+ #
747
+ def h2_for(identifier)
748
+ find_selenium_element(identifier, Elements::Heading, 'h2')
749
+ end
750
+
751
+ #
752
+ # platform method to retrieve all h2 elements
753
+ #
754
+ def h2s_for(identifier)
755
+ find_selenium_elements(identifier, Elements::Heading, 'h2')
756
+ end
757
+
758
+ #
759
+ # platform method to retrieve the text from a h3
760
+ # See PageObject::Accessors#h3
761
+ #
762
+ def h3_text_for(identifier)
763
+ process_selenium_call(identifier, Elements::Heading, 'h3') do |how, what|
764
+ @browser.find_element(how, what).text
765
+ end
766
+ end
767
+
768
+ #
769
+ # platform method to retrieve the h3 element
770
+ # See PageObject::Accessors#h3
771
+ #
772
+ def h3_for(identifier)
773
+ find_selenium_element(identifier, Elements::Heading, 'h3')
774
+ end
775
+
776
+ #
777
+ # platform method to retrieve all h3 elements
778
+ #
779
+ def h3s_for(identifier)
780
+ find_selenium_elements(identifier, Elements::Heading, 'h3')
781
+ end
782
+
783
+ #
784
+ # platform method to retrieve the text from a h4
785
+ # See PageObject::Accessors#h4
786
+ #
787
+ def h4_text_for(identifier)
788
+ process_selenium_call(identifier, Elements::Heading, 'h4') do |how, what|
789
+ @browser.find_element(how, what).text
790
+ end
791
+ end
792
+
793
+ #
794
+ # platform method to retrieve the h4 element
795
+ # See PageObject::Accessors#h4
796
+ #
797
+ def h4_for(identifier)
798
+ find_selenium_element(identifier, Elements::Heading, 'h4')
799
+ end
800
+
801
+ #
802
+ # platform method to retrieve all h4 elements
803
+ #
804
+ def h4s_for(identifier)
805
+ find_selenium_elements(identifier, Elements::Heading, 'h4')
806
+ end
807
+
808
+ #
809
+ # platform method to retrieve the text from a h5
810
+ # See PageObject::Accessors#h5
811
+ #
812
+ def h5_text_for(identifier)
813
+ process_selenium_call(identifier, Elements::Heading, 'h5') do |how, what|
814
+ @browser.find_element(how, what).text
815
+ end
816
+ end
817
+
818
+ #
819
+ # platform method to retrieve the h5 element
820
+ # See PageObject::Accessors#h5
821
+ #
822
+ def h5_for(identifier)
823
+ find_selenium_element(identifier, Elements::Heading, 'h5')
824
+ end
825
+
826
+ #
827
+ # platform method to retrieve all h5 elements
828
+ #
829
+ def h5s_for(identifier)
830
+ find_selenium_elements(identifier, Elements::Heading, 'h5')
831
+ end
832
+
833
+ #
834
+ # platform method to retrieve the text from a h6
835
+ # See PageObject::Accessors#h6
836
+ #
837
+ def h6_text_for(identifier)
838
+ process_selenium_call(identifier, Elements::Heading, 'h6') do |how, what|
839
+ @browser.find_element(how, what).text
840
+ end
841
+ end
842
+
843
+ #
844
+ # platform method to retrieve the h6 element
845
+ # See PageObject::Accessors#h6
846
+ #
847
+ def h6_for(identifier)
848
+ find_selenium_element(identifier, Elements::Heading, 'h6')
849
+ end
850
+
851
+ #
852
+ # platform method to retrieve all h6 elements
853
+ #
854
+ def h6s_for(identifier)
855
+ find_selenium_elements(identifier, Elements::Heading, 'h6')
856
+ end
857
+
858
+ #
859
+ # platform method to retrieve the text for a paragraph
860
+ # See PageObject::Accessors#paragraph
861
+ #
862
+ def paragraph_text_for(identifier)
863
+ process_selenium_call(identifier, Elements::Paragraph, 'p') do |how, what|
864
+ @browser.find_element(how, what).text
865
+ end
866
+ end
867
+
868
+ #
869
+ # platform method to retrieve the paragraph element
870
+ # See PageObject::Accessors#paragraph
871
+ #
872
+ def paragraph_for(identifier)
873
+ find_selenium_element(identifier, Elements::Paragraph, 'p')
874
+ end
875
+
876
+ #
877
+ # platform method to retrieve all paragraph elements
878
+ #
879
+ def paragraphs_for(identifier)
880
+ find_selenium_elements(identifier, Elements::Paragraph, 'p')
881
+ end
882
+
883
+ #
884
+ # platform method to return the text for a label
885
+ # See PageObject::Accessors#label
886
+ #
887
+ def label_text_for(identifier)
888
+ process_selenium_call(identifier, Elements::Label, 'label') do |how, what|
889
+ @browser.find_element(how, what).text
890
+ end
891
+ end
892
+
893
+
894
+ #
895
+ # platform method to return a PageObject::Elements::Label element
896
+ # See PageObject::Accessors#label
897
+ #
898
+ def label_for(identifier)
899
+ find_selenium_element(identifier, Elements::Label, 'label')
900
+ end
901
+
902
+
903
+ #
904
+ # platform method to retrieve all label elements
905
+ #
906
+ def labels_for(identifier)
907
+ find_selenium_elements(identifier, Elements::Label, 'label')
908
+ end
909
+
910
+ #
911
+ # platform method to set the file on a file_field element
912
+ # See PageObject::Accessors#file_field
913
+ #
914
+ def file_field_value_set(identifier, value)
915
+ process_selenium_call(identifier, Elements::FileField, 'input', :type => 'file') do |how, what|
916
+ @browser.find_element(how, what).send_keys(value)
917
+ end
918
+ end
919
+
920
+ #
921
+ # platform method to retrieve a file_field element
922
+ # See PageObject::Accessors#file_field
923
+ #
924
+ def file_field_for(identifier)
925
+ find_selenium_element(identifier, Elements::FileField, 'input', :type => 'file')
926
+ end
927
+
928
+ #
929
+ # platform method to return an array of file field elements
930
+ #
931
+ def file_fields_for(identifier)
932
+ find_selenium_elements(identifier, Elements::FileField, 'input', :type => 'file')
933
+ end
934
+
935
+ #
936
+ # platform method to click on an area
937
+ #
938
+ def click_area_for(identifier)
939
+ process_selenium_call(identifier, Elements::Area, 'area') do |how, what|
940
+ @browser.find_element(how, what).click
941
+ end
942
+ end
943
+
944
+ #
945
+ # platform method to retrieve an area element
946
+ #
947
+ def area_for(identifier)
948
+ find_selenium_element(identifier, Elements::Area, 'area')
949
+ end
950
+
951
+ #
952
+ # platform method to return an array of area elements
953
+ #
954
+ def areas_for(identifier)
955
+ find_selenium_elements(identifier, Elements::Area, 'area')
956
+ end
957
+
958
+ #
959
+ # platform method to retrieve a canvas element
960
+ #
961
+ def canvas_for(identifier)
962
+ find_selenium_element(identifier, Elements::Canvas, 'canvas')
963
+ end
964
+
965
+ #
966
+ # platform method to return an array of canvas elements
967
+ #
968
+ def canvass_for(identifier)
969
+ find_selenium_elements(identifier, Elements::Canvas, 'canvas')
970
+ end
971
+
972
+ #
973
+ # platform method to retrieve an audio element
974
+ #
975
+ def audio_for(identifier)
976
+ find_selenium_element(identifier, Elements::Audio, 'audio')
977
+ end
978
+
979
+ #
980
+ # platform method to return an array of audio elements
981
+ #
982
+ def audios_for(identifier)
983
+ find_selenium_elements(identifier, Elements::Audio, 'audio')
984
+ end
985
+
986
+ #
987
+ # platform method to retrieve a video element
988
+ #
989
+ def video_for(identifier)
990
+ find_selenium_element(identifier, Elements::Video, 'video')
991
+ end
992
+
993
+ #
994
+ # platform method to return an array of video elements
995
+ #
996
+ def videos_for(identifier)
997
+ find_selenium_elements(identifier, Elements::Video, 'video')
998
+ end
999
+
1000
+ #
1001
+ # platform method to retrieve a generic element
1002
+ # See PageObject::Accessors#element
1003
+ #
1004
+ def element_for(tag, identifier)
1005
+ find_selenium_element(identifier, Elements::Element, tag.to_s)
1006
+ end
1007
+
1008
+ #
1009
+ # platform method to retrieve a collection of generic elements
1010
+ # See PageObject::Accessors#elements
1011
+ #
1012
+ def elements_for(tag, identifier)
1013
+ find_selenium_elements(identifier, Elements::Element, tag.to_s)
1014
+ end
1015
+
1016
+ #
1017
+ # platform method to return a PageObject rooted at an element
1018
+ # See PageObject::Accessors#page_section
1019
+ #
1020
+ def page_for(identifier, page_class)
1021
+ find_selenium_page(identifier, page_class)
1022
+ end
1023
+
1024
+ #
1025
+ # platform method to return a collection of PageObjects rooted at elements
1026
+ # See PageObject::Accessors#page_sections
1027
+ #
1028
+ def pages_for(identifier, page_class)
1029
+ SectionCollection.new(find_selenium_pages(identifier, page_class))
1030
+ end
1031
+
1032
+ #
1033
+ # platform method to return a svg element
1034
+ #
1035
+ def svg_for(identifier)
1036
+ find_selenium_element(identifier, Elements::Element, 'svg')
1037
+ end
1038
+
1039
+ #
1040
+ # platform method to return an array of svg elements
1041
+ #
1042
+ def svgs_for(identifier)
1043
+ find_selenium_elements(identifier, Elements::Element, 'svg')
1044
+ end
1045
+
1046
+
1047
+ #
1048
+ # platform method to retrieve the text from a b
1049
+ # See PageObject::Accessors#b
1050
+ #
1051
+ def b_text_for(identifier)
1052
+ process_selenium_call(identifier, Elements::Bold, 'b') do |how, what|
1053
+ @browser.find_element(how, what).text
1054
+ end
1055
+ end
1056
+
1057
+ #
1058
+ # platform method to retrieve the h1 element
1059
+ # See PageObject::Accessors#b
1060
+ #
1061
+ def b_for(identifier)
1062
+ find_selenium_element(identifier, Elements::Bold, 'b')
1063
+ end
1064
+
1065
+ #
1066
+ # platform method to retrieve all b elements
1067
+ #
1068
+ def bs_for(identifier)
1069
+ find_selenium_elements(identifier, Elements::Bold, 'b')
1070
+ end
1071
+
1072
+ private
1073
+
1074
+ def process_selenium_call(identifier, type, tag, other=nil)
1075
+ how, what, frame_identifiers = parse_identifiers(identifier, type, tag, other)
1076
+ switch_to_frame(frame_identifiers)
1077
+ value = yield how, what
1078
+ @browser.switch_to.default_content unless frame_identifiers.nil?
1079
+ value
1080
+ end
1081
+
1082
+ def find_selenium_element(identifier, type, tag, other=nil)
1083
+ regexp = delete_regexp(identifier)
1084
+ how, what, frame_identifiers = parse_identifiers(identifier, type, tag, other)
1085
+ switch_to_frame(frame_identifiers)
1086
+ begin
1087
+ unless regexp
1088
+ element = @browser.find_element(how, what)
1089
+ else
1090
+ elements = @browser.find_elements(how, what)
1091
+ element = elements.find {|ele| matches_selector?(ele, regexp[0], regexp[1])}
1092
+ end
1093
+ rescue Selenium::WebDriver::Error::NoSuchElementError
1094
+ @browser.switch_to.default_content unless frame_identifiers.nil?
1095
+ return build_null_object(identifier, type, tag, other)
1096
+ end
1097
+ @browser.switch_to.default_content unless frame_identifiers.nil?
1098
+ type.new(element, :platform => :selenium_webdriver)
1099
+ end
1100
+
1101
+ def find_selenium_elements(identifier, type, tag, other=nil)
1102
+ regexp = delete_regexp(identifier)
1103
+ how, what, frame_identifiers = parse_identifiers(identifier, type, tag, other)
1104
+ switch_to_frame(frame_identifiers)
1105
+ unless regexp
1106
+ elements = @browser.find_elements(how, what)
1107
+ else
1108
+ eles = @browser.find_elements(how, what)
1109
+ elements = eles.find_all {|ele| matches_selector?(ele, regexp[0], regexp[1])}
1110
+ end
1111
+ @browser.switch_to.default_content unless frame_identifiers.nil?
1112
+ elements.map { |element| type.new(element, :platform => :selenium_webdriver) }
1113
+ end
1114
+
1115
+ def find_selenium_pages(identifier, page_class)
1116
+ regexp = delete_regexp(identifier)
1117
+ how, what, frame_identifiers = parse_identifiers(identifier, Elements::Element, 'element')
1118
+ switch_to_frame(frame_identifiers)
1119
+ unless regexp
1120
+ elements = @browser.find_elements(how, what)
1121
+ else
1122
+ eles = @browser.find_elements(how, what)
1123
+ elements = eles.find_all {|ele| matches_selector?(ele, regexp[0], regexp[1])}
1124
+ end
1125
+ @browser.switch_to.default_content unless frame_identifiers.nil?
1126
+ elements.map { |element| page_class.new(element) }
1127
+ end
1128
+
1129
+ def find_selenium_page(identifier, page_class)
1130
+ type, tag = Elements::Element, 'element'
1131
+ regexp = delete_regexp(identifier)
1132
+ how, what, frame_identifiers = parse_identifiers(identifier, type, tag)
1133
+ switch_to_frame(frame_identifiers)
1134
+ begin
1135
+ unless regexp
1136
+ element = @browser.find_element(how, what)
1137
+ else
1138
+ elements = @browser.find_elements(how, what)
1139
+ element = elements.find {|ele| matches_selector?(ele, regexp[0], regexp[1])}
1140
+ end
1141
+ rescue Selenium::WebDriver::Error::NoSuchElementError
1142
+ @browser.switch_to.default_content unless frame_identifiers.nil?
1143
+ return build_null_object(identifier, type, tag, nil)
1144
+ end
1145
+ @browser.switch_to.default_content unless frame_identifiers.nil?
1146
+ page_class.new(element)
1147
+ end
1148
+
1149
+ def build_null_object(identifier, type, tag, other)
1150
+ null_element = SurrogateSeleniumElement.new
1151
+ null_element.identifier = identifier
1152
+ null_element.type = type
1153
+ null_element.tag = tag
1154
+ null_element.other = other
1155
+ null_element.platform = self
1156
+ Elements::Element.new(null_element, :platform => :selenium_webdriver)
1157
+ end
1158
+
1159
+ def delete_regexp(identifier)
1160
+ regexp = identifier.find {|ident| ident[1].is_a?(Regexp)}
1161
+ identifier.delete(regexp[0]) if regexp
1162
+ regexp
1163
+ end
1164
+
1165
+ def parse_identifiers(identifier, element, tag_name=nil, additional=nil)
1166
+ frame_identifiers = identifier.delete(:frame)
1167
+ identifier = add_tagname_if_needed identifier, tag_name, additional if tag_name
1168
+ how, what = element.selenium_identifier_for identifier
1169
+ return how, what, frame_identifiers
1170
+ end
1171
+
1172
+ def add_tagname_if_needed identifier, tag, additional=nil
1173
+ return identifier if identifier.length < 2 and supported_identifier(identifier, tag, additional)
1174
+ identifier[:tag_name] = tag
1175
+ if additional
1176
+ additional.each do |key, value|
1177
+ identifier[key] = value
1178
+ end
1179
+ end
1180
+ identifier
1181
+ end
1182
+
1183
+ def supported_identifier(identifier, tag, additional)
1184
+ return false if identifier.size == 0
1185
+ return false if identifier[:index]
1186
+ return false if identifier[:action] and tag == 'form'
1187
+ return false if identifier[:alt] and tag == 'img'
1188
+ return false if identifier[:alt] and tag == 'input' and
1189
+ ['submit', 'image', 'button', 'reset'].include? additional[:type]
1190
+ return false if identifier[:href] and tag == 'a'
1191
+ return false if identifier[:src] and tag == 'input' and
1192
+ ['submit', 'image', 'button', 'reset'].include? additional[:type]
1193
+ return false if identifier[:src] and tag == 'img'
1194
+ return false if identifier[:label]
1195
+ return false if identifier[:text] and tag == 'input' and additional[:type] == 'hidden'
1196
+ return false if identifier[:text] and tag == 'input' and additional[:type] == 'text'
1197
+ return false if identifier[:text] and ['div', 'span', 'td', 'label', 'li'].include? tag
1198
+ return false if identifier[:title] and tag == 'input' and additional[:type] == 'text'
1199
+ return false if identifier[:title] and tag == 'input' and additional[:type] == 'file'
1200
+ return false if identifier[:title] and tag == 'a'
1201
+ return false if identifier[:title] and tag == 'span'
1202
+ return false if identifier[:title] and tag == 'div'
1203
+ return false if identifier[:value] and tag == 'input' and
1204
+ ['radio', 'submit', 'image', 'button', 'reset', 'checkbox', 'hidden'].include? additional[:type]
1205
+ true
1206
+ end
1207
+
1208
+ def matches_selector?(element, how, what)
1209
+ what === fetch_value(element, how)
1210
+ end
1211
+
1212
+ def fetch_value(element, how)
1213
+ case how
1214
+ when :text
1215
+ element.text
1216
+ when :tag_name
1217
+ element.tag_name.downcase
1218
+ when :href
1219
+ (href = element.attribute(:href)) && href.strip
1220
+ else
1221
+ element.attribute(how.to_s.gsub("_", "-").to_sym)
1222
+ end
1223
+ end
1224
+
1225
+ def switch_to_frame(frame_identifiers)
1226
+ unless frame_identifiers.nil?
1227
+ frame_identifiers.each do |frame|
1228
+ frame_id = frame.values.first
1229
+ value = frame_id.values.first
1230
+ @browser.switch_to.frame(value)
1231
+ end
1232
+ end
1233
+ end
1234
+ end
1235
+ end
1236
+ end
1237
+ end