meeane-page-object 0.1.8

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 (262) 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 +10 -0
  7. data/ChangeLog +790 -0
  8. data/Gemfile +13 -0
  9. data/Guardfile +20 -0
  10. data/LICENSE +20 -0
  11. data/README.md +141 -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/button.feature +87 -0
  18. data/features/canvas.feature +37 -0
  19. data/features/check_box.feature +55 -0
  20. data/features/div.feature +45 -0
  21. data/features/element.feature +322 -0
  22. data/features/file_field.feature +40 -0
  23. data/features/form.feature +43 -0
  24. data/features/frames.feature +75 -0
  25. data/features/generic_elements.feature +29 -0
  26. data/features/gxt_table_extension.feature +24 -0
  27. data/features/headings.feature +97 -0
  28. data/features/hidden_field.feature +45 -0
  29. data/features/html/04-Death_Becomes_Fur.mp4 +0 -0
  30. data/features/html/04-Death_Becomes_Fur.oga +0 -0
  31. data/features/html/async.html +36 -0
  32. data/features/html/double_click.html +13 -0
  33. data/features/html/failure.html +8 -0
  34. data/features/html/frame_1.html +18 -0
  35. data/features/html/frame_2.html +16 -0
  36. data/features/html/frame_3.html +14 -0
  37. data/features/html/frames.html +12 -0
  38. data/features/html/hover.html +12 -0
  39. data/features/html/iframes.html +12 -0
  40. data/features/html/images/circle.png +0 -0
  41. data/features/html/images/img_pulpit.jpg +0 -0
  42. data/features/html/images/submit.gif +0 -0
  43. data/features/html/indexed_property.html +52 -0
  44. data/features/html/modal.html +17 -0
  45. data/features/html/modal_1.html +38 -0
  46. data/features/html/modal_2.html +27 -0
  47. data/features/html/movie.mp4 +0 -0
  48. data/features/html/movie.ogg +0 -0
  49. data/features/html/multi_elements.html +144 -0
  50. data/features/html/nested_elements.html +77 -0
  51. data/features/html/nested_frame_1.html +1 -0
  52. data/features/html/nested_frame_2.html +11 -0
  53. data/features/html/nested_frame_3.html +14 -0
  54. data/features/html/nested_frames.html +10 -0
  55. data/features/html/planets.gif +0 -0
  56. data/features/html/static_elements.html +206 -0
  57. data/features/html/success.html +8 -0
  58. data/features/html/sun.gif +0 -0
  59. data/features/html/sun.html +7 -0
  60. data/features/image.feature +50 -0
  61. data/features/indexed_property.feature +98 -0
  62. data/features/javascript.feature +28 -0
  63. data/features/label.feature +46 -0
  64. data/features/link.feature +52 -0
  65. data/features/list_item.feature +36 -0
  66. data/features/modal_dialog.feature +15 -0
  67. data/features/multi_elements.feature +486 -0
  68. data/features/nested_elements.feature +117 -0
  69. data/features/ordered_list.feature +56 -0
  70. data/features/page_level_actions.feature +90 -0
  71. data/features/paragraph.feature +35 -0
  72. data/features/radio_button.feature +58 -0
  73. data/features/radio_button_group.feature +29 -0
  74. data/features/sample-app/public/jquery-1.3.2.js +4376 -0
  75. data/features/sample-app/public/jquery.html +30 -0
  76. data/features/sample-app/public/prototype-1.6.0.3.js +4320 -0
  77. data/features/sample-app/public/prototype.html +35 -0
  78. data/features/sample-app/sample_app.rb +35 -0
  79. data/features/select_list.feature +86 -0
  80. data/features/span.feature +37 -0
  81. data/features/step_definitions/accessor_steps.rb +60 -0
  82. data/features/step_definitions/area_steps.rb +19 -0
  83. data/features/step_definitions/async_steps.rb +83 -0
  84. data/features/step_definitions/audio_steps.rb +27 -0
  85. data/features/step_definitions/button_steps.rb +43 -0
  86. data/features/step_definitions/canvas_steps.rb +15 -0
  87. data/features/step_definitions/check_box_steps.rb +35 -0
  88. data/features/step_definitions/div_steps.rb +19 -0
  89. data/features/step_definitions/element_steps.rb +266 -0
  90. data/features/step_definitions/file_field_steps.rb +19 -0
  91. data/features/step_definitions/form_steps.rb +19 -0
  92. data/features/step_definitions/frames_steps.rb +159 -0
  93. data/features/step_definitions/generic_element_steps.rb +31 -0
  94. data/features/step_definitions/gxt_table_steps.rb +58 -0
  95. data/features/step_definitions/headings_steps.rb +12 -0
  96. data/features/step_definitions/hidden_field_steps.rb +27 -0
  97. data/features/step_definitions/image_steps.rb +27 -0
  98. data/features/step_definitions/indexed_property_steps.rb +129 -0
  99. data/features/step_definitions/javascript_steps.rb +53 -0
  100. data/features/step_definitions/label_steps.rb +19 -0
  101. data/features/step_definitions/link_steps.rb +40 -0
  102. data/features/step_definitions/list_item_steps.rb +19 -0
  103. data/features/step_definitions/modal_dialog_steps.rb +62 -0
  104. data/features/step_definitions/multi_elements_steps.rb +528 -0
  105. data/features/step_definitions/nested_elements_steps.rb +212 -0
  106. data/features/step_definitions/ordered_list_steps.rb +23 -0
  107. data/features/step_definitions/page_level_actions_steps.rb +135 -0
  108. data/features/step_definitions/page_traversal_steps.rb +4 -0
  109. data/features/step_definitions/paragraph_steps.rb +28 -0
  110. data/features/step_definitions/radio_button_group_steps.rb +36 -0
  111. data/features/step_definitions/radio_button_steps.rb +27 -0
  112. data/features/step_definitions/select_list_steps.rb +65 -0
  113. data/features/step_definitions/span_steps.rb +19 -0
  114. data/features/step_definitions/table_cell_steps.rb +15 -0
  115. data/features/step_definitions/table_steps.rb +66 -0
  116. data/features/step_definitions/text_area_steps.rb +35 -0
  117. data/features/step_definitions/text_field_steps.rb +35 -0
  118. data/features/step_definitions/unordered_list_steps.rb +23 -0
  119. data/features/step_definitions/video_steps.rb +45 -0
  120. data/features/support/ajax_text_environment.rb +26 -0
  121. data/features/support/env.rb +8 -0
  122. data/features/support/hooks.rb +8 -0
  123. data/features/support/page.rb +364 -0
  124. data/features/support/persistent_browser.rb +70 -0
  125. data/features/support/targets/firefox14_osx.rb +6 -0
  126. data/features/support/targets/firefox14_windows7.rb +6 -0
  127. data/features/support/url_helper.rb +57 -0
  128. data/features/table.feature +114 -0
  129. data/features/table_cell.feature +45 -0
  130. data/features/text_area.feature +51 -0
  131. data/features/text_field.feature +70 -0
  132. data/features/unordered_list.feature +56 -0
  133. data/features/video.feature +73 -0
  134. data/lib/page-object/accessors.rb +1313 -0
  135. data/lib/page-object/core_ext/string.rb +5 -0
  136. data/lib/page-object/element_locators.rb +21 -0
  137. data/lib/page-object/elements/area.rb +31 -0
  138. data/lib/page-object/elements/audio.rb +9 -0
  139. data/lib/page-object/elements/button.rb +35 -0
  140. data/lib/page-object/elements/canvas.rb +23 -0
  141. data/lib/page-object/elements/check_box.rb +37 -0
  142. data/lib/page-object/elements/div.rb +19 -0
  143. data/lib/page-object/elements/element.rb +226 -0
  144. data/lib/page-object/elements/file_field.rb +38 -0
  145. data/lib/page-object/elements/form.rb +36 -0
  146. data/lib/page-object/elements/heading.rb +15 -0
  147. data/lib/page-object/elements/hidden_field.rb +22 -0
  148. data/lib/page-object/elements/image.rb +36 -0
  149. data/lib/page-object/elements/label.rb +36 -0
  150. data/lib/page-object/elements/link.rb +46 -0
  151. data/lib/page-object/elements/list_item.rb +19 -0
  152. data/lib/page-object/elements/media.rb +45 -0
  153. data/lib/page-object/elements/option.rb +10 -0
  154. data/lib/page-object/elements/ordered_list.rb +50 -0
  155. data/lib/page-object/elements/paragraph.rb +9 -0
  156. data/lib/page-object/elements/radio_button.rb +37 -0
  157. data/lib/page-object/elements/select_list.rb +42 -0
  158. data/lib/page-object/elements/span.rb +19 -0
  159. data/lib/page-object/elements/table.rb +68 -0
  160. data/lib/page-object/elements/table_cell.rb +28 -0
  161. data/lib/page-object/elements/table_row.rb +50 -0
  162. data/lib/page-object/elements/text_area.rb +38 -0
  163. data/lib/page-object/elements/text_field.rb +42 -0
  164. data/lib/page-object/elements/unordered_list.rb +51 -0
  165. data/lib/page-object/elements/video.rb +18 -0
  166. data/lib/page-object/elements.rb +59 -0
  167. data/lib/page-object/indexed_properties.rb +36 -0
  168. data/lib/page-object/javascript/jquery.rb +14 -0
  169. data/lib/page-object/javascript/prototype.rb +14 -0
  170. data/lib/page-object/javascript/yui.rb +19 -0
  171. data/lib/page-object/javascript_framework_facade.rb +78 -0
  172. data/lib/page-object/loads_platform.rb +26 -0
  173. data/lib/page-object/locator_generator.rb +129 -0
  174. data/lib/page-object/nested_elements.rb +17 -0
  175. data/lib/page-object/page_factory.rb +108 -0
  176. data/lib/page-object/page_populator.rb +92 -0
  177. data/lib/page-object/platforms/selenium_webdriver/button.rb +15 -0
  178. data/lib/page-object/platforms/selenium_webdriver/check_box.rb +29 -0
  179. data/lib/page-object/platforms/selenium_webdriver/element.rb +291 -0
  180. data/lib/page-object/platforms/selenium_webdriver/file_field.rb +16 -0
  181. data/lib/page-object/platforms/selenium_webdriver/form.rb +16 -0
  182. data/lib/page-object/platforms/selenium_webdriver/image.rb +28 -0
  183. data/lib/page-object/platforms/selenium_webdriver/label.rb +17 -0
  184. data/lib/page-object/platforms/selenium_webdriver/link.rb +23 -0
  185. data/lib/page-object/platforms/selenium_webdriver/ordered_list.rb +39 -0
  186. data/lib/page-object/platforms/selenium_webdriver/page_object.rb +1136 -0
  187. data/lib/page-object/platforms/selenium_webdriver/radio_button.rb +22 -0
  188. data/lib/page-object/platforms/selenium_webdriver/select_list.rb +93 -0
  189. data/lib/page-object/platforms/selenium_webdriver/surrogate_selenium_element.rb +42 -0
  190. data/lib/page-object/platforms/selenium_webdriver/table.rb +42 -0
  191. data/lib/page-object/platforms/selenium_webdriver/table_row.rb +43 -0
  192. data/lib/page-object/platforms/selenium_webdriver/text_area.rb +17 -0
  193. data/lib/page-object/platforms/selenium_webdriver/text_field.rb +17 -0
  194. data/lib/page-object/platforms/selenium_webdriver/unordered_list.rb +39 -0
  195. data/lib/page-object/platforms/selenium_webdriver.rb +18 -0
  196. data/lib/page-object/platforms/watir_webdriver/check_box.rb +29 -0
  197. data/lib/page-object/platforms/watir_webdriver/element.rb +249 -0
  198. data/lib/page-object/platforms/watir_webdriver/file_field.rb +16 -0
  199. data/lib/page-object/platforms/watir_webdriver/form.rb +16 -0
  200. data/lib/page-object/platforms/watir_webdriver/image.rb +22 -0
  201. data/lib/page-object/platforms/watir_webdriver/label.rb +17 -0
  202. data/lib/page-object/platforms/watir_webdriver/link.rb +15 -0
  203. data/lib/page-object/platforms/watir_webdriver/ordered_list.rb +35 -0
  204. data/lib/page-object/platforms/watir_webdriver/page_object.rb +1029 -0
  205. data/lib/page-object/platforms/watir_webdriver/radio_button.rb +22 -0
  206. data/lib/page-object/platforms/watir_webdriver/select_list.rb +74 -0
  207. data/lib/page-object/platforms/watir_webdriver/table.rb +38 -0
  208. data/lib/page-object/platforms/watir_webdriver/table_row.rb +37 -0
  209. data/lib/page-object/platforms/watir_webdriver/text_area.rb +23 -0
  210. data/lib/page-object/platforms/watir_webdriver/text_field.rb +16 -0
  211. data/lib/page-object/platforms/watir_webdriver/unordered_list.rb +36 -0
  212. data/lib/page-object/platforms/watir_webdriver.rb +18 -0
  213. data/lib/page-object/platforms.rb +18 -0
  214. data/lib/page-object/version.rb +4 -0
  215. data/lib/page-object/widgets.rb +133 -0
  216. data/lib/page-object.rb +408 -0
  217. data/meeane-page-object.gemspec +32 -0
  218. data/pageobject.gems +1 -0
  219. data/spec/page-object/element_locators_spec.rb +1065 -0
  220. data/spec/page-object/elements/area_spec.rb +45 -0
  221. data/spec/page-object/elements/button_spec.rb +50 -0
  222. data/spec/page-object/elements/canvas_spec.rb +40 -0
  223. data/spec/page-object/elements/check_box_spec.rb +49 -0
  224. data/spec/page-object/elements/div_spec.rb +28 -0
  225. data/spec/page-object/elements/element_spec.rb +114 -0
  226. data/spec/page-object/elements/file_field_spec.rb +39 -0
  227. data/spec/page-object/elements/form_spec.rb +28 -0
  228. data/spec/page-object/elements/heading_spec.rb +48 -0
  229. data/spec/page-object/elements/hidden_field_spec.rb +28 -0
  230. data/spec/page-object/elements/image_spec.rb +66 -0
  231. data/spec/page-object/elements/label_spec.rb +29 -0
  232. data/spec/page-object/elements/link_spec.rb +49 -0
  233. data/spec/page-object/elements/list_item_spec.rb +28 -0
  234. data/spec/page-object/elements/nested_element_spec.rb +254 -0
  235. data/spec/page-object/elements/option_spec.rb +11 -0
  236. data/spec/page-object/elements/ordered_list_spec.rb +94 -0
  237. data/spec/page-object/elements/paragraph_spec.rb +28 -0
  238. data/spec/page-object/elements/select_list_spec.rb +142 -0
  239. data/spec/page-object/elements/selenium/radio_button_spec.rb +44 -0
  240. data/spec/page-object/elements/selenium/text_field_spec.rb +49 -0
  241. data/spec/page-object/elements/selenium_element_spec.rb +172 -0
  242. data/spec/page-object/elements/span_spec.rb +26 -0
  243. data/spec/page-object/elements/table_cell_spec.rb +21 -0
  244. data/spec/page-object/elements/table_row_spec.rb +70 -0
  245. data/spec/page-object/elements/table_spec.rb +98 -0
  246. data/spec/page-object/elements/text_area_spec.rb +39 -0
  247. data/spec/page-object/elements/unordered_list_spec.rb +95 -0
  248. data/spec/page-object/elements/watir_element_spec.rb +142 -0
  249. data/spec/page-object/javascript_framework_facade_spec.rb +61 -0
  250. data/spec/page-object/loads_platform_spec.rb +53 -0
  251. data/spec/page-object/page-object_spec.rb +405 -0
  252. data/spec/page-object/page_factory_spec.rb +256 -0
  253. data/spec/page-object/page_populator_spec.rb +122 -0
  254. data/spec/page-object/platforms/selenium_webdriver/selenium_page_object_spec.rb +68 -0
  255. data/spec/page-object/platforms/selenium_webdriver_spec.rb +29 -0
  256. data/spec/page-object/platforms/watir_webdriver/watir_page_object_spec.rb +29 -0
  257. data/spec/page-object/platforms/watir_webdriver_spec.rb +9 -0
  258. data/spec/page-object/selenium_accessors_spec.rb +589 -0
  259. data/spec/page-object/watir_accessors_spec.rb +1107 -0
  260. data/spec/page-object/widget_spec.rb +226 -0
  261. data/spec/spec_helper.rb +44 -0
  262. metadata +404 -0
@@ -0,0 +1,1313 @@
1
+ require 'erb'
2
+ require 'page-object/locator_generator'
3
+
4
+ module PageObject
5
+ #
6
+ # Contains the class level methods that are inserted into your page objects
7
+ # when you include the PageObject module. These methods will generate another
8
+ # set of methods that provide access to the elements on the web pages.
9
+ #
10
+ # @see PageObject::WatirPageObject for the watir implementation of the platform delegate
11
+ # @see PageObject::SeleniumPageObject for the selenium implementation of the platform delegate
12
+ #
13
+ module Accessors
14
+
15
+ #
16
+ # Set some values that can be used within the class. This is
17
+ # typically used to provide values that help build dynamic urls in
18
+ # the page_url method
19
+ #
20
+ # @param [Hash] the value to set the params
21
+ #
22
+ def params=(the_params)
23
+ @params = the_params
24
+ end
25
+
26
+ #
27
+ # Return the params that exist on this page class
28
+ #
29
+ def params
30
+ @params ||= {}
31
+ end
32
+
33
+ #
34
+ # Specify the url for the page. A call to this method will generate a
35
+ # 'goto' method to take you to the page.
36
+ #
37
+ # @param [String] the url for the page.
38
+ # @param [Symbol] a method name to call to get the url
39
+ #
40
+ def page_url(url)
41
+ define_method("goto") do
42
+ platform.navigate_to self.page_url_value
43
+ end
44
+
45
+ define_method('page_url_value') do
46
+ lookup = url.kind_of?(Symbol) ? self.send(url) : url
47
+ erb = ERB.new(%Q{#{lookup}})
48
+ merged_params = self.class.instance_variable_get("@merged_params")
49
+ params = merged_params ? merged_params : self.class.params
50
+ erb.result(binding)
51
+ end
52
+ end
53
+ alias_method :direct_url, :page_url
54
+
55
+ #
56
+ # Creates a method that waits the expected_title of a page to match the actual.
57
+ # @param [String] expected_title the literal expected title for the page
58
+ # @param [Regexp] expected_title the expected title pattern for the page
59
+ # @param [optional, Integer] timeout default value is nil - do not wait
60
+ # @return [boolean]
61
+ # @raise An exception if expected_title does not match actual title
62
+ #
63
+ # @example Specify 'Google' as the expected title of a page
64
+ # expected_title "Google"
65
+ # page.has_expected_title?
66
+ #
67
+ def wait_for_expected_title(expected_title, timeout=::PageObject.default_element_wait)
68
+ define_method("wait_for_expected_title?") do
69
+ page_title = title
70
+ has_expected_title = (expected_title === page_title)
71
+ if not has_expected_title and not timeout.nil?
72
+ wait_until(timeout, "Expected title '#{expected_title}' instead of '#{page_title}'") do
73
+ has_expected_title = (expected_title === page_title)
74
+ has_expected_title
75
+ end
76
+ end
77
+ raise "Expected title '#{expected_title}' instead of '#{page_title}'" unless has_expected_title
78
+ has_expected_title
79
+ end
80
+ end
81
+
82
+
83
+ #
84
+ # Creates a method that compares the expected_title of a page against the actual.
85
+ # @param [String] expected_title the literal expected title for the page
86
+ # @param [Regexp] expected_title the expected title pattern for the page
87
+ # @return [boolean]
88
+ # @raise An exception if expected_title does not match actual title
89
+ #
90
+ # @example Specify 'Google' as the expected title of a page
91
+ # expected_title "Google"
92
+ # page.has_expected_title?
93
+ #
94
+ def expected_title(expected_title)
95
+ define_method("has_expected_title?") do
96
+ page_title = title
97
+ has_expected_title = (expected_title === page_title)
98
+ raise "Expected title '#{expected_title}' instead of '#{page_title}'" unless has_expected_title
99
+ has_expected_title
100
+ end
101
+ end
102
+
103
+ #
104
+ # Creates a method that provides a way to initialize a page based upon an expected element.
105
+ # This is useful for pages that load dynamic content.
106
+ # @param [Symbol] the name given to the element in the declaration
107
+ # @param [optional, Integer] timeout default value is 5 seconds
108
+ # @return [boolean]
109
+ #
110
+ # @example Specify a text box named :address expected on the page within 10 seconds
111
+ # expected_element(:address, 10)
112
+ # page.has_expected_element?
113
+ #
114
+ def expected_element(element_name, timeout=::PageObject.default_element_wait)
115
+ define_method("has_expected_element?") do
116
+ self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_present timeout
117
+ end
118
+ end
119
+
120
+ #
121
+ # Creates a method that provides a way to initialize a page based upon an expected element to become visible.
122
+ # This is useful for pages that load dynamic content and might have hidden elements that are not shown.
123
+ # @param [Symbol] the name given to the element in the declaration
124
+ # @param [optional, Integer] timeout default value is 5 seconds
125
+ # @param [optional, boolean] also check that element to be visible if set to true
126
+ # @return [boolean]
127
+ #
128
+ # @example Specify a text box named :address expected on the page within 10 seconds
129
+ # expected_element_visible(:address, 10)
130
+ # page.has_expected_element_visible?
131
+ #
132
+ def expected_element_visible(element_name, timeout=::PageObject.default_element_wait, check_visible=false)
133
+ define_method("has_expected_element_visible?") do
134
+ self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_present timeout
135
+ self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_visible timeout
136
+ end
137
+ end
138
+
139
+ #
140
+ # Identify an element as existing within a frame . A frame parameter
141
+ # is passed to the block and must be passed to the other calls to PageObject.
142
+ # You can nest calls to in_frame by passing the frame to the next level.
143
+ #
144
+ # @example
145
+ # in_frame(:id => 'frame_id') do |frame|
146
+ # text_field(:first_name, :id => 'fname', :frame => frame)
147
+ # end
148
+ #
149
+ # @param [Hash] identifier how we find the frame. The valid keys are:
150
+ # * :id => Watir and Selenium
151
+ # * :index => Watir and Selenium
152
+ # * :name => Watir and Selenium
153
+ # * :regexp => Watir only
154
+ # @param frame passed from a previous call to in_frame. Used to nest calls
155
+ # @param block that contains the calls to elements that exist inside the frame.
156
+ #
157
+ def in_frame(identifier, frame=nil, &block)
158
+ frame = [] if frame.nil?
159
+ frame << {frame: identifier}
160
+ block.call(frame)
161
+ end
162
+
163
+ #
164
+ # Identify an element as existing within an iframe. A frame parameter
165
+ # is passed to the block and must be passed to the other calls to PageObject.
166
+ # You can nest calls to in_frame by passing the frame to the next level.
167
+ #
168
+ # @example
169
+ # in_iframe(:id => 'frame_id') do |frame|
170
+ # text_field(:first_name, :id => 'fname', :frame => frame)
171
+ # end
172
+ #
173
+ # @param [Hash] identifier how we find the frame. The valid keys are:
174
+ # * :id => Watir and Selenium
175
+ # * :index => Watir and Selenium
176
+ # * :name => Watir and Selenium
177
+ # * :regexp => Watir only
178
+ # @param frame passed from a previous call to in_iframe. Used to nest calls
179
+ # @param block that contains the calls to elements that exist inside the iframe.
180
+ #
181
+ def in_iframe(identifier, frame=nil, &block)
182
+ frame = [] if frame.nil?
183
+ frame << {iframe: identifier}
184
+ block.call(frame)
185
+ end
186
+
187
+ #
188
+ # adds four methods to the page object - one to set text in a text field,
189
+ # another to retrieve text from a text field, another to return the text
190
+ # field element, another to check the text field's existence.
191
+ #
192
+ # @example
193
+ # text_field(:first_name, :id => "first_name")
194
+ # # will generate 'first_name', 'first_name=', 'first_name_element',
195
+ # # 'first_name?' methods
196
+ #
197
+ # @param [String] the name used for the generated methods
198
+ # @param [Hash] identifier how we find a text field. You can use a multiple parameters
199
+ # by combining of any of the following except xpath. The valid keys are:
200
+ # * :class => Watir and Selenium
201
+ # * :css => Selenium only
202
+ # * :id => Watir and Selenium
203
+ # * :index => Watir and Selenium
204
+ # * :label => Watir and Selenium
205
+ # * :name => Watir and Selenium
206
+ # * :text => Watir and Selenium
207
+ # * :title => Watir and Selenium
208
+ # * :value => Watir only
209
+ # * :xpath => Watir and Selenium
210
+ # @param optional block to be invoked when element method is called
211
+ #
212
+ def text_field(name, identifier={:index => 0}, &block)
213
+ standard_methods(name, identifier, 'text_field_for', &block)
214
+ define_method(name) do
215
+ return platform.text_field_value_for identifier.clone unless block_given?
216
+ self.send("#{name}_element").value
217
+ end
218
+ define_method("#{name}=") do |value|
219
+ return platform.text_field_value_set(identifier.clone, value) unless block_given?
220
+ self.send("#{name}_element").value = value
221
+ end
222
+ end
223
+
224
+ #
225
+ # adds three methods to the page object - one to get the text from a hidden field,
226
+ # another to retrieve the hidden field element, and another to check the hidden
227
+ # field's existence.
228
+ #
229
+ # @example
230
+ # hidden_field(:user_id, :id => "user_identity")
231
+ # # will generate 'user_id', 'user_id_element' and 'user_id?' methods
232
+ #
233
+ # @param [String] the name used for the generated methods
234
+ # @param [Hash] identifier how we find a hidden field. You can use a multiple parameters
235
+ # by combining of any of the following except xpath. The valid keys are:
236
+ # * :class => Watir and Selenium
237
+ # * :css => Selenium only
238
+ # * :id => Watir and Selenium
239
+ # * :index => Watir and Selenium
240
+ # * :name => Watir and Selenium
241
+ # * :text => Watir and Selenium
242
+ # * :value => Watir and Selenium
243
+ # * :xpath => Watir and Selenium
244
+ # @param optional block to be invoked when element method is called
245
+ #
246
+ def hidden_field(name, identifier={:index => 0}, &block)
247
+ standard_methods(name, identifier, 'hidden_field_for', &block)
248
+ define_method(name) do
249
+ return platform.hidden_field_value_for identifier.clone unless block_given?
250
+ self.send("#{name}_element").value
251
+ end
252
+ end
253
+ alias_method :hidden, :hidden_field
254
+
255
+ #
256
+ # adds four methods to the page object - one to set text in a text area,
257
+ # another to retrieve text from a text area, another to return the text
258
+ # area element, and another to check the text area's existence.
259
+ #
260
+ # @example
261
+ # text_area(:address, :id => "address")
262
+ # # will generate 'address', 'address=', 'address_element',
263
+ # # 'address?' methods
264
+ #
265
+ # @param [String] the name used for the generated methods
266
+ # @param [Hash] identifier how we find a text area. You can use a multiple parameters
267
+ # by combining of any of the following except xpath. The valid keys are:
268
+ # * :class => Watir and Selenium
269
+ # * :css => Selenium only
270
+ # * :id => Watir and Selenium
271
+ # * :index => Watir and Selenium
272
+ # * :name => Watir and Selenium
273
+ # * :xpath => Watir and Selenium
274
+ # * :label => Watir and Selenium
275
+ # @param optional block to be invoked when element method is called
276
+ #
277
+ def text_area(name, identifier={:index => 0}, &block)
278
+ standard_methods(name, identifier, 'text_area_for', &block)
279
+ define_method(name) do
280
+ return platform.text_area_value_for identifier.clone unless block_given?
281
+ self.send("#{name}_element").value
282
+ end
283
+ define_method("#{name}=") do |value|
284
+ return platform.text_area_value_set(identifier.clone, value) unless block_given?
285
+ self.send("#{name}_element").value = value
286
+ end
287
+ end
288
+ alias_method :textarea, :text_area
289
+
290
+ #
291
+ # adds five methods - one to select an item in a drop-down,
292
+ # another to fetch the currently selected item text, another
293
+ # to retrieve the select list element, another to check the
294
+ # drop down's existence and another to get all the available options
295
+ # to select from.
296
+ #
297
+ # @example
298
+ # select_list(:state, :id => "state")
299
+ # # will generate 'state', 'state=', 'state_element', 'state?', "state_options" methods
300
+ #
301
+ # @param [Symbol] the name used for the generated methods
302
+ # @param [Hash] identifier how we find a select list. You can use a multiple parameters
303
+ # by combining of any of the following except xpath. The valid keys are:
304
+ # * :class => Watir and Selenium
305
+ # * :css => Selenium only
306
+ # * :id => Watir and Selenium
307
+ # * :index => Watir and Selenium
308
+ # * :name => Watir and Selenium
309
+ # * :text => Watir only
310
+ # * :value => Watir only
311
+ # * :xpath => Watir and Selenium
312
+ # * :label => Watir and Selenium
313
+ # @param optional block to be invoked when element method is called
314
+ #
315
+ def select_list(name, identifier={:index => 0}, &block)
316
+ standard_methods(name, identifier, 'select_list_for', &block)
317
+ define_method(name) do
318
+ return platform.select_list_value_for identifier.clone unless block_given?
319
+ self.send("#{name}_element").value
320
+ end
321
+ define_method("#{name}=") do |value|
322
+ return platform.select_list_value_set(identifier.clone, value) unless block_given?
323
+ self.send("#{name}_element").select(value)
324
+ end
325
+ define_method("#{name}_options") do
326
+ element = self.send("#{name}_element")
327
+ (element && element.options) ? element.options.collect(&:text) : []
328
+ end
329
+ end
330
+ alias_method :select, :select_list
331
+
332
+ #
333
+ # adds three methods - one to select a link, another
334
+ # to return a PageObject::Elements::Link object representing
335
+ # the link, and another that checks the link's existence.
336
+ #
337
+ # @example
338
+ # link(:add_to_cart, :text => "Add to Cart")
339
+ # # will generate 'add_to_cart', 'add_to_cart_element', and 'add_to_cart?' methods
340
+ #
341
+ # @param [Symbol] the name used for the generated methods
342
+ # @param [Hash] identifier how we find a link. You can use a multiple parameters
343
+ # by combining of any of the following except xpath. The valid keys are:
344
+ # * :class => Watir and Selenium
345
+ # * :css => Watir and Selenium
346
+ # * :href => Watir and Selenium
347
+ # * :id => Watir and Selenium
348
+ # * :index => Watir and Selenium
349
+ # * :link => Watir and Selenium
350
+ # * :link_text => Watir and Selenium
351
+ # * :name => Watir and Selenium
352
+ # * :text => Watir and Selenium
353
+ # * :title => Watir and Selenium
354
+ # * :xpath => Watir and Selenium
355
+ # @param optional block to be invoked when element method is called
356
+ #
357
+ def link(name, identifier={:index => 0}, &block)
358
+ standard_methods(name, identifier, 'link_for', &block)
359
+ define_method(name) do
360
+ return platform.click_link_for identifier.clone unless block_given?
361
+ self.send("#{name}_element").click
362
+ end
363
+ end
364
+ alias_method :a, :link
365
+
366
+ #
367
+ # adds five methods - one to check, another to uncheck, another
368
+ # to return the state of a checkbox, another to return
369
+ # a PageObject::Elements::CheckBox object representing the checkbox, and
370
+ # a final method to check the checkbox's existence.
371
+ #
372
+ # @example
373
+ # checkbox(:active, :name => "is_active")
374
+ # # will generate 'check_active', 'uncheck_active', 'active_checked?',
375
+ # # 'active_element', and 'active?' methods
376
+ #
377
+ # @param [Symbol] the name used for the generated methods
378
+ # @param [Hash] identifier how we find a checkbox. You can use a multiple parameters
379
+ # by combining of any of the following except xpath. The valid keys are:
380
+ # * :class => Watir and Selenium
381
+ # * :css => Selenium only
382
+ # * :id => Watir and Selenium
383
+ # * :index => Watir and Selenium
384
+ # * :name => Watir and Selenium
385
+ # * :value => Watir and Selenium
386
+ # * :xpath => Watir and Selenium
387
+ # * :label => Watir and Selenium
388
+ # @param optional block to be invoked when element method is called
389
+ #
390
+ def checkbox(name, identifier={:index => 0}, &block)
391
+ standard_methods(name, identifier, 'checkbox_for', &block)
392
+ define_method("check_#{name}") do
393
+ return platform.check_checkbox(identifier.clone) unless block_given?
394
+ self.send("#{name}_element").check
395
+ end
396
+ define_method("uncheck_#{name}") do
397
+ return platform.uncheck_checkbox(identifier.clone) unless block_given?
398
+ self.send("#{name}_element").uncheck
399
+ end
400
+ define_method("#{name}_checked?") do
401
+ return platform.checkbox_checked?(identifier.clone) unless block_given?
402
+ self.send("#{name}_element").checked?
403
+ end
404
+ end
405
+
406
+ #
407
+ # adds four methods - one to select, another to return if a radio button
408
+ # is selected, another method to return a PageObject::Elements::RadioButton
409
+ # object representing the radio button element, and another to check
410
+ # the radio button's existence.
411
+ #
412
+ # @example
413
+ # radio_button(:north, :id => "north")
414
+ # # will generate 'select_north', 'north_selected?',
415
+ # # 'north_element', and 'north?' methods
416
+ #
417
+ # @param [Symbol] the name used for the generated methods
418
+ # @param [Hash] identifier how we find a radio button. You can use a multiple parameters
419
+ # by combining of any of the following except xpath. The valid keys are:
420
+ # * :class => Watir and Selenium
421
+ # * :css => Selenium only
422
+ # * :id => Watir and Selenium
423
+ # * :index => Watir and Selenium
424
+ # * :name => Watir and Selenium
425
+ # * :value => Watir and Selenium
426
+ # * :xpath => Watir and Selenium
427
+ # * :label => Watir and Selenium
428
+ # @param optional block to be invoked when element method is called
429
+ #
430
+ def radio_button(name, identifier={:index => 0}, &block)
431
+ standard_methods(name, identifier, 'radio_button_for', &block)
432
+ define_method("select_#{name}") do
433
+ return platform.select_radio(identifier.clone) unless block_given?
434
+ self.send("#{name}_element").select
435
+ end
436
+ define_method("#{name}_selected?") do
437
+ return platform.radio_selected?(identifier.clone) unless block_given?
438
+ self.send("#{name}_element").selected?
439
+ end
440
+ end
441
+ alias_method :radio, :radio_button
442
+
443
+ #
444
+ # adds five methods to help interact with a radio button group -
445
+ # a method to select a radio button in the group by given value/text,
446
+ # a method to return the values of all radio buttons in the group, a method
447
+ # to return if a radio button in the group is selected (will return
448
+ # the text of the selected radio button, if true), a method to return
449
+ # an array of PageObject::Elements::RadioButton objects representing
450
+ # the radio button group, and finally a method to check the existence
451
+ # of the radio button group.
452
+ #
453
+ # @example
454
+ # radio_button_group(:color, :name => "preferred_color")
455
+ # will generate 'select_color', 'color_values', 'color_selected?',
456
+ # 'color_elements', and 'color?' methods
457
+ #
458
+ # @param [Symbol] the name used for the generated methods
459
+ # @param [Hash] shared identifier for the radio button group. Typically, a 'name' attribute.
460
+ # The valid keys are:
461
+ # * :name => Watir and Selenium
462
+ #
463
+ def radio_button_group(name, identifier)
464
+ define_method("select_#{name}") do |value|
465
+ platform.radio_buttons_for(identifier.clone).each do |radio_elem|
466
+ if radio_elem.value == value
467
+ return radio_elem.select
468
+ end
469
+ end
470
+ end
471
+ define_method("#{name}_values") do
472
+ result = []
473
+ platform.radio_buttons_for(identifier.clone).each do |radio_elem|
474
+ result << radio_elem.value
475
+ end
476
+ return result
477
+ end
478
+ define_method("#{name}_selected?") do
479
+ platform.radio_buttons_for(identifier.clone).each do |radio_elem|
480
+ return radio_elem.value if radio_elem.selected?
481
+ end
482
+ return false
483
+ end
484
+ define_method("#{name}_elements") do
485
+ return platform.radio_buttons_for(identifier.clone)
486
+ end
487
+ define_method("#{name}?") do
488
+ return platform.radio_buttons_for(identifier.clone).any?
489
+ end
490
+ end
491
+ alias_method :radio_group, :radio_button_group
492
+
493
+ #
494
+ # adds three methods - one to click a button, another to
495
+ # return the button element, and another to check the button's existence.
496
+ #
497
+ # @example
498
+ # button(:purchase, :id => 'purchase')
499
+ # # will generate 'purchase', 'purchase_element', and 'purchase?' methods
500
+ #
501
+ # @param [Symbol] the name used for the generated methods
502
+ # @param [Hash] identifier how we find a button. You can use a multiple parameters
503
+ # by combining of any of the following except xpath. The valid keys are:
504
+ # * :class => Watir and Selenium
505
+ # * :css => Watir and Selenium
506
+ # * :id => Watir and Selenium
507
+ # * :index => Watir and Selenium
508
+ # * :name => Watir and Selenium
509
+ # * :text => Watir only
510
+ # * :value => Watir and Selenium
511
+ # * :xpath => Watir and Selenium
512
+ # * :src => Watir and Selenium (input type=image only)
513
+ # * :alt => Watir and Selenium (input type=image only)
514
+ # @param optional block to be invoked when element method is called
515
+ #
516
+ def button(name, identifier={:index => 0}, &block)
517
+ standard_methods(name, identifier, 'button_for', &block)
518
+ define_method(name) do
519
+ return platform.click_button_for identifier.clone unless block_given?
520
+ self.send("#{name}_element").click
521
+ end
522
+ end
523
+
524
+ #
525
+ # adds three methods - one to retrieve the text from a div,
526
+ # another to return the div element, and another to check the div's existence.
527
+ #
528
+ # @example
529
+ # div(:message, :id => 'message')
530
+ # # will generate 'message', 'message_element', and 'message?' methods
531
+ #
532
+ # @param [Symbol] the name used for the generated methods
533
+ # @param [Hash] identifier how we find a div. You can use a multiple parameters
534
+ # by combining of any of the following except xpath. The valid keys are:
535
+ # * :class => Watir and Selenium
536
+ # * :css => Watir and Selenium
537
+ # * :id => Watir and Selenium
538
+ # * :index => Watir and Selenium
539
+ # * :name => Watir and Selenium
540
+ # * :text => Watir and Selenium
541
+ # * :title => Watir and Selenium
542
+ # * :xpath => Watir and Selenium
543
+ # @param optional block to be invoked when element method is called
544
+ #
545
+ def div(name, identifier={:index => 0}, &block)
546
+ standard_methods(name, identifier, 'div_for', &block)
547
+ define_method(name) do
548
+ return platform.div_text_for identifier.clone unless block_given?
549
+ self.send("#{name}_element").text
550
+ end
551
+ end
552
+
553
+ #
554
+ # adds three methods - one to retrieve the text from a span,
555
+ # another to return the span element, and another to check the span's existence.
556
+ #
557
+ # @example
558
+ # span(:alert, :id => 'alert')
559
+ # # will generate 'alert', 'alert_element', and 'alert?' methods
560
+ #
561
+ # @param [Symbol] the name used for the generated methods
562
+ # @param [Hash] identifier how we find a span. You can use a multiple parameters
563
+ # by combining of any of the following except xpath. The valid keys are:
564
+ # * :class => Watir and Selenium
565
+ # * :css => Watir and Selenium
566
+ # * :id => Watir and Selenium
567
+ # * :index => Watir and Selenium
568
+ # * :name => Watir and Selenium
569
+ # * :text => Watir and Selenium
570
+ # * :title => Watir and Selenium
571
+ # * :xpath => Watir and Selenium
572
+ # @param optional block to be invoked when element method is called
573
+ #
574
+ def span(name, identifier={:index => 0}, &block)
575
+ standard_methods(name, identifier, 'span_for', &block)
576
+ define_method(name) do
577
+ return platform.span_text_for identifier.clone unless block_given?
578
+ self.send("#{name}_element").text
579
+ end
580
+ end
581
+
582
+ #
583
+ # adds three methods - one to return the text for the table, one
584
+ # to retrieve the table element, and another to
585
+ # check the table's existence. The existence method does not work
586
+ # on Selenium so it should not be called.
587
+ #
588
+ # @example
589
+ # table(:cart, :id => 'shopping_cart')
590
+ # # will generate a 'cart', 'cart_element' and 'cart?' method
591
+ #
592
+ # @param [Symbol] the name used for the generated methods
593
+ # @param [Hash] identifier how we find a table. You can use a multiple parameters
594
+ # by combining of any of the following except xpath. The valid keys are:
595
+ # * :class => Watir and Selenium
596
+ # * :css => Selenium only
597
+ # * :id => Watir and Selenium
598
+ # * :index => Watir and Selenium
599
+ # * :name => Watir and Selenium
600
+ # * :xpath => Watir and Selenium
601
+ # @param optional block to be invoked when element method is called
602
+ #
603
+ def table(name, identifier={:index => 0}, &block)
604
+ standard_methods(name, identifier, 'table_for', &block)
605
+ define_method(name) do
606
+ return platform.table_text_for identifier.clone unless block_given?
607
+ self.send("#{name}_element").text
608
+ end
609
+ end
610
+
611
+ #
612
+ # adds three methods - one to retrieve the text from a table cell,
613
+ # another to return the table cell element, and another to check the cell's
614
+ # existence.
615
+ #
616
+ # @example
617
+ # cell(:total, :id => 'total_cell')
618
+ # # will generate 'total', 'total_element', and 'total?' methods
619
+ #
620
+ # @param [Symbol] the name used for the generated methods
621
+ # @param [Hash] identifier how we find a cell. You can use a multiple parameters
622
+ # by combining of any of the following except xpath. The valid keys are:
623
+ # * :class => Watir and Selenium
624
+ # * :css => Watir and Selenium
625
+ # * :id => Watir and Selenium
626
+ # * :index => Watir and Selenium
627
+ # * :name => Watir and Selenium
628
+ # * :text => Watir and Selenium
629
+ # * :xpath => Watir and Selenium
630
+ # * :css => Selenium only
631
+ # @param optional block to be invoked when element method is called
632
+ #
633
+ def cell(name, identifier={:index => 0}, &block)
634
+ standard_methods(name, identifier, 'cell_for', &block)
635
+ define_method("#{name}") do
636
+ return platform.cell_text_for identifier.clone unless block_given?
637
+ self.send("#{name}_element").text
638
+ end
639
+ end
640
+ alias_method :td, :cell
641
+
642
+ #
643
+ # adds two methods - one to retrieve the image element, and another to
644
+ # check the image's existence.
645
+ #
646
+ # @example
647
+ # image(:logo, :id => 'logo')
648
+ # # will generate 'logo_element' and 'logo?' methods
649
+ #
650
+ # @param [Symbol] the name used for the generated methods
651
+ # @param [Hash] identifier how we find an image. You can use a multiple parameters
652
+ # by combining of any of the following except xpath. The valid keys are:
653
+ # * :alt => Watir and Selenium
654
+ # * :class => Watir and Selenium
655
+ # * :css => Selenium only
656
+ # * :id => Watir and Selenium
657
+ # * :index => Watir and Selenium
658
+ # * :name => Watir and Selenium
659
+ # * :src => Watir and Selenium
660
+ # * :xpath => Watir and Selenium
661
+ # @param optional block to be invoked when element method is called
662
+ #
663
+ def image(name, identifier={:index => 0}, &block)
664
+ standard_methods(name, identifier, 'image_for', &block)
665
+ end
666
+ alias_method :img, :image
667
+
668
+ #
669
+ # adds two methods - one to retrieve the form element, and another to
670
+ # check the form's existence.
671
+ #
672
+ # @example
673
+ # form(:login, :id => 'login')
674
+ # # will generate 'login_element' and 'login?' methods
675
+ #
676
+ # @param [Symbol] the name used for the generated methods
677
+ # @param [Hash] identifier how we find a form. You can use a multiple parameters
678
+ # by combining of any of the following except xpath. The valid keys are:
679
+ # * :action => Watir and Selenium
680
+ # * :class => Watir and Selenium
681
+ # * :css => Selenium only
682
+ # * :id => Watir and Selenium
683
+ # * :index => Watir and Selenium
684
+ # * :xpath => Watir and Selenium
685
+ # @param optional block to be invoked when element method is called
686
+ #
687
+ def form(name, identifier={:index => 0}, &block)
688
+ standard_methods(name, identifier, 'form_for', &block)
689
+ end
690
+
691
+ #
692
+ # adds three methods - one to retrieve the text from a list item,
693
+ # another to return the list item element, and another to check the list item's
694
+ # existence.
695
+ #
696
+ # @example
697
+ # list_item(:item_one, :id => 'one')
698
+ # # will generate 'item_one', 'item_one_element', and 'item_one?' methods
699
+ #
700
+ # @param [Symbol] the name used for the generated methods
701
+ # @param [Hash] identifier how we find a list item. You can use a multiple parameters
702
+ # by combining of any of the following except xpath. The valid keys are:
703
+ # * :class => Watir and Selenium
704
+ # * :css => Watir and Selenium
705
+ # * :id => Watir and Selenium
706
+ # * :index => Watir and Selenium
707
+ # * :name => Watir and Selenium
708
+ # * :text => Watir and Selenium
709
+ # * :xpath => Watir and Selenium
710
+ # @param optional block to be invoked when element method is called
711
+ #
712
+ def list_item(name, identifier={:index => 0}, &block)
713
+ standard_methods(name, identifier, 'list_item_for', &block)
714
+ define_method(name) do
715
+ return platform.list_item_text_for identifier.clone unless block_given?
716
+ self.send("#{name}_element").text
717
+ end
718
+ end
719
+ alias_method :li, :list_item
720
+
721
+ #
722
+ # adds three methods - one to return the text within the unordered
723
+ # list, one to retrieve the unordered list element, and another to
724
+ # check it's existence.
725
+ #
726
+ # @example
727
+ # unordered_list(:menu, :id => 'main_menu')
728
+ # # will generate 'menu', 'menu_element' and 'menu?' methods
729
+ #
730
+ # @param [Symbol] the name used for the generated methods
731
+ # @param [Hash] identifier how we find an unordered list. You can use a multiple parameters
732
+ # by combining of any of the following except xpath. The valid keys are:
733
+ # * :class => Watir and Selenium
734
+ # * :css => Selenium only
735
+ # * :id => Watir and Selenium
736
+ # * :index => Watir and Selenium
737
+ # * :name => Watir and Selenium
738
+ # * :xpath => Watir and Selenium
739
+ # @param optional block to be invoked when element method is called
740
+ #
741
+ def unordered_list(name, identifier={:index => 0}, &block)
742
+ standard_methods(name, identifier, 'unordered_list_for', &block)
743
+ define_method(name) do
744
+ return platform.unordered_list_text_for identifier.clone unless block_given?
745
+ self.send("#{name}_element").text
746
+ end
747
+ end
748
+ alias_method :ul, :unordered_list
749
+
750
+ #
751
+ # adds three methods - one to return the text within the ordered
752
+ # list, one to retrieve the ordered list element, and another to
753
+ # test it's existence.
754
+ #
755
+ # @example
756
+ # ordered_list(:top_five, :id => 'top')
757
+ # # will generate 'top_five', 'top_five_element' and 'top_five?' methods
758
+ #
759
+ # @param [Symbol] the name used for the generated methods
760
+ # @param [Hash] identifier how we find an ordered list. You can use a multiple parameters
761
+ # by combining of any of the following except xpath. The valid keys are:
762
+ # * :class => Watir and Selenium
763
+ # * :css => Selenium only
764
+ # * :id => Watir and Selenium
765
+ # * :index => Watir and Selenium
766
+ # * :name => Watir and Selenium
767
+ # * :xpath => Watir and Selenium
768
+ # @param optional block to be invoked when element method is called
769
+ #
770
+ def ordered_list(name, identifier={:index => 0}, &block)
771
+ standard_methods(name, identifier, 'ordered_list_for', &block)
772
+ define_method(name) do
773
+ return platform.ordered_list_text_for identifier.clone unless block_given?
774
+ self.send("#{name}_element").text
775
+ end
776
+ end
777
+ alias_method :ol, :ordered_list
778
+
779
+ #
780
+ # adds three methods - one to retrieve the text of a h1 element, another to
781
+ # retrieve a h1 element, and another to check for it's existence.
782
+ #
783
+ # @example
784
+ # h1(:title, :id => 'title')
785
+ # # will generate 'title', 'title_element', and 'title?' methods
786
+ #
787
+ # @param [Symbol] the name used for the generated methods
788
+ # @param [Hash] identifier how we find a H1. You can use a multiple parameters
789
+ # by combining of any of the following except xpath. The valid keys are:
790
+ # * :class => Watir and Selenium
791
+ # * :css => Watir and Selenium
792
+ # * :id => Watir and Selenium
793
+ # * :index => Watir and Selenium
794
+ # * :name => Watir and Selenium
795
+ # * :xpath => Watir and Selenium
796
+ # @param optional block to be invoked when element method is called
797
+ #
798
+ def h1(name, identifier={:index => 0}, &block)
799
+ standard_methods(name, identifier,'h1_for', &block)
800
+ define_method(name) do
801
+ return platform.h1_text_for identifier.clone unless block_given?
802
+ self.send("#{name}_element").text
803
+ end
804
+ end
805
+
806
+ #
807
+ # adds three methods - one to retrieve the text of a h2 element, another
808
+ # to retrieve a h2 element, and another to check for it's existence.
809
+ #
810
+ # @example
811
+ # h2(:title, :id => 'title')
812
+ # # will generate 'title', 'title_element', and 'title?' methods
813
+ #
814
+ # @param [Symbol] the name used for the generated methods
815
+ # @param [Hash] identifier how we find a H2. You can use a multiple parameters
816
+ # by combining of any of the following except xpath. The valid keys are:
817
+ # * :class => Watir and Selenium
818
+ # * :css => Watir and Selenium
819
+ # * :id => Watir and Selenium
820
+ # * :index => Watir and Selenium
821
+ # * :name => Watir and Selenium
822
+ # * :xpath => Watir and Selenium
823
+ # @param optional block to be invoked when element method is called
824
+ #
825
+ def h2(name, identifier={:index => 0}, &block)
826
+ standard_methods(name, identifier, 'h2_for', &block)
827
+ define_method(name) do
828
+ return platform.h2_text_for identifier.clone unless block_given?
829
+ self.send("#{name}_element").text
830
+ end
831
+ end
832
+
833
+ #
834
+ # adds three methods - one to retrieve the text of a h3 element,
835
+ # another to return a h3 element, and another to check for it's existence.
836
+ #
837
+ # @example
838
+ # h3(:title, :id => 'title')
839
+ # # will generate 'title', 'title_element', and 'title?' methods
840
+ #
841
+ # @param [Symbol] the name used for the generated methods
842
+ # @param [Hash] identifier how we find a H3. You can use a multiple parameters
843
+ # by combining of any of the following except xpath. The valid keys are:
844
+ # * :class => Watir and Selenium
845
+ # * :css => Watir and Selenium
846
+ # * :id => Watir and Selenium
847
+ # * :index => Watir and Selenium
848
+ # * :name => Watir and Selenium
849
+ # * :xpath => Watir and Selenium
850
+ # @param optional block to be invoked when element method is called
851
+ #
852
+ def h3(name, identifier={:index => 0}, &block)
853
+ standard_methods(name, identifier, 'h3_for', &block)
854
+ define_method(name) do
855
+ return platform.h3_text_for identifier.clone unless block_given?
856
+ self.send("#{name}_element").text
857
+ end
858
+ end
859
+
860
+ #
861
+ # adds three methods - one to retrieve the text of a h4 element,
862
+ # another to return a h4 element, and another to check for it's existence.
863
+ #
864
+ # @example
865
+ # h4(:title, :id => 'title')
866
+ # # will generate 'title', 'title_element', and 'title?' methods
867
+ #
868
+ # @param [Symbol] the name used for the generated methods
869
+ # @param [Hash] identifier how we find a H4. You can use a multiple parameters
870
+ # by combining of any of the following except xpath. The valid keys are:
871
+ # * :class => Watir and Selenium
872
+ # * :css => Watir and Selenium
873
+ # * :id => Watir and Selenium
874
+ # * :index => Watir and Selenium
875
+ # * :name => Watir and Selenium
876
+ # * :xpath => Watir and Selenium
877
+ # @param optional block to be invoked when element method is called
878
+ #
879
+ def h4(name, identifier={:index => 0}, &block)
880
+ standard_methods(name, identifier, 'h4_for', &block)
881
+ define_method(name) do
882
+ return platform.h4_text_for identifier.clone unless block_given?
883
+ self.send("#{name}_element").text
884
+ end
885
+ end
886
+
887
+ #
888
+ # adds three methods - one to retrieve the text of a h5 element,
889
+ # another to return a h5 element, and another to check for it's existence.
890
+ #
891
+ # @example
892
+ # h5(:title, :id => 'title')
893
+ # # will generate 'title', 'title_element', and 'title?' methods
894
+ #
895
+ # @param [Symbol] the name used for the generated methods
896
+ # @param [Hash] identifier how we find a H5. You can use a multiple parameters
897
+ # by combining of any of the following except xpath. The valid keys are:
898
+ # * :class => Watir and Selenium
899
+ # * :css => Watir and Selenium
900
+ # * :id => Watir and Selenium
901
+ # * :index => Watir and Selenium
902
+ # * :name => Watir and Selenium
903
+ # * :xpath => Watir and Selenium
904
+ # @param optional block to be invoked when element method is called
905
+ #
906
+ def h5(name, identifier={:index => 0}, &block)
907
+ standard_methods(name, identifier, 'h5_for', &block)
908
+ define_method(name) do
909
+ return platform.h5_text_for identifier.clone unless block_given?
910
+ self.send("#{name}_element").text
911
+ end
912
+ end
913
+
914
+ #
915
+ # adds three methods - one to retrieve the text of a h6 element,
916
+ # another to return a h6 element, and another to check for it's existence.
917
+ #
918
+ # @example
919
+ # h6(:title, :id => 'title')
920
+ # # will generate 'title', 'title_element', and 'title?' methods
921
+ #
922
+ # @param [Symbol] the name used for the generated methods
923
+ # @param [Hash] identifier how we find a H6. You can use a multiple parameters
924
+ # by combining of any of the following except xpath. The valid keys are:
925
+ # * :class => Watir and Selenium
926
+ # * :css => Watir and Selenium
927
+ # * :id => Watir and Selenium
928
+ # * :index => Watir and Selenium
929
+ # * :name => Watir and Selenium
930
+ # * :xpath => Watir and Selenium
931
+ # @param optional block to be invoked when element method is called
932
+ #
933
+ def h6(name, identifier={:index => 0}, &block)
934
+ standard_methods(name, identifier, 'h6_for', &block)
935
+ define_method(name) do
936
+ return platform.h6_text_for identifier.clone unless block_given?
937
+ self.send("#{name}_element").text
938
+ end
939
+ end
940
+
941
+ #
942
+ # adds three methods - one to retrieve the text of a paragraph, another
943
+ # to retrieve a paragraph element, and another to check the paragraph's existence.
944
+ #
945
+ # @example
946
+ # paragraph(:title, :id => 'title')
947
+ # # will generate 'title', 'title_element', and 'title?' methods
948
+ #
949
+ # @param [Symbol] the name used for the generated methods
950
+ # @param [Hash] identifier how we find a paragraph. You can use a multiple parameters
951
+ # by combining of any of the following except xpath. The valid keys are:
952
+ # * :class => Watir and Selenium
953
+ # * :css => Watir and Selenium
954
+ # * :id => Watir and Selenium
955
+ # * :index => Watir and Selenium
956
+ # * :name => Watir and Selenium
957
+ # * :xpath => Watir and Selenium
958
+ # @param optional block to be invoked when element method is called
959
+ #
960
+ def paragraph(name, identifier={:index => 0}, &block)
961
+ standard_methods(name, identifier, 'paragraph_for', &block)
962
+ define_method(name) do
963
+ return platform.paragraph_text_for identifier.clone unless block_given?
964
+ self.send("#{name}_element").text
965
+ end
966
+ end
967
+ alias_method :p, :paragraph
968
+
969
+ #
970
+ # adds three methods - one to set the file for a file field, another to retrieve
971
+ # the file field element, and another to check it's existence.
972
+ #
973
+ # @example
974
+ # file_field(:the_file, :id => 'file_to_upload')
975
+ # # will generate 'the_file=', 'the_file_element', and 'the_file?' methods
976
+ #
977
+ # @param [Symbol] the name used for the generated methods
978
+ # @param [Hash] identifier how we find a file_field. You can use a multiple parameters
979
+ # by combining of any of the following except xpath. The valid keys are:
980
+ # * :class => Watir and Selenium
981
+ # * :css => Selenium only
982
+ # * :id => Watir and Selenium
983
+ # * :index => Watir and Selenium
984
+ # * :name => Watir and Selenium
985
+ # * :title => Watir and Selenium
986
+ # * :xpath => Watir and Selenium
987
+ # * :label => Watir and Selenium
988
+ # @param optional block to be invoked when element method is called
989
+ #
990
+ def file_field(name, identifier={:index => 0}, &block)
991
+ standard_methods(name, identifier, 'file_field_for', &block)
992
+ define_method("#{name}=") do |value|
993
+ return platform.file_field_value_set(identifier.clone, value) unless block_given?
994
+ self.send("#{name}_element").value = value
995
+ end
996
+ end
997
+
998
+ #
999
+ # adds three methods - one to retrieve the text from a label,
1000
+ # another to return the label element, and another to check the label's existence.
1001
+ #
1002
+ # @example
1003
+ # label(:message, :id => 'message')
1004
+ # # will generate 'message', 'message_element', and 'message?' methods
1005
+ #
1006
+ # @param [Symbol] the name used for the generated methods
1007
+ # @param [Hash] identifier how we find a label. You can use a multiple parameters
1008
+ # by combining of any of the following except xpath. The valid keys are:
1009
+ # * :class => Watir and Selenium
1010
+ # * :css => Watir and Selenium
1011
+ # * :id => Watir and Selenium
1012
+ # * :index => Watir and Selenium
1013
+ # * :name => Watir and Selenium
1014
+ # * :text => Watir and Selenium
1015
+ # * :xpath => Watir and Selenium
1016
+ # @param optional block to be invoked when element method is called
1017
+ #
1018
+ def label(name, identifier={:index => 0}, &block)
1019
+ standard_methods(name, identifier, 'label_for', &block)
1020
+ define_method("choose_#{name}") do
1021
+ return platform.choose_label(identifier.clone) unless block_given?
1022
+ self.send("#{name}_element").click
1023
+ end
1024
+ define_method(name) do
1025
+ return platform.label_text_for identifier.clone unless block_given?
1026
+ self.send("#{name}_element").text
1027
+ end
1028
+ end
1029
+
1030
+ #
1031
+ # adds three methods - one to click the area,
1032
+ # another to return the area element, and another to check the area's existence.
1033
+ #
1034
+ # @example
1035
+ # area(:message, :id => 'message')
1036
+ # # will generate 'message', 'message_element', and 'message?' methods
1037
+ #
1038
+ # @param [Symbol] the name used for the generated methods
1039
+ # @param [Hash] identifier how we find an area. You can use a multiple parameters
1040
+ # by combining of any of the following except xpath. The valid keys are:
1041
+ # * :class => Watir and Selenium
1042
+ # * :css => Watir and Selenium
1043
+ # * :id => Watir and Selenium
1044
+ # * :index => Watir and Selenium
1045
+ # * :name => Watir and Selenium
1046
+ # * :text => Watir and Selenium
1047
+ # * :xpath => Watir and Selenium
1048
+ # @param optional block to be invoked when element method is called
1049
+ #
1050
+ def area(name, identifier={:index => 0}, &block)
1051
+ standard_methods(name, identifier, 'area_for', &block)
1052
+ define_method(name) do
1053
+ return platform.click_area_for identifier.clone unless block_given?
1054
+ self.send("#{name}_element").click
1055
+ end
1056
+ end
1057
+
1058
+ #
1059
+ # adds two methods - one to return the canvas element and another to check
1060
+ # the canvas's existence.
1061
+ #
1062
+ # @example
1063
+ # canvas(:my_canvas, :id => 'canvas_id')
1064
+ # # will generate 'my_canvas_element' and 'my_canvas?' methods
1065
+ #
1066
+ # @param [Symbol] the name used for the generated methods
1067
+ # @param [Hash] identifier how we find a canvas. You can use a multiple parameters
1068
+ # by combining of any of the following except xpath. The valid keys are:
1069
+ # * :class => Watir and Selenium
1070
+ # * :css => Watir and Selenium
1071
+ # * :id => Watir and Selenium
1072
+ # * :index => Watir and Selenium
1073
+ # * :name => Watir and Selenium
1074
+ # * :xpath => Watir and Selenium
1075
+ # @param optional block to be invoked when element method is called
1076
+ #
1077
+ def canvas(name, identifier={:index => 0}, &block)
1078
+ standard_methods(name, identifier, 'canvas_for', &block)
1079
+ end
1080
+
1081
+ #
1082
+ # adds two methods - one to return the audio element and another to check
1083
+ # the audio's existence.
1084
+ #
1085
+ # @example
1086
+ # audio(:acdc, :id => 'audio_id')
1087
+ # # will generate 'acdc_element' and 'acdc?' methods
1088
+ #
1089
+ # @param [Symbol] the name used for the generated methods
1090
+ # @param [Hash] identifier how we find an audio element. You can use a multiple parameters
1091
+ # by combining of any of the following except xpath. The valid keys are:
1092
+ # * :class => Watir and Selenium
1093
+ # * :css => Watir and Selenium
1094
+ # * :id => Watir and Selenium
1095
+ # * :index => Watir and Selenium
1096
+ # * :name => Watir and Selenium
1097
+ # * :xpath => Watir and Selenium
1098
+ # @param optional block to be invoked when element method is called
1099
+ #
1100
+ def audio(name, identifier={:index => 0}, &block)
1101
+ standard_methods(name, identifier, 'audio_for', &block)
1102
+ end
1103
+
1104
+ #
1105
+ # adds two methods - one to return the video element and another to check
1106
+ # the video's existence.
1107
+ #
1108
+ # @example
1109
+ # video(:movie, :id => 'video_id')
1110
+ # # will generate 'movie_element' and 'movie?' methods
1111
+ #
1112
+ # @param [Symbol] the name used for the generated methods
1113
+ # @param [Hash] identifier how we find a video element. You can use a multiple parameters
1114
+ # by combining of any of the following except xpath. The valid keys are:
1115
+ # * :class => Watir and Selenium
1116
+ # * :css => Watir and Selenium
1117
+ # * :id => Watir and Selenium
1118
+ # * :index => Watir and Selenium
1119
+ # * :name => Watir and Selenium
1120
+ # * :xpath => Watir and Selenium
1121
+ # @param optional block to be invoked when element method is called
1122
+ #
1123
+ def video(name, identifier={:index => 0}, &block)
1124
+ standard_methods(name, identifier, 'video_for', &block)
1125
+ end
1126
+
1127
+ #
1128
+ # adds two methods - one to retrieve a svg, and another to check
1129
+ # the svg's existence.
1130
+ #
1131
+ # @example
1132
+ # svg(:circle, :id => 'circle')
1133
+ # # will generate 'circle_element', and 'circle?' methods
1134
+ #
1135
+ # @param [Symbol] the name used for the generated methods
1136
+ # @param [Hash] identifier how we find a svg. You can use a multiple parameters
1137
+ # by combining of any of the following except xpath. The valid keys are:
1138
+ # * :class => Watir and Selenium
1139
+ # * :css => Selenium only
1140
+ # * :id => Watir and Selenium
1141
+ # * :index => Watir and Selenium
1142
+ # * :name => Watir and Selenium
1143
+ # * :xpath => Watir and Selenium
1144
+ # @param optional block to be invoked when element method is called
1145
+ #
1146
+ def svg(name, identifier={:index => 0}, &block)
1147
+ standard_methods(name, identifier, 'svg_for', &block)
1148
+ end
1149
+
1150
+
1151
+ #
1152
+ # adds three methods - one to retrieve the text of an element, another
1153
+ # to retrieve an element, and another to check the element's existence.
1154
+ #
1155
+ # @example
1156
+ # element(:title, :header, :id => 'title')
1157
+ # # will generate 'title', 'title_element', and 'title?' methods
1158
+ #
1159
+ # @param [Symbol] the name used for the generated methods
1160
+ # @param [Symbol] the name of the tag for the element
1161
+ # @param [Hash] identifier how we find an element. You can use a multiple parameters
1162
+ # by combining of any of the following except xpath. The valid keys are:
1163
+ # * :class => Watir and Selenium
1164
+ # * :css => Selenium only
1165
+ # * :id => Watir and Selenium
1166
+ # * :index => Watir and Selenium
1167
+ # * :name => Watir and Selenium
1168
+ # * :xpath => Watir and Selenium
1169
+ # @param optional block to be invoked when element method is called
1170
+ #
1171
+ def element(name, tag, identifier={:index => 0}, &block)
1172
+ define_method("#{name}") do
1173
+ self.send("#{name}_element").text
1174
+ end
1175
+ define_method("#{name}_element") do
1176
+ return call_block(&block) if block_given?
1177
+ platform.element_for(tag, identifier.clone)
1178
+ end
1179
+ define_method("#{name}?") do
1180
+ self.send("#{name}_element").exists?
1181
+ end
1182
+ end
1183
+
1184
+ #
1185
+ # adds a method to return a collection of generic Element objects
1186
+ # for a specific tag.
1187
+ #
1188
+ # @example
1189
+ # elements(:title, :header, :id => 'title')
1190
+ # # will generate ''title_elements'
1191
+ #
1192
+ # @param [Symbol] the name used for the generated methods
1193
+ # @param [Symbol] the name of the tag for the element
1194
+ # @param [Hash] identifier how we find an element. You can use a multiple parameters
1195
+ # by combining of any of the following except xpath. The valid keys are:
1196
+ # * :class => Watir and Selenium
1197
+ # * :css => Selenium only
1198
+ # * :id => Watir and Selenium
1199
+ # * :index => Watir and Selenium
1200
+ # * :name => Watir and Selenium
1201
+ # * :xpath => Watir and Selenium
1202
+ # @param optional block to be invoked when element method is called
1203
+ #
1204
+ def elements(name, tag, identifier={:index => 0}, &block)
1205
+ define_method("#{name}_elements") do
1206
+ return call_block(&block) if block_given?
1207
+ platform.elements_for(tag, identifier.clone)
1208
+ end
1209
+ end
1210
+
1211
+ #
1212
+ # methods to generate accessors for types that follow the same
1213
+ # pattern as element
1214
+ #
1215
+ # @example
1216
+ # article(:my_article, :id => "article_id")
1217
+ # will generate 'my_article', 'my_article_element' and 'my_article?'
1218
+ # articles(:my_article, :id => 'article_id')
1219
+ # will generate 'my_article_elements'
1220
+ #
1221
+ # @param [Symbol] the name used for the generated methods
1222
+ # @param [Symbol] the name of the tag for the element
1223
+ # @param [Hash] identifier how we find an element. You can use a multiple parameters
1224
+ # by combining of any of the following except xpath. The valid keys are:
1225
+ # * :class => Watir and Selenium
1226
+ # * :css => Selenium only
1227
+ # * :id => Watir and Selenium
1228
+ # * :index => Watir and Selenium
1229
+ # * :name => Watir and Selenium
1230
+ # * :xpath => Watir and Selenium
1231
+ # @param optional block to be invoked when element method is called
1232
+ #
1233
+ LocatorGenerator::BASIC_ELEMENTS.each do |tag|
1234
+ define_method(tag) do |name, *identifier, &block|
1235
+ identifier = identifier[0] ? identifier[0] : {:index => 0}
1236
+ element(name, tag, identifier, &block)
1237
+ end
1238
+ define_method("#{tag}s") do |name, *identifier, &block|
1239
+ identifier = identifier[0] ? identifier[0] : {:index => 0}
1240
+ elements(name, tag, identifier, &block)
1241
+ end unless tag == :param
1242
+ end
1243
+
1244
+ def standard_methods(name, identifier, method, &block)
1245
+ define_method("#{name}_element") do
1246
+ return call_block(&block) if block_given?
1247
+ platform.send(method, identifier.clone)
1248
+ end
1249
+ define_method("#{name}?") do
1250
+ return call_block(&block).exists? if block_given?
1251
+ platform.send(method, identifier.clone).exists?
1252
+ end
1253
+ end
1254
+
1255
+ #
1256
+ # adds a method that will return an indexed property. The property will respond to
1257
+ # the [] method with an object that has a set of normal page_object properties that
1258
+ # correspond to the definitions included in the identifier_list parameter, with the
1259
+ # "what" of the "how and what" substituted based on the index provided to the []
1260
+ # method.
1261
+ #
1262
+ # @example
1263
+ # indexed_property(:title, [
1264
+ # [:text_field, :field_1, :id => 'table[%s].field_1'],
1265
+ # [:button, :button_1, :id => 'table[%s].button_1'],
1266
+ # [:text_field, :field_2, :name => 'table[%s].field_2']
1267
+ # ])
1268
+ # # will generate a title method that responds to []. title['foo'] will return an object
1269
+ # # that responds to the normal methods expected for two text_fields and a button with the
1270
+ # # given names, using the given how and what with 'foo' substituted for the %s. title[123]
1271
+ # # will do the same, using the integer 123 instead.
1272
+ #
1273
+ # @param [Symbol] the name used for the generated method
1274
+ # @param [Array] definitions an array of definitions to define on the indexed property. Each
1275
+ # entry in the array should contain two symbols and a hash, corresponding to one of the standard
1276
+ # page_object properties with a single substitution marker in each value in the hash,
1277
+ # e.g. [:text_field, :field_1, :id => 'table[%s].field_1']
1278
+ #
1279
+ def indexed_property (name, identifier_list)
1280
+ define_method("#{name}") do
1281
+ IndexedProperties::TableOfElements.new(@browser, identifier_list)
1282
+ end
1283
+ end
1284
+
1285
+ #
1286
+ # methods to fetch multiple elements of the same type
1287
+ #
1288
+ # adds a method to the page object to return all of the matching elements
1289
+ #
1290
+ # @example
1291
+ # text_fields(:first_name, :id => "first_name")
1292
+ # # will generate 'first_name_elements'
1293
+ #
1294
+ # @param [String] the name used for the generated methods
1295
+ # @param [Hash] identifier how we find a text field. You can use a multiple parameters
1296
+ # by combining of any of the following except xpath. The valid
1297
+ # keys are the same ones supported by the standard methods.
1298
+ # @param optional block to be invoked when element method is called
1299
+ #
1300
+ idx = LocatorGenerator::ADVANCED_ELEMENTS.find_index { |type| type == :checkbox }
1301
+ elements = LocatorGenerator::ADVANCED_ELEMENTS.clone
1302
+ elements[idx] = :checkboxe
1303
+ elements.each do |method_name|
1304
+ define_method("#{method_name}s") do |name, *identifier, &block|
1305
+ define_method("#{name}_elements") do
1306
+ return call_block(&block) unless block.nil?
1307
+ platform_method = (method_name == :checkboxe) ? 'checkboxs_for' : "#{method_name.to_s}s_for"
1308
+ platform.send platform_method, (identifier.first ? identifier.first.clone : {})
1309
+ end
1310
+ end
1311
+ end
1312
+ end
1313
+ end