page_object 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
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,5 @@
1
+ class String
2
+ def is_integer
3
+ true if Integer(self) rescue false
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ require 'page-object/locator_generator'
2
+
3
+ module PageObject
4
+ module ElementLocators
5
+
6
+ def self.included(cls)
7
+ ::PageObject::LocatorGenerator.generate_locators(cls)
8
+ end
9
+
10
+ def element(tag, identifier={:index => 0})
11
+ platform.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,60 @@
1
+ module PageObject
2
+ module Elements
3
+ class << self
4
+
5
+ #
6
+ # method to return the collection of tag_name to class mappings
7
+ #
8
+ def tag_to_class
9
+ @tag_to_class ||= {}
10
+ end
11
+
12
+ def type_to_class
13
+ @type_to_class ||= {}
14
+ end
15
+
16
+ #
17
+ # method to return the element for a tag_name
18
+ #
19
+ def element_class_for(tag_name, type=nil)
20
+ return type_to_class[type.to_sym] if type
21
+ tag_to_class[tag_name.to_sym] || ::PageObject::Elements::Element
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ require 'page-object/elements/element'
30
+ require 'page-object/elements/link'
31
+ require 'page-object/elements/text_field'
32
+ require 'page-object/elements/select_list'
33
+ require 'page-object/elements/check_box'
34
+ require 'page-object/elements/button'
35
+ require 'page-object/elements/radio_button'
36
+ require 'page-object/elements/div'
37
+ require 'page-object/elements/table'
38
+ require 'page-object/elements/table_cell'
39
+ require 'page-object/elements/table_row'
40
+ require 'page-object/elements/span'
41
+ require 'page-object/elements/image'
42
+ require 'page-object/elements/hidden_field'
43
+ require 'page-object/elements/form'
44
+ require 'page-object/elements/text_area'
45
+ require 'page-object/elements/list_item'
46
+ require 'page-object/elements/unordered_list'
47
+ require 'page-object/elements/ordered_list'
48
+ require 'page-object/elements/option'
49
+ require 'page-object/elements/heading'
50
+ require 'page-object/elements/paragraph'
51
+ require 'page-object/elements/label'
52
+ require 'page-object/elements/file_field'
53
+ require 'page-object/elements/area'
54
+ require 'page-object/elements/canvas'
55
+ require 'page-object/elements/media'
56
+ require 'page-object/elements/audio'
57
+ require 'page-object/elements/video'
58
+ require 'page-object/elements/bold'
59
+
60
+
@@ -0,0 +1,31 @@
1
+
2
+ module PageObject
3
+ module Elements
4
+ class Area < Element
5
+
6
+ #
7
+ # return the coordinates of the area
8
+ #
9
+ def coords
10
+ attribute(:coords)
11
+ end
12
+
13
+ #
14
+ # return the shape of the area
15
+ #
16
+ def shape
17
+ attribute(:shape)
18
+ end
19
+
20
+ #
21
+ # return the href of the area
22
+ #
23
+ def href
24
+ attribute(:href)
25
+ end
26
+
27
+ end
28
+
29
+ ::PageObject::Elements.type_to_class[:area] = ::PageObject::Elements::Area
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+
2
+ module PageObject
3
+ module Elements
4
+ class Audio < Media
5
+
6
+ end
7
+ ::PageObject::Elements.type_to_class[:audio] = ::PageObject::Elements::Audio
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module PageObject
2
+ module Elements
3
+ class Bold < Element
4
+
5
+ end
6
+
7
+ ::PageObject::Elements.tag_to_class[:b] = ::PageObject::Elements::Bold
8
+
9
+
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+
2
+ module PageObject
3
+ module Elements
4
+ class Button < Element
5
+
6
+ def initialize(element, platform)
7
+ @element = element
8
+ include_platform_for platform
9
+ end
10
+
11
+ protected
12
+
13
+ def self.watir_finders
14
+ super + [:text, :value, :src, :alt, :css]
15
+ end
16
+
17
+ def self.selenium_finders
18
+ super + [:value, :src, :alt]
19
+ end
20
+
21
+ def include_platform_for platform
22
+ super
23
+ if platform[:platform] == :selenium_webdriver
24
+ require 'page-object/platforms/selenium_webdriver/button'
25
+ self.class.send :include, PageObject::Platforms::SeleniumWebDriver::Button
26
+ end
27
+ end
28
+ end
29
+
30
+ ::PageObject::Elements.type_to_class[:submit] = ::PageObject::Elements::Button
31
+ ::PageObject::Elements.type_to_class[:image] = ::PageObject::Elements::Button
32
+ ::PageObject::Elements.type_to_class[:button] = ::PageObject::Elements::Button
33
+ ::PageObject::Elements.type_to_class[:reset] = ::PageObject::Elements::Button
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module PageObject
3
+ module Elements
4
+ class Canvas < Element
5
+ #
6
+ # return the width of the canvas
7
+ #
8
+ def width
9
+ attribute(:width).to_i
10
+ end
11
+
12
+ #
13
+ # return the height of the canvas
14
+ #
15
+ def height
16
+ attribute(:height).to_i
17
+ end
18
+
19
+ end
20
+ ::PageObject::Elements.type_to_class[:canvas] = ::PageObject::Elements::Canvas
21
+ end
22
+ end
23
+
@@ -0,0 +1,37 @@
1
+ module PageObject
2
+ module Elements
3
+ class CheckBox < Element
4
+
5
+ def initialize(element, platform)
6
+ @element = element
7
+ include_platform_for platform
8
+ end
9
+
10
+ protected
11
+
12
+ def self.watir_finders
13
+ super + [:value, :label]
14
+ end
15
+
16
+ def self.selenium_finders
17
+ super + [:value, :label, :css]
18
+ end
19
+
20
+ def include_platform_for platform
21
+ super
22
+ if platform[:platform] == :watir_webdriver
23
+ require 'page-object/platforms/watir_webdriver/check_box'
24
+ self.class.send :include, PageObject::Platforms::WatirWebDriver::CheckBox
25
+ elsif platform[:platform] == :selenium_webdriver
26
+ require 'page-object/platforms/selenium_webdriver/check_box'
27
+ self.class.send :include, PageObject::Platforms::SeleniumWebDriver::CheckBox
28
+ else
29
+ raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
30
+ end
31
+ end
32
+ end
33
+
34
+ ::PageObject::Elements.type_to_class[:checkbox] = ::PageObject::Elements::CheckBox
35
+
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ module PageObject
2
+ module Elements
3
+ class Div < Element
4
+
5
+ protected
6
+
7
+ def self.watir_finders
8
+ super + [:text, :title]
9
+ end
10
+
11
+ def self.selenium_finders
12
+ super + [:text, :title]
13
+ end
14
+
15
+ end
16
+
17
+ ::PageObject::Elements.tag_to_class[:div] = ::PageObject::Elements::Div
18
+ end
19
+ end
@@ -0,0 +1,226 @@
1
+ require 'page-object/nested_elements'
2
+
3
+ module PageObject
4
+ module Elements
5
+ #
6
+ # Contains functionality that is common across all elements.
7
+ #
8
+ # @see PageObject::Platforms::WatirWebDriver::Element for the Watir version of all common methods
9
+ # @see PageObject::Platforms::SeleniumWebDriver::Element for the Selenium version of all common methods
10
+ #
11
+ class Element
12
+ include ::PageObject::NestedElements
13
+
14
+ attr_reader :element
15
+
16
+ def initialize(element, platform)
17
+ @element = element
18
+ include_platform_for platform
19
+ end
20
+
21
+ #
22
+ # click the element
23
+ #
24
+ def click
25
+ element.click
26
+ end
27
+
28
+
29
+
30
+ #
31
+ # return true if the element is enabled
32
+ #
33
+ def enabled?
34
+ element.enabled?
35
+ end
36
+
37
+ #
38
+ # return true if the element is not enabled
39
+ #
40
+ def disabled?
41
+ not enabled?
42
+ end
43
+
44
+ #
45
+ # get the value of the given CSS property
46
+ #
47
+ def style(property)
48
+ element.style property
49
+ end
50
+
51
+ def inspect
52
+ element.inspect
53
+ end
54
+
55
+ #
56
+ # retrieve the class name for an element
57
+ #
58
+ def class_name
59
+ attribute 'class'
60
+ end
61
+
62
+ #
63
+ # specify plural form of element
64
+ #
65
+ def self.plural_form
66
+ "#{self.to_s.split('::')[-1].
67
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
68
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
69
+ tr("-", "_").
70
+ downcase}s"
71
+ end
72
+
73
+ # @private
74
+ def self.watir_identifier_for identifier
75
+ if should_build_watir_xpath(identifier)
76
+ how = :xpath
77
+ what = build_xpath_for(identifier)
78
+ return how => what
79
+ end
80
+ all_identities = {}
81
+ identifier.each do |key, value|
82
+ each = {key => value}
83
+ ident = identifier_for each, watir_finders, watir_mapping
84
+ all_identities[ident.keys.first] = ident.values.first
85
+ end
86
+ all_identities
87
+ end
88
+
89
+ # @private
90
+ def self.selenium_identifier_for identifier
91
+ if identifier.length == 1
92
+ identifier = identifier_for identifier, selenium_finders, selenium_mapping
93
+ return identifier.keys.first, identifier.values.first
94
+ elsif identifier.length > 1
95
+ how = :xpath
96
+ what = build_xpath_for identifier
97
+ return how, what
98
+ end
99
+ end
100
+
101
+ # @private
102
+ # delegate calls to driver element
103
+ def method_missing(*args, &block)
104
+ m = args.shift
105
+ $stderr.puts "*** DEPRECATION WARNING"
106
+ $stderr.puts "*** You are calling a method named #{m} at #{caller[0]}."
107
+ $stderr.puts "*** This method does not exist in page-object so it is being passed to the driver."
108
+ $stderr.puts "*** This feature will be removed in the near future."
109
+ $stderr.puts "*** Please change your code to call the correct page-object method."
110
+ $stderr.puts "*** If you are using functionality that does not exist in page-object please request it be added."
111
+ begin
112
+ element.send m, *args, &block
113
+ rescue Exception => e
114
+ raise
115
+ end
116
+ end
117
+
118
+ protected
119
+
120
+ def self.should_build_watir_xpath identifier
121
+ ['table', 'span', 'div', 'td', 'li', 'ul', 'ol', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'label', 'area', 'canvas', 'audio', 'video', 'b'].include? identifier[:tag_name] and identifier[:name]
122
+ end
123
+
124
+ def self.build_xpath_for identifier
125
+ tag_locator = identifier.delete(:tag_name)
126
+ idx = identifier.delete(:index)
127
+ if tag_locator == 'input' and identifier[:type] == 'submit'
128
+ identifier.delete(:type)
129
+ btn_ident = identifier.clone
130
+ if btn_ident[:value]
131
+ btn_ident[:text] = btn_ident[:value]
132
+ btn_ident.delete(:value)
133
+ end
134
+ xpath = ".//button"
135
+ xpath << "[#{attribute_expression(btn_ident)}]" unless btn_ident.empty?
136
+ xpath = "(#{xpath})[#{idx+1}]" if idx
137
+ identifier[:type] = %w[button reset submit image]
138
+ xpath << " | .//input"
139
+ else
140
+ xpath = ".//#{tag_locator}"
141
+ end
142
+ xpath << "[#{attribute_expression(identifier)}]" unless identifier.empty?
143
+ xpath = "(#{xpath})[#{idx+1}]" if idx
144
+ xpath
145
+ end
146
+
147
+ def self.attribute_expression(identifier)
148
+ identifier.map do |key, value|
149
+ if value.kind_of?(Array)
150
+ "(" + value.map { |v| equal_pair(key, v) }.join(" or ") + ")"
151
+ else
152
+ equal_pair(key, value)
153
+ end
154
+ end.join(" and ")
155
+ end
156
+
157
+ def self.equal_pair(key, value)
158
+ if key == :label
159
+ "@id=//label[normalize-space()=#{xpath_string(value)}]/@for"
160
+ else
161
+ "#{lhs_for(key)}=#{xpath_string(value)}"
162
+ end
163
+ end
164
+
165
+ def self.lhs_for(key)
166
+ case key
167
+ when :text, 'text'
168
+ 'normalize-space()'
169
+ when :href
170
+ 'normalize-space(@href)'
171
+ else
172
+ "@#{key.to_s.gsub("_", "-")}"
173
+ end
174
+ end
175
+
176
+ def self.xpath_string(value)
177
+ if value.include? "'"
178
+ parts = value.split("'", -1).map { |part| "'#{part}'" }
179
+ string = parts.join(%{,"'",})
180
+ "concat(#{string})"
181
+ else
182
+ "'#{value}'"
183
+ end
184
+ end
185
+
186
+ def self.identifier_for identifier, find_by, find_by_mapping
187
+ how, what = identifier.keys.first, identifier.values.first
188
+ return how => what if find_by.include? how or how == :tag_name
189
+ return find_by_mapping[how] => what if find_by_mapping[how]
190
+ identifier
191
+ end
192
+
193
+ def self.watir_finders
194
+ [:class, :id, :index, :name, :xpath]
195
+ end
196
+
197
+ def self.watir_mapping
198
+ {}
199
+ end
200
+
201
+ def self.selenium_finders
202
+ [:class, :css, :id, :index, :name, :xpath]
203
+ end
204
+
205
+ def self.selenium_mapping
206
+ {}
207
+ end
208
+
209
+ def include_platform_for platform
210
+ if platform[:platform] == :watir_webdriver
211
+ self.class.send :include, ::PageObject::Platforms::WatirWebDriver::Element
212
+ @platform = ::PageObject::Platforms::WatirWebDriver::PageObject.new(@element)
213
+ elsif platform[:platform] == :selenium_webdriver
214
+ self.class.send :include, ::PageObject::Platforms::SeleniumWebDriver::Element
215
+ @platform = ::PageObject::Platforms::SeleniumWebDriver::PageObject.new(@element)
216
+ else
217
+ raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
218
+ end
219
+ end
220
+
221
+ def to_ary
222
+ nil
223
+ end
224
+ end
225
+ end
226
+ end