druid-s 1.0.0

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 (219) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +27 -0
  6. data/ChangeLog +541 -0
  7. data/Gemfile +8 -0
  8. data/README.md +78 -0
  9. data/Rakefile +33 -0
  10. data/cucumber.yml +6 -0
  11. data/druid.gemspec +30 -0
  12. data/features/area.feature +33 -0
  13. data/features/async.feature +16 -0
  14. data/features/audio.feature +61 -0
  15. data/features/bold.feature +20 -0
  16. data/features/button.feature +81 -0
  17. data/features/canvas.feature +34 -0
  18. data/features/checkbox.feature +48 -0
  19. data/features/div.feature +45 -0
  20. data/features/element.feature +281 -0
  21. data/features/file_field.feature +38 -0
  22. data/features/form.feature +37 -0
  23. data/features/frames.feature +76 -0
  24. data/features/generic_elements.feature +29 -0
  25. data/features/heading.feature +160 -0
  26. data/features/hidden_field.feature +39 -0
  27. data/features/html/async.html +31 -0
  28. data/features/html/frame_1.html +18 -0
  29. data/features/html/frame_2.html +16 -0
  30. data/features/html/frame_3.html +14 -0
  31. data/features/html/frames.html +12 -0
  32. data/features/html/hover.html +11 -0
  33. data/features/html/iframes.html +12 -0
  34. data/features/html/images/circle.png +0 -0
  35. data/features/html/images/img_pulpit.jpg +0 -0
  36. data/features/html/modal.html +17 -0
  37. data/features/html/modal_1.html +38 -0
  38. data/features/html/modal_2.html +27 -0
  39. data/features/html/multi_elements.html +145 -0
  40. data/features/html/nested_elements.html +75 -0
  41. data/features/html/nested_frame_1.html +1 -0
  42. data/features/html/nested_frame_2.html +11 -0
  43. data/features/html/nested_frame_3.html +14 -0
  44. data/features/html/nested_frames.html +10 -0
  45. data/features/html/planets.gif +0 -0
  46. data/features/html/static_elements.html +203 -0
  47. data/features/html/success.html +8 -0
  48. data/features/html/sun.gif +0 -0
  49. data/features/html/sun.html +7 -0
  50. data/features/image.feature +47 -0
  51. data/features/italic.feature +20 -0
  52. data/features/javascript.feature +28 -0
  53. data/features/label.feature +43 -0
  54. data/features/link.feature +56 -0
  55. data/features/list_item.feature +37 -0
  56. data/features/modal_dialog.feature +9 -0
  57. data/features/multi_elements.feature +498 -0
  58. data/features/nested_elements.feature +121 -0
  59. data/features/ordered_list.feature +46 -0
  60. data/features/page_level_actions.feature +116 -0
  61. data/features/paragraph.feature +33 -0
  62. data/features/populate_page_with.feature +25 -0
  63. data/features/radio_button.feature +51 -0
  64. data/features/radio_button_group.feature +28 -0
  65. data/features/sample-app/public/04-Death_Becomes_Fur.mp4 +0 -0
  66. data/features/sample-app/public/04-Death_Becomes_Fur.oga +0 -0
  67. data/features/sample-app/public/audio_video.html +19 -0
  68. data/features/sample-app/public/jquery-1.3.2.js +4376 -0
  69. data/features/sample-app/public/jquery.html +28 -0
  70. data/features/sample-app/public/movie.mp4 +0 -0
  71. data/features/sample-app/public/movie.ogg +0 -0
  72. data/features/sample-app/public/prototype-1.6.0.3.js +4320 -0
  73. data/features/sample-app/public/prototype.html +32 -0
  74. data/features/sample-app/sample_app.rb +35 -0
  75. data/features/section.feature +132 -0
  76. data/features/select_list.feature +84 -0
  77. data/features/span.feature +43 -0
  78. data/features/step_definations/area_steps.rb +23 -0
  79. data/features/step_definations/async_steps.rb +80 -0
  80. data/features/step_definations/audio_steps.rb +47 -0
  81. data/features/step_definations/bold_steps.rb +11 -0
  82. data/features/step_definations/button_steps.rb +52 -0
  83. data/features/step_definations/canvas_steps.rb +19 -0
  84. data/features/step_definations/checkbox_steps.rb +39 -0
  85. data/features/step_definations/div_steps.rb +28 -0
  86. data/features/step_definations/element_steps.rb +217 -0
  87. data/features/step_definations/file_field_steps.rb +31 -0
  88. data/features/step_definations/form_steps.rb +23 -0
  89. data/features/step_definations/frame_steps.rb +189 -0
  90. data/features/step_definations/generic_element_steps.rb +31 -0
  91. data/features/step_definations/heading_steps.rb +39 -0
  92. data/features/step_definations/hidden_field_steps.rb +27 -0
  93. data/features/step_definations/image_steps.rb +35 -0
  94. data/features/step_definations/italic_steps.rb +11 -0
  95. data/features/step_definations/javasript_steps.rb +52 -0
  96. data/features/step_definations/label_steps.rb +19 -0
  97. data/features/step_definations/link_steps.rb +42 -0
  98. data/features/step_definations/list_item_steps.rb +24 -0
  99. data/features/step_definations/modal_dialog_steps.rb +38 -0
  100. data/features/step_definations/multi_elements_steps.rb +557 -0
  101. data/features/step_definations/nested_elements_steps.rb +219 -0
  102. data/features/step_definations/ordered_list_steps.rb +49 -0
  103. data/features/step_definations/page_level_actions_steps.rb +172 -0
  104. data/features/step_definations/page_traversal_steps.rb +4 -0
  105. data/features/step_definations/paragraph_steps.rb +19 -0
  106. data/features/step_definations/populate_page_with_steps.rb +3 -0
  107. data/features/step_definations/radio_button_group_steps.rb +32 -0
  108. data/features/step_definations/radio_button_steps.rb +31 -0
  109. data/features/step_definations/section_steps.rb +271 -0
  110. data/features/step_definations/select_list_steps.rb +91 -0
  111. data/features/step_definations/span_steps.rb +23 -0
  112. data/features/step_definations/table_cell_steps.rb +27 -0
  113. data/features/step_definations/table_row_steps.rb +23 -0
  114. data/features/step_definations/table_steps.rb +109 -0
  115. data/features/step_definations/text_area_steps.rb +39 -0
  116. data/features/step_definations/text_field_steps.rb +39 -0
  117. data/features/step_definations/unordered_list_steps.rb +27 -0
  118. data/features/step_definations/video_steps.rb +27 -0
  119. data/features/support/ajax_test_environment.rb +26 -0
  120. data/features/support/audio_video_page.rb +23 -0
  121. data/features/support/env.rb +5 -0
  122. data/features/support/hooks.rb +3 -0
  123. data/features/support/page.rb +372 -0
  124. data/features/support/persistent_browser.rb +58 -0
  125. data/features/support/targets/firefox14_osx.rb +5 -0
  126. data/features/support/targets/firefox14_windows7.rb +5 -0
  127. data/features/support/url_helper.rb +50 -0
  128. data/features/table.feature +127 -0
  129. data/features/table_cell.feature +42 -0
  130. data/features/table_row.feature +30 -0
  131. data/features/text_area.feature +44 -0
  132. data/features/text_field.feature +53 -0
  133. data/features/unordered_list.feature +46 -0
  134. data/features/video.feature +66 -0
  135. data/lib/druid/accessors.rb +1082 -0
  136. data/lib/druid/assist.rb +653 -0
  137. data/lib/druid/element_locators.rb +21 -0
  138. data/lib/druid/elements/area.rb +9 -0
  139. data/lib/druid/elements/audio.rb +9 -0
  140. data/lib/druid/elements/bold.rb +8 -0
  141. data/lib/druid/elements/button.rb +12 -0
  142. data/lib/druid/elements/canvas.rb +9 -0
  143. data/lib/druid/elements/check_box.rb +9 -0
  144. data/lib/druid/elements/div.rb +9 -0
  145. data/lib/druid/elements/element.rb +187 -0
  146. data/lib/druid/elements/file_field.rb +9 -0
  147. data/lib/druid/elements/form.rb +9 -0
  148. data/lib/druid/elements/heading.rb +14 -0
  149. data/lib/druid/elements/hidden_field.rb +9 -0
  150. data/lib/druid/elements/image.rb +9 -0
  151. data/lib/druid/elements/italic.rb +9 -0
  152. data/lib/druid/elements/label.rb +8 -0
  153. data/lib/druid/elements/link.rb +9 -0
  154. data/lib/druid/elements/list_item.rb +9 -0
  155. data/lib/druid/elements/media.rb +11 -0
  156. data/lib/druid/elements/option.rb +9 -0
  157. data/lib/druid/elements/ordered_list.rb +29 -0
  158. data/lib/druid/elements/paragraph.rb +9 -0
  159. data/lib/druid/elements/radio_button.rb +9 -0
  160. data/lib/druid/elements/select_list.rb +30 -0
  161. data/lib/druid/elements/span.rb +9 -0
  162. data/lib/druid/elements/table.rb +92 -0
  163. data/lib/druid/elements/table_cell.rb +11 -0
  164. data/lib/druid/elements/table_row.rb +50 -0
  165. data/lib/druid/elements/text_area.rb +10 -0
  166. data/lib/druid/elements/text_field.rb +11 -0
  167. data/lib/druid/elements/unordered_list.rb +32 -0
  168. data/lib/druid/elements/video.rb +8 -0
  169. data/lib/druid/elements.rb +55 -0
  170. data/lib/druid/javascript/angularjs.rb +12 -0
  171. data/lib/druid/javascript/jquery.rb +12 -0
  172. data/lib/druid/javascript/prototype.rb +12 -0
  173. data/lib/druid/javascript/yui.rb +19 -0
  174. data/lib/druid/javascript_framework_facade.rb +76 -0
  175. data/lib/druid/locator_generator.rb +181 -0
  176. data/lib/druid/nested_elements.rb +56 -0
  177. data/lib/druid/page_factory.rb +115 -0
  178. data/lib/druid/page_populator.rb +104 -0
  179. data/lib/druid/section_collection.rb +17 -0
  180. data/lib/druid/version.rb +3 -0
  181. data/lib/druid.rb +452 -0
  182. data/spec/druid/accessors_spec.rb +1209 -0
  183. data/spec/druid/druid_spec.rb +295 -0
  184. data/spec/druid/element_locators_spec.rb +750 -0
  185. data/spec/druid/elements/bold_spec.rb +12 -0
  186. data/spec/druid/elements/button_spec.rb +23 -0
  187. data/spec/druid/elements/check_box_spec.rb +14 -0
  188. data/spec/druid/elements/div_spec.rb +10 -0
  189. data/spec/druid/elements/element_spec.rb +250 -0
  190. data/spec/druid/elements/file_field_spec.rb +13 -0
  191. data/spec/druid/elements/form_spec.rb +18 -0
  192. data/spec/druid/elements/heading_spec.rb +30 -0
  193. data/spec/druid/elements/hidden_field_spec.rb +10 -0
  194. data/spec/druid/elements/image_spec.rb +23 -0
  195. data/spec/druid/elements/itatic_spec.rb +11 -0
  196. data/spec/druid/elements/label_spec.rb +10 -0
  197. data/spec/druid/elements/link_spec.rb +10 -0
  198. data/spec/druid/elements/list_item_spec.rb +10 -0
  199. data/spec/druid/elements/media_spec.rb +12 -0
  200. data/spec/druid/elements/option_spec.rb +21 -0
  201. data/spec/druid/elements/ordered_list_spec.rb +38 -0
  202. data/spec/druid/elements/page_factory_spec.rb +40 -0
  203. data/spec/druid/elements/paragraph_spec.rb +12 -0
  204. data/spec/druid/elements/radio_button_spec.rb +14 -0
  205. data/spec/druid/elements/select_list_spec.rb +51 -0
  206. data/spec/druid/elements/span_spec.rb +10 -0
  207. data/spec/druid/elements/table_cell_spec.rb +14 -0
  208. data/spec/druid/elements/table_row_spec.rb +34 -0
  209. data/spec/druid/elements/table_spec.rb +47 -0
  210. data/spec/druid/elements/text_area_spec.rb +13 -0
  211. data/spec/druid/elements/text_field_spec.rb +22 -0
  212. data/spec/druid/elements/unordered_list_spec.rb +39 -0
  213. data/spec/druid/javascript_framework_facade_spec.rb +59 -0
  214. data/spec/druid/nested_element_spec.rb +128 -0
  215. data/spec/druid/page_factory_spec.rb +235 -0
  216. data/spec/druid/page_populator_spec.rb +173 -0
  217. data/spec/druid/page_section_spec.rb +70 -0
  218. data/spec/spec_helper.rb +9 -0
  219. metadata +517 -0
@@ -0,0 +1,653 @@
1
+ module Druid
2
+ module Assist
3
+ def click_link_for identifier
4
+ process_call("link(identifier).click if identifier", Elements::Link, identifier)
5
+ end
6
+
7
+ def link_for identifier
8
+ find_element("link(identifier)", Elements::Link, identifier)
9
+ end
10
+
11
+ #
12
+ # retrieve all link elements
13
+ #
14
+ def links_for identifier
15
+ find_elements("links(identifier)", Elements::Link, identifier)
16
+ end
17
+
18
+ def text_field_for identifier
19
+ find_element("text_field(identifier)", Elements::TextField, identifier)
20
+ end
21
+
22
+ #
23
+ # retrieve an array of hidden field elements
24
+ #
25
+ def text_fields_for(identifier)
26
+ elements = find_elements("text_fields(identifier)", Elements::TextField, identifier)
27
+ elements.select {|e| e.element.tag_name == "input"}
28
+ end
29
+
30
+ def text_field_value_for identifier
31
+ process_call("text_field(identifier).value", Elements::TextField, identifier)
32
+ end
33
+
34
+ def text_field_value_set identifier, value
35
+ process_call("text_field(identifier).set(value)", Elements::TextField, identifier, value)
36
+ end
37
+
38
+ def check_checkbox identifier
39
+ process_call("checkbox(identifier).set", Elements::CheckBox, identifier)
40
+ end
41
+
42
+ def uncheck_checkbox identifier
43
+ process_call("checkbox(identifier).clear", Elements::CheckBox, identifier)
44
+ end
45
+
46
+ def checkbox_checked? identifier
47
+ process_call("checkbox(identifier).set?", Elements::CheckBox, identifier)
48
+ end
49
+
50
+ def checkbox_for identifier
51
+ find_element("checkbox(identifier)", Elements::CheckBox, identifier)
52
+ end
53
+
54
+ #
55
+ # retrieve an array of checkbox elements
56
+
57
+ def checkboxs_for identifier
58
+ find_elements("checkboxes(identifier)", Elements::CheckBox, identifier)
59
+ end
60
+
61
+ def select_list_value_set identifier, value
62
+ process_call("select_list(identifier).select(value)", Elements::SelectList, identifier, value)
63
+ end
64
+
65
+ def select_list_value_for identifier
66
+ options = process_call("select_list(identifier).selected_options", Elements::SelectList, identifier)
67
+ return nil if options.empty?
68
+ options.first.text
69
+ end
70
+
71
+ def select_list_for identifier
72
+ find_element("select_list(identifier)", Elements::SelectList, identifier)
73
+ end
74
+
75
+ #
76
+ # retrieve an array of select_list elements
77
+ #
78
+ def select_lists_for identifier
79
+ find_elements("select_lists(identifier)", Elements::SelectList, identifier)
80
+ end
81
+
82
+ def select_radio identifier
83
+ process_call("radio(identifier).set", Elements::RadioButton, identifier)
84
+ end
85
+
86
+ def radio_selected? identifier
87
+ process_call("radio(identifier).set?", Elements::RadioButton, identifier)
88
+ end
89
+
90
+ def radio_button_for identifier
91
+ find_element("radio(identifier)", Elements::RadioButton, identifier)
92
+ end
93
+
94
+ #
95
+ # retrieve an array of radio button elements
96
+ def radio_buttons_for identifier
97
+ find_elements("radios(identifier)", Elements::RadioButton, identifier)
98
+ end
99
+
100
+ def click_button_for identifier
101
+ process_call("button(identifier).click", Elements::Button, identifier)
102
+ end
103
+
104
+ def button_for identifier
105
+ find_element("button(identifier)", Elements::Button, identifier)
106
+ end
107
+
108
+ #
109
+ # retrieve an array of button elements
110
+ #
111
+ def buttons_for(identifier)
112
+ find_elements("buttons(identifier)", Elements::Button, identifier)
113
+ end
114
+
115
+ def div_text_for identifier
116
+ process_call("div(identifier).text", Elements::Div, identifier, nil, 'div')
117
+ end
118
+
119
+ def div_for identifier
120
+ find_element("div(identifier)", Elements::Div, identifier, 'div')
121
+ end
122
+
123
+ #
124
+ # retrieve an array of div elements
125
+ #
126
+ def divs_for identifier
127
+ find_elements("divs(identifier)", Elements::Div, identifier, 'div')
128
+ end
129
+
130
+ #
131
+ # method to return the text for a table
132
+ #
133
+ def table_text_for(identifier)
134
+ process_call("table(identifier).text", Elements::Table, identifier, nil, 'table')
135
+ end
136
+
137
+ def table_for identifier
138
+ find_element("table(identifier)", Elements::Table, identifier, 'table')
139
+ end
140
+
141
+ #
142
+ # retrieve an array of table elements
143
+ #
144
+ def tables_for identifier
145
+ find_elements("tables(identifier)", Elements::Table, identifier, 'table')
146
+ end
147
+
148
+ def cell_text_for identifier
149
+ process_call("td(identifier).text", Elements::TableCell, identifier, nil, 'td')
150
+ end
151
+
152
+ def cell_for identifier
153
+ find_element("td(identifier)", Elements::TableCell, identifier, 'td')
154
+ end
155
+
156
+ #
157
+ # retrieve an array of cell elements
158
+ #
159
+ def cells_for identifier
160
+ find_elements("tds(identifier)", Elements::TableCell, identifier, 'td')
161
+ end
162
+
163
+ def span_text_for identifier
164
+ process_call("span(identifier).text", Elements::Span, identifier, nil, 'span')
165
+ end
166
+
167
+ def span_for identifier
168
+ find_element("span(identifier)", Elements::Span, identifier, 'span')
169
+ end
170
+
171
+ #
172
+ # retrieve an array of span elements
173
+ #
174
+ def spans_for identifier
175
+ find_elements("spans(identifier)", Elements::Span, identifier, 'span')
176
+ end
177
+
178
+ def image_for identifier
179
+ find_element("image(identifier)", Elements::Image, identifier)
180
+ end
181
+
182
+ #
183
+ # retrieve an array of image elements
184
+ #
185
+ def images_for identifier
186
+ find_elements("images(identifier)", Elements::Image, identifier)
187
+ end
188
+
189
+ #
190
+ # method to retrieve load status of an image element
191
+ #
192
+ def image_loaded_for(identifier)
193
+ process_call("image(identifier).loaded?", Elements::Image, identifier)
194
+ end
195
+
196
+ def form_for identifier
197
+ find_element("form(identifier)", Elements::Form, identifier)
198
+ end
199
+
200
+ #
201
+ # retrieve an array of form elements
202
+ #
203
+ def forms_for identifier
204
+ find_elements("forms(identifier)", Elements::Form, identifier)
205
+ end
206
+
207
+ def hidden_field_value_for identifier
208
+ process_call("hidden(identifier).value", Elements::HiddenField, identifier)
209
+ end
210
+
211
+ def hidden_field_for identifier
212
+ find_element("hidden(identifier)", Elements::HiddenField, identifier)
213
+ end
214
+
215
+ #
216
+ # retrieve an array of hidden_field elements
217
+ #
218
+ def hidden_fields_for identifier
219
+ find_elements("hiddens(identifier)", Elements::HiddenField, identifier)
220
+ end
221
+
222
+ def list_item_text_for identifier
223
+ process_call("li(identifier).text", Elements::ListItem, identifier, nil, 'li')
224
+ end
225
+
226
+ def list_item_for identifier
227
+ find_element("li(identifier)", Elements::ListItem, identifier, 'li')
228
+ end
229
+
230
+ #
231
+ # retrieve an array of list_item elements
232
+ #
233
+ def list_items_for identifier
234
+ find_elements("lis(identifier)", Elements::ListItem, identifier, 'li')
235
+ end
236
+
237
+ #
238
+ # method to retrieve the text from an ordered list
239
+ #
240
+ def ordered_list_text_for(identifier)
241
+ process_call("ol(identifier).text", Elements::OrderedList, identifier, nil, 'ol')
242
+ end
243
+
244
+ def ordered_list_for identifier
245
+ find_element("ol(identifier)", Elements::OrderedList, identifier, 'ol')
246
+ end
247
+
248
+ #
249
+ # retrieve an array of ordered_list elements
250
+ #
251
+ def ordered_lists_for identifier
252
+ find_elements("ols(identifier)", Elements::OrderedList, identifier, 'ol')
253
+ end
254
+
255
+ def text_area_value_set identifier, value
256
+ process_call("textarea(identifier).set(value)", Elements::TextArea, identifier, value)
257
+ end
258
+
259
+ def text_area_value_for identifier
260
+ process_call("textarea(identifier).value", Elements::TextArea, identifier)
261
+ end
262
+
263
+ def text_area_for identifier
264
+ find_element("textarea(identifier)", Elements::TextArea, identifier)
265
+ end
266
+ #
267
+ # retrieve an array of textarea elements
268
+ def text_areas_for identifier
269
+ find_elements("textareas(identifier)", Elements::TextArea, identifier)
270
+ end
271
+
272
+ #
273
+ # method to retrieve the text from an unordered list
274
+ #
275
+ def unordered_list_text_for(identifier)
276
+ process_call("ul(identifier).text", Elements::UnOrderedList, identifier, nil, 'ul')
277
+ end
278
+
279
+ def unordered_list_for identifier
280
+ find_element("ul(identifier)", Elements::UnOrderedList, identifier, 'ul')
281
+ end
282
+
283
+ #
284
+ # retrieve an array of unordered_lists elements
285
+ #
286
+ def unordered_lists_for identifier
287
+ find_elements("uls(identifier)", Elements::UnOrderedList, identifier, 'ul')
288
+ end
289
+
290
+ def h1_text_for identifier
291
+ process_call("h1(identifier).text", Elements::Heading, identifier, nil, 'h1')
292
+ end
293
+
294
+ def h1_for identifier
295
+ find_element("h1(identifier)", Elements::Heading, identifier, 'h1')
296
+ end
297
+
298
+ #
299
+ # retrieve an array of h1 elements
300
+ #
301
+ def h1s_for identifier
302
+ find_elements("h1s(identifier)", Elements::Heading, identifier, 'h1')
303
+ end
304
+
305
+ def h2_text_for identifier
306
+ process_call("h2(identifier).text", Elements::Heading, identifier, nil, 'h2')
307
+ end
308
+
309
+ def h2_for identifier
310
+ find_element("h2(identifier)", Elements::Heading, identifier, 'h2')
311
+ end
312
+
313
+ #
314
+ # retrieve an array of h2 elements
315
+ #
316
+ def h2s_for identifier
317
+ find_elements("h2s(identifier)", Elements::Heading, identifier, 'h2')
318
+ end
319
+
320
+ def h3_text_for identifier
321
+ process_call("h3(identifier).text", Elements::Heading, identifier, nil, 'h3')
322
+ end
323
+
324
+ def h3_for identifier
325
+ find_element("h3(identifier)", Elements::Heading, identifier, 'h3')
326
+ end
327
+
328
+ #
329
+ # retrieve an array of h3 elements
330
+ #
331
+ def h3s_for identifier
332
+ find_elements("h3s(identifier)", Elements::Heading, identifier, 'h3')
333
+ end
334
+
335
+ def h4_text_for identifier
336
+ process_call("h4(identifier).text", Elements::Heading, identifier, nil, 'h4')
337
+ end
338
+
339
+ def h4_for identifier
340
+ find_element("h4(identifier)", Elements::Heading, identifier, 'h4')
341
+ end
342
+
343
+ #
344
+ # retrieve an array of h4 elements
345
+ #
346
+ def h4s_for identifier
347
+ find_elements("h4s(identifier)", Elements::Heading, identifier, 'h4')
348
+ end
349
+
350
+ def h5_text_for identifier
351
+ process_call("h5(identifier).text", Elements::Heading, identifier, nil, 'h5')
352
+ end
353
+
354
+ def h5_for identifier
355
+ find_element("h5(identifier)", Elements::Heading, identifier, 'h5')
356
+ end
357
+
358
+ #
359
+ # retrieve an array of h5 elements
360
+ #
361
+ def h5s_for identifier
362
+ find_elements("h5s(identifier)", Elements::Heading, identifier, 'h5')
363
+ end
364
+
365
+ def h6_text_for identifier
366
+ process_call("h6(identifier).text", Elements::Heading, identifier, nil, 'h6')
367
+ end
368
+
369
+ def h6_for identifier
370
+ find_element("h6(identifier)", Elements::Heading, identifier, 'h6')
371
+ end
372
+
373
+ #
374
+ # retrieve an array of h6 elements
375
+ #
376
+ def h6s_for identifier
377
+ find_elements("h6s(identifier)", Elements::Heading, identifier, 'h6')
378
+ end
379
+
380
+ def paragraph_text_for identifier
381
+ process_call("p(identifier).text", Elements::Paragraph, identifier, nil, 'p')
382
+ end
383
+
384
+ def paragraph_for identifier
385
+ find_element("p(identifier)", Elements::Paragraph, identifier, 'p')
386
+ end
387
+
388
+ #
389
+ # retrieve an array of paragraph Elements
390
+ #
391
+ def paragraphs_for identifier
392
+ find_elements("ps(identifier)", Elements::Paragraph, identifier, 'p')
393
+ end
394
+
395
+ def file_field_value_set identifier, value
396
+ process_call("file_field(identifier).set(value)", Elements::FileField, identifier, value)
397
+ end
398
+
399
+ def file_field_for identifier
400
+ find_element("file_field(identifier)", Elements::FileField, identifier)
401
+ end
402
+
403
+ #
404
+ # retrieve an array of file field elements
405
+ #
406
+ def file_fields_for identifier
407
+ find_elements("file_fields(identifier)", Elements::FileField, identifier)
408
+ end
409
+
410
+ #
411
+ # method to return the text for a label
412
+ #
413
+ def label_text_for(identifier)
414
+ process_call("label(identifier).text", Elements::Label, identifier, nil, 'label')
415
+ end
416
+
417
+ #
418
+ # method to return a Druid::Elements::Label element
419
+ #
420
+ def label_for(identifier)
421
+ find_element("label(identifier)", Elements::Label, identifier, 'label')
422
+ end
423
+
424
+ #
425
+ # method to retrieve an array of label elements
426
+ #
427
+ def labels_for(identifier)
428
+ find_elements("labels(identifier)", Elements::Label, identifier, 'p')
429
+ end
430
+
431
+ #
432
+ # method to click on an area
433
+ #
434
+ def click_area_for(identifier)
435
+ process_call("area(identifier).click", Elements::Area, identifier, nil, 'area')
436
+ end
437
+
438
+ #
439
+ # method to retrieve an area element
440
+ #
441
+ def area_for(identifier)
442
+ find_element("area(identifier)", Elements::Area, identifier, 'area')
443
+ end
444
+
445
+ #
446
+ # method to retrieve an array of area elements
447
+ #
448
+ def areas_for(identifier)
449
+ find_elements("areas(identifier)", Elements::Area, identifier, 'area')
450
+ end
451
+
452
+ #
453
+ # method to retrieve a canvas element
454
+ #
455
+ def canvas_for(identifier)
456
+ find_element("canvas(identifier)", Elements::Canvas, identifier, 'canvas')
457
+ end
458
+
459
+ #
460
+ # method to retrieve an array of canvas elements
461
+ #
462
+ def canvass_for(identifier)
463
+ find_elements("canvases(identifier)", Elements::Canvas, identifier, 'canvas')
464
+ end
465
+
466
+ #
467
+ # method to retrieve an audio element
468
+ #
469
+ def audio_for(identifier)
470
+ find_element("audio(identifier)", Elements::Audio, identifier, 'audio')
471
+ end
472
+
473
+ #
474
+ # method to retrieve an array of audio elements
475
+ #
476
+ def audios_for(identifier)
477
+ find_elements("audios(identifier)", Elements::Audio, identifier, 'audio')
478
+ end
479
+
480
+ #
481
+ # method to retrieve an video element
482
+ #
483
+ def video_for(identifier)
484
+ find_element("video(identifier)", Elements::Video, identifier, 'video')
485
+ end
486
+
487
+ #
488
+ # method to retrieve an array of audio elements
489
+ #
490
+ def videos_for(identifier)
491
+ find_elements("videos(identifier)", Elements::Video, identifier, 'video')
492
+ end
493
+
494
+ #
495
+ # method to retrieve the text from a table row_text_for
496
+ #
497
+ def row_text_for(identifier)
498
+ process_call("tr(identifier).text", Elements::TableRow, identifier, nil, 'tr')
499
+ end
500
+
501
+ def row_for(identifier)
502
+ find_element("tr(identifier)", Elements::TableRow, identifier, 'tr')
503
+ end
504
+
505
+ def rows_for(identifier)
506
+ find_elements("trs(identifier)", Elements::TableRow, identifier, 'tr')
507
+ end
508
+
509
+ def element_for(tag, identifier)
510
+ find_element("#{tag.to_s}(identifier)", Elements::Element, identifier, tag.to_s)
511
+ end
512
+
513
+ def elements_for(tag, identifier)
514
+ find_elements("#{tag.to_s}s(identifier)", Elements::Element, identifier, tag.to_s)
515
+ end
516
+
517
+ #
518
+ # method to return a svg element
519
+ #
520
+ def svg_for(identifier)
521
+ find_element("element(identifier)", Elements::Element, identifier)
522
+ end
523
+
524
+ #
525
+ # method to return an array of svg elements
526
+ #
527
+ def svgs_for(identifier)
528
+ find_elements("element(identifier)", Elements::Element, identifier)
529
+ end
530
+
531
+ #
532
+ # method to retrieve the text for a b
533
+ #
534
+ def b_text_for(identifier)
535
+ process_call("b(identifier).text", Elements::Bold, identifier, nil, 'b')
536
+ end
537
+
538
+ #
539
+ # method to retrieve the b element
540
+ #
541
+ def b_for(identifier)
542
+ find_element("b(identifier)", Elements::Bold, identifier, 'b')
543
+ end
544
+
545
+ #
546
+ # method to retrieve all b elements
547
+ #
548
+ def bs_for(identifier)
549
+ find_elements("bs(identifier)", Elements::Bold, identifier, 'b')
550
+ end
551
+
552
+ #
553
+ # method to retrieve the text for a i
554
+ #
555
+ def i_text_for(identifier)
556
+ process_call("i(identifier).text", Elements::Italic, identifier, nil, 'i')
557
+ end
558
+
559
+ #
560
+ # method to retrieve the i element
561
+ #
562
+ def i_for(identifier)
563
+ find_element("i(identifier)", Elements::Italic, identifier, 'i')
564
+ end
565
+
566
+ #
567
+ # method to retrieve all i elements
568
+ #
569
+ def is_for(identifier)
570
+ find_elements("is(identifier)", Elements::Italic, identifier, 'i')
571
+ end
572
+
573
+ #
574
+ # method to return a Druid rooted at an element
575
+ #
576
+ def page_for(identifier, section_class)
577
+ find_page(identifier, section_class)
578
+ end
579
+
580
+ #
581
+ # method to return a collection of Druids rooted at elements
582
+ #
583
+ def pages_for(identifier, section_class)
584
+ SectionCollection[*find_pages(identifier, section_class)]
585
+ end
586
+
587
+ private
588
+
589
+ def find_elements(the_call, type, identifier, tag_name=nil)
590
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
591
+ elements = driver.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
592
+ switch_to_default_content(frame_identifiers)
593
+ elements.map { |element| type.new(element) }
594
+ end
595
+
596
+ def find_element(the_call, type, identifier, tag_name=nil)
597
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
598
+ element = driver.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
599
+ switch_to_default_content(frame_identifiers)
600
+ type.new(element)
601
+ end
602
+
603
+ def find_pages(identifier, section_class)
604
+ identifier, frame_identifiers = parse_identifiers(identifier, Elements::Element, 'element')
605
+ elements = driver.instance_eval "#{nested_frames(frame_identifiers)}elements(identifier)"
606
+ switch_to_default_content(frame_identifiers)
607
+ elements.map { |element| section_class.new(element) }
608
+ end
609
+
610
+ def find_page(identifier, section_class)
611
+ identifier, frame_identifiers = parse_identifiers(identifier, Elements::Element, 'element')
612
+ element = driver.instance_eval "#{nested_frames(frame_identifiers)}element(identifier)"
613
+ switch_to_default_content(frame_identifiers)
614
+ section_class.new(element)
615
+ end
616
+
617
+ def process_call(the_call, type, identifier, value=nil, tag_name=nil)
618
+ identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
619
+ value = driver.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
620
+ switch_to_default_content(frame_identifiers)
621
+ value
622
+ end
623
+
624
+ def parse_identifiers(identifier, element, tag_name=nil)
625
+ new_identifiers = identifier.dup
626
+ frame_identifiers = new_identifiers.delete(:frame)
627
+ return new_identifiers, frame_identifiers
628
+ end
629
+
630
+ def nested_frames(frame_identifiers)
631
+ return if frame_identifiers.nil?
632
+ frame_str = ''
633
+ frame_identifiers.each do |frame|
634
+ type = frame.keys.first
635
+ identifier = frame.values.first.map do |key, value|
636
+ if value.is_a?(Regexp)
637
+ ":#{key} => #{value.inspect}"
638
+ elsif value.is_a? Integer
639
+ ":#{key} => #{value}"
640
+ else
641
+ ":#{key} => '#{value}'"
642
+ end
643
+ end.join(', ')
644
+ frame_str +="#{type.to_s}(#{identifier})."
645
+ end
646
+ frame_str
647
+ end
648
+
649
+ def switch_to_default_content(frame_identifiers)
650
+ driver.browser.wd.switch_to.default_content unless frame_identifiers.nil?
651
+ end
652
+ end
653
+ end
@@ -0,0 +1,21 @@
1
+ require 'druid/locator_generator'
2
+
3
+ module Druid
4
+ module ElementLocators
5
+
6
+ def self.included(cls)
7
+ Druid::LocatorGenerator.generate_locators(cls)
8
+ end
9
+
10
+ def element(tag, identifier={:index => 0})
11
+ element_for(tag, identifier.clone)
12
+ end
13
+
14
+ private
15
+
16
+ def locator(identifier)
17
+ identifier[0] ? identifier[0] : {:index => 0}
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module Druid
2
+ module Elements
3
+ class Area < Element
4
+
5
+ end
6
+
7
+ Druid::Elements.type_to_class[:area] = Druid::Elements::Area
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Druid
2
+ module Elements
3
+ class Audio < Media
4
+
5
+ end
6
+
7
+ Druid::Elements.type_to_class[:audio] = Druid::Elements::Audio
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Druid
2
+ module Elements
3
+ class Bold < Element
4
+
5
+ end
6
+ Druid::Elements.tag_to_class[:b] = Druid::Elements::Bold
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ module Druid
2
+ module Elements
3
+ class Button < Element
4
+
5
+ end
6
+
7
+ Druid::Elements.type_to_class[:submit] = Druid::Elements::Button
8
+ Druid::Elements.type_to_class[:image] = Druid::Elements::Button
9
+ Druid::Elements.type_to_class[:button] = Druid::Elements::Button
10
+ Druid::Elements.type_to_class[:reset] = Druid::Elements::Button
11
+ end
12
+ end