watir 1.6.5 → 1.6.6.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGES +461 -326
  2. data/VERSION +1 -0
  3. data/bin/watir-console +6 -6
  4. data/lib/changes.rb +3 -3
  5. data/lib/license.rb +38 -38
  6. data/lib/readme.rb +140 -140
  7. data/lib/watir/WindowHelper.rb +49 -49
  8. data/lib/watir/camel_case.rb +66 -66
  9. data/lib/watir/clickJSDialog.rb +19 -19
  10. data/lib/watir/close_all.rb +37 -37
  11. data/lib/watir/collections.rb +392 -344
  12. data/lib/watir/container.rb +857 -815
  13. data/lib/watir/contrib/enabled_popup.rb +20 -20
  14. data/lib/watir/contrib/ie-new-process.rb +27 -27
  15. data/lib/watir/contrib/page_checker.rb +29 -29
  16. data/lib/watir/cookiemanager.rb +55 -55
  17. data/lib/watir/core.rb +28 -0
  18. data/lib/watir/core_ext.rb +17 -17
  19. data/lib/watir/datahandler.rb +107 -107
  20. data/lib/watir/dialog.rb +46 -46
  21. data/lib/watir/element.rb +351 -343
  22. data/lib/watir/element_collections.rb +97 -97
  23. data/lib/watir/form.rb +170 -170
  24. data/lib/watir/frame.rb +59 -59
  25. data/lib/watir/html_element.rb +22 -0
  26. data/lib/watir/ie-class.rb +1006 -1009
  27. data/lib/watir/ie-process.rb +39 -39
  28. data/lib/watir/ie.rb +70 -133
  29. data/lib/watir/image.rb +130 -130
  30. data/lib/watir/input_elements.rb +614 -572
  31. data/lib/watir/irb-history.rb +30 -30
  32. data/lib/watir/link.rb +64 -64
  33. data/lib/watir/locator.rb +200 -176
  34. data/lib/watir/logger.rb +19 -19
  35. data/lib/watir/modal_dialog.rb +122 -122
  36. data/lib/watir/module.rb +37 -0
  37. data/lib/watir/non_control_elements.rb +145 -145
  38. data/lib/watir/page-container.rb +116 -107
  39. data/lib/watir/popup.rb +29 -29
  40. data/lib/watir/process.rb +19 -19
  41. data/lib/watir/screen_capture.rb +115 -115
  42. data/lib/watir/setFileDialog.rb +16 -16
  43. data/lib/watir/table.rb +395 -362
  44. data/lib/watir/watir_simple.rb +475 -475
  45. data/lib/watir/win32.rb +35 -35
  46. data/lib/watir/win32ole.rb +14 -14
  47. data/lib/watir/winClicker.rb +496 -496
  48. data/rakefile.rb +70 -0
  49. data/unittests/all_tests.rb +10 -10
  50. data/unittests/buttons_xpath_test.rb +69 -69
  51. data/unittests/checkbox_test.rb +179 -179
  52. data/unittests/checkbox_xpath_test.rb +107 -107
  53. data/unittests/click_no_wait_test.rb +21 -0
  54. data/unittests/core_tests.rb +17 -17
  55. data/unittests/css_test.rb +42 -35
  56. data/unittests/defer_test.rb +46 -46
  57. data/unittests/dialog_test.rb +77 -77
  58. data/unittests/div2_xpath_test.rb +21 -21
  59. data/unittests/div_test.rb +188 -188
  60. data/unittests/div_xpath_test.rb +96 -96
  61. data/unittests/element_test.rb +49 -0
  62. data/unittests/errorchecker_test.rb +32 -22
  63. data/unittests/filefield_test.rb +39 -39
  64. data/unittests/filefield_xpath_test.rb +33 -33
  65. data/unittests/form_test.rb +280 -280
  66. data/unittests/form_xpath_test.rb +252 -252
  67. data/unittests/frame_test.rb +155 -155
  68. data/unittests/google_form_test.rb +15 -15
  69. data/unittests/html/JavascriptClick.html +39 -39
  70. data/unittests/html/blankpage.html +11 -11
  71. data/unittests/html/buttons1.html +40 -40
  72. data/unittests/html/checkboxes1.html +89 -89
  73. data/unittests/html/click_no_wait.html +14 -0
  74. data/unittests/html/complex_table.html +36 -36
  75. data/unittests/html/cssTest.html +42 -42
  76. data/unittests/html/depot_store.html +59 -59
  77. data/unittests/html/div.html +93 -93
  78. data/unittests/html/div_xml.html +20 -20
  79. data/unittests/html/fileupload.html +45 -45
  80. data/unittests/html/formTest1.html +38 -38
  81. data/unittests/html/forms2.html +44 -44
  82. data/unittests/html/forms3.html +131 -131
  83. data/unittests/html/forms4.html +27 -27
  84. data/unittests/html/frame_buttons.html +3 -3
  85. data/unittests/html/frame_links.html +3 -3
  86. data/unittests/html/frame_multi.html +4 -4
  87. data/unittests/html/google_india.html +119 -119
  88. data/unittests/html/iframeTest.html +12 -12
  89. data/unittests/html/iframeTest1.html +6 -6
  90. data/unittests/html/iframeTest2.html +5 -5
  91. data/unittests/html/images1.html +66 -66
  92. data/unittests/html/javascriptevents.html +35 -35
  93. data/unittests/html/link_pass.html +10 -10
  94. data/unittests/html/links1.html +38 -38
  95. data/unittests/html/links2.html +10 -10
  96. data/unittests/html/links_multi.html +14 -14
  97. data/unittests/html/list_matters.html +720 -720
  98. data/unittests/html/lists.html +17 -17
  99. data/unittests/html/map_test.html +31 -31
  100. data/unittests/html/modal_dialog.html +10 -10
  101. data/unittests/html/modal_dialog_launcher.html +11 -11
  102. data/unittests/html/nestedFrames.html +6 -6
  103. data/unittests/html/new_browser.html +16 -16
  104. data/unittests/html/pass.html +12 -12
  105. data/unittests/html/popups1.html +59 -59
  106. data/unittests/html/pre.html +27 -27
  107. data/unittests/html/radioButtons1.html +71 -71
  108. data/unittests/html/select_tealeaf.html +54 -54
  109. data/unittests/html/selectboxes1.html +52 -52
  110. data/unittests/html/simple_table.html +26 -26
  111. data/unittests/html/simple_table_buttons.html +104 -104
  112. data/unittests/html/simple_table_columns.html +76 -76
  113. data/unittests/html/table1.html +181 -181
  114. data/unittests/html/tableCell_using_xpath.html +19 -19
  115. data/unittests/html/table_and_tablerow_to_a.html +174 -0
  116. data/unittests/html/textarea.html +30 -30
  117. data/unittests/html/textfields1.html +88 -88
  118. data/unittests/html/textsearch.html +44 -44
  119. data/unittests/html/wallofcheckboxes.html +1003 -1003
  120. data/unittests/html/xpath_nbsp.html +12 -12
  121. data/unittests/ie_exists_test.rb +33 -33
  122. data/unittests/ie_mock.rb +94 -94
  123. data/unittests/ie_test.rb +51 -51
  124. data/unittests/images_test.rb +157 -157
  125. data/unittests/images_xpath_test.rb +91 -91
  126. data/unittests/links_multi_test.rb +48 -48
  127. data/unittests/links_test.rb +175 -175
  128. data/unittests/links_xpath_test.rb +39 -39
  129. data/unittests/lists_test.rb +32 -32
  130. data/unittests/map_test.rb +98 -98
  131. data/unittests/minmax_test.rb +31 -31
  132. data/unittests/navigate_test.rb +39 -39
  133. data/unittests/nbsp_xpath_test.rb +16 -16
  134. data/unittests/non_core_tests.rb +12 -12
  135. data/unittests/other/WindowLogonExample.rb +27 -27
  136. data/unittests/other/WindowLogonExtra.rb +6 -6
  137. data/unittests/other/all_tests_concurrent.rb +57 -57
  138. data/unittests/other/jscriptExtraAlert.rb +6 -6
  139. data/unittests/other/jscriptExtraConfirmCancel.rb +6 -6
  140. data/unittests/other/jscriptExtraConfirmOk.rb +6 -6
  141. data/unittests/other/jscriptPushButton.rb +6 -6
  142. data/unittests/other/jscript_test.rb +63 -63
  143. data/unittests/other/navigate_exception_test.rb +24 -24
  144. data/unittests/other/rexml_unit_test.rb +27 -27
  145. data/unittests/other/screen_capture_test.rb +54 -54
  146. data/unittests/other/testcase_method_order_test.rb +35 -35
  147. data/unittests/other/testcase_verify_test.rb +24 -24
  148. data/unittests/other/wait_until_test.rb +99 -99
  149. data/unittests/pagecontainstext_test.rb +69 -69
  150. data/unittests/parent_child_test.rb +43 -43
  151. data/unittests/perf_test.rb +20 -20
  152. data/unittests/popups_test.rb +43 -43
  153. data/unittests/pre_test.rb +53 -53
  154. data/unittests/radios_test.rb +212 -212
  155. data/unittests/radios_xpath_test.rb +101 -101
  156. data/unittests/security_setting_test.rb +23 -23
  157. data/unittests/selectbox_test.rb +148 -148
  158. data/unittests/selectbox_xpath_test.rb +113 -113
  159. data/unittests/setup.rb +87 -77
  160. data/unittests/speed_settings_test.rb +67 -67
  161. data/unittests/table_and_tablerow_to_a_test.rb +117 -0
  162. data/unittests/table_cell_using_xpath_test.rb +35 -35
  163. data/unittests/table_test.rb +376 -376
  164. data/unittests/table_xpath_test.rb +110 -110
  165. data/unittests/test_tests.rb +9 -9
  166. data/unittests/textarea_test.rb +92 -92
  167. data/unittests/textarea_xpath_test.rb +78 -78
  168. data/unittests/textfield_for_ch_char_test.rb +31 -31
  169. data/unittests/textfields_test.rb +218 -218
  170. data/unittests/textfields_xpath_test.rb +111 -111
  171. data/unittests/window_tests.rb +10 -10
  172. data/unittests/windows/attach_to_existing_window_test.rb +53 -53
  173. data/unittests/windows/attach_to_new_window_test.rb +83 -83
  174. data/unittests/windows/close_window_test.rb +20 -20
  175. data/unittests/windows/frame_links_test.rb +25 -25
  176. data/unittests/windows/ie-each_test.rb +47 -47
  177. data/unittests/windows/iedialog_test.rb +54 -54
  178. data/unittests/windows/js_events_test.rb +42 -55
  179. data/unittests/windows/modal_dialog_test.rb +128 -128
  180. data/unittests/windows/new_test.rb +57 -57
  181. data/unittests/windows/open_close_test.rb +18 -18
  182. data/unittests/windows/send_keys_test.rb +33 -33
  183. data/unittests/xpath_tests.rb +10 -10
  184. metadata +85 -31
  185. data/lib/watir/utils.rb +0 -20
  186. data/lib/watir/version.rb +0 -5
@@ -1,475 +1,475 @@
1
- =begin
2
- license
3
- ---------------------------------------------------------------------------
4
- Copyright (c) 2004-2005, Atomic Object LLC
5
- All rights reserved.
6
-
7
- Redistribution and use in source and binary forms, with or without
8
- modification, are permitted provided that the following conditions are met:
9
-
10
- 1. Redistributions of source code must retain the above copyright notice,
11
- this list of conditions and the following disclaimer.
12
-
13
- 2. Redistributions in binary form must reproduce the above copyright
14
- notice, this list of conditions and the following disclaimer in the
15
- documentation and/or other materials provided with the distribution.
16
-
17
- 3. Neither the name "Atomic Object LLC" nor the names of contributors to
18
- this software may be used to endorse or promote products derived from this
19
- software without specific prior written permission.
20
-
21
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
22
- IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
25
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28
- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
- --------------------------------------------------------------------------
33
- (based on BSD Open Source License)
34
- =end
35
-
36
- require 'test/unit/assertions'
37
- require 'watir'
38
-
39
- module Watir
40
- # = Description
41
- # Watir::Simple is a simple wrapper around the Watir module. It provides a
42
- # similar set of operations while simplifying them and removing as much syntax
43
- # and test-framework context code as possible.
44
- # The goal is to allow toolsmiths to write domain-language frameworks on top of
45
- # Watir, using Watir::Simple as an easier, lightweight interface to the power
46
- # of Watir.
47
- #
48
- # = Note
49
- # Most action methods in Watir::Simple will automatically wait for the browser
50
- # not to be busy before and after they perform the specified action.
51
- #
52
- # revision: $Revision$
53
- module Simple
54
-
55
- # Open up a browser and point it at a certain URL.
56
- def new_browser_at(url)
57
- @@browser = IE.new
58
- @@browser.typingspeed = 0
59
- @@browser.goto url
60
- end
61
-
62
-
63
- # Tell the browser to load a particular URL.
64
- def navigate_to(url)
65
- @@browser.goto url
66
- end
67
-
68
-
69
- # Much like click_link_with_url but navigates to link instead of clicking it,
70
- # thereby not invoking OnClick for links.
71
- def navigate_to_link_with_url(url)
72
- # FIXME: this should be moved into Watir!
73
- wait_before_and_after do
74
- doc = @@browser.getDocument
75
- links = doc.links
76
- link = nil
77
- links.each do |n|
78
- match = false
79
- case url
80
- when Regexp
81
- match = (n.invoke("href") =~ url)
82
- when String
83
- match = (n.invoke("href") == url)
84
- end
85
- if match
86
- link = n
87
- break
88
- end
89
- end
90
- raise "Couldn't find link with url #{url}" unless link
91
- @@browser.goto link
92
- end
93
- end
94
-
95
- # Much like click_link_with_id but navigates to link instead of clicking it,
96
- # thereby not invoking OnClick for links.
97
- def navigate_to_link_with_id(id)
98
- # FIXME: this should be moved into Watir!
99
- wait_before_and_after do
100
- doc = @@browser.getDocument
101
- links = doc.links
102
- link = nil
103
- links.each do |n|
104
- match = false
105
- case id
106
- when Regexp
107
- match = (n.invoke("id") =~ id)
108
- when String
109
- match = (n.invoke("id") == id)
110
- end
111
- if match
112
- link = n
113
- break
114
- end
115
- end
116
- raise "Couldn't find link with id #{id}" unless link
117
- @@browser.goto link
118
- end
119
- end
120
-
121
- # Tell the browser to click on the first link with the specified URL.
122
- # This takes the address of the link instead of the text displayed.
123
- # * url - can be a string to match exactly, or a regular expression.
124
- #
125
- # Example:
126
- # click_link_with_url "http://google.com"
127
- # or:
128
- # click_link_with_url /goo*/
129
- def click_link_with_url(url)
130
- wait_before_and_after { @@browser.link(:url, url).click }
131
- end
132
-
133
-
134
- # Tell the browser to click on the first link with the specified id attribute
135
- # (the preferred method.)
136
- def click_link_with_id(id)
137
- wait_before_and_after { @@browser.link(:id, id).click }
138
- end
139
-
140
-
141
- # Tell the browser to click on the first link with the specified name attribute
142
- def click_link_with_name(name)
143
- wait_before_and_after { @@browser.link(:name, name).click }
144
- end
145
-
146
-
147
- # Tell the browser to click on the specified link as determined by the
148
- # sequential ordering of links on the document.
149
- def click_link_with_index(index)
150
- wait_before_and_after { @@browser.link(:index, index).click }
151
- end
152
-
153
-
154
- # Tell the browser to click on the first link with the specified text in the
155
- # link body.
156
- def click_link_with_text(text)
157
- wait_before_and_after { @@browser.link(:text, text).click }
158
- end
159
-
160
-
161
- # Set the text of the field with a given name (the preferred method.)
162
- # This only types characters into the field and does not submit the form.
163
- def enter_text_into_field_with_name(name, text)
164
- wait_before_and_after { @@browser.textField(:name, name).set(text) }
165
- end
166
-
167
-
168
- # Set the text of the field with a given id attribute (the preferred method.)
169
- # This only types characters into the field and does not submit the form.
170
- def enter_text_into_field_with_id(id, text)
171
- wait_before_and_after { @@browser.textField(:id, id).set(text) }
172
- end
173
-
174
-
175
- # Set the text of the indexed field. This only types characters
176
- # into the field and does not submit the form.
177
- def enter_text_into_field_with_index(index, text)
178
- wait_before_and_after { @@browser.textField(:index, index).set(text) }
179
- end
180
-
181
-
182
- # Select an item from a selectbox (a.k.a "combo box", or "pulldown")
183
- # The selectbox is chose by matching its name attribute.
184
- # The item is selected based on the text content of <OPTION> tags.
185
- def select_from_combobox_with_name(name, text)
186
- wait_before_and_after { @@browser.selectBox(:name, name).select(text) }
187
- end
188
-
189
-
190
- # Select an item from a selectbox (a.k.a "combo box", or "pulldown")
191
- # The selectbox is chose by matching its id attribute.
192
- # The item is selected based on the text content of <OPTION> tags.
193
- def select_from_combobox_with_id(id, text)
194
- wait_before_and_after { @@browser.selectBox(:id, id).select(text) }
195
- end
196
-
197
-
198
- # Select an item from a selectbox (a.k.a "combo box", or "pulldown")
199
- # The selectbox is chose by matching its order of appearance in the
200
- # document.
201
- # The item is selected based on the text content of <OPTION> tags.
202
- def select_from_combobox_with_index(index, text)
203
- wait_before_and_after { @@browser.selectBox(:index, index).select(text) }
204
- end
205
-
206
-
207
- # Select an item (+value+) from the radio button collection with +name+.
208
- def select_radio_button_with_name(name, value)
209
- wait_before_and_after { @@browser.radio(:name, name, value).click }
210
- end
211
-
212
-
213
- # Select an item (+value+) from the +index+'th radio button collection.
214
- def select_radio_button_with_name(index, value)
215
- wait_before_and_after { @@browser.radio(:index, index, value).click }
216
- end
217
-
218
-
219
- # Select an item (+value+) from the radio button collection with a matching
220
- # +id+ attribute.
221
- def select_radio_button_with_id(id, value)
222
- wait_before_and_after { @@browser.radio(:id, id, value).click }
223
- end
224
-
225
-
226
- # Tell the browser to click on a form button with +name+.
227
- def click_button_with_name(name)
228
- wait_before_and_after { @@browser.button(:name, name).click }
229
- end
230
-
231
-
232
- # Tell the browser to click on a form button with the specified id attribute.
233
- def click_button_with_id(id)
234
- wait_before_and_after { @@browser.button(:id, id).click }
235
- end
236
-
237
-
238
- # Tell the browser to click on a form button with the specified value attribute.
239
- def click_button_with_value(value)
240
- wait_before_and_after { @@browser.button(:value, value).click }
241
- end
242
-
243
-
244
- # Tell the browser to click on a form button with the specified caption text.
245
- def click_button_with_caption(caption)
246
- wait_before_and_after { @@browser.button(:caption, caption).click }
247
- end
248
-
249
-
250
- # Tell the browser to click on the +index+'th form button on the page.
251
- def click_button_with_index(index)
252
- wait_before_and_after { @@browser.button(:index, index).click }
253
- end
254
-
255
-
256
- # Make a Test::Unit assertion that the given +text+ does not appear in the text
257
- # body.
258
- #
259
- # * mesg - An assertion-failed message.
260
- def assert_text_not_in_body(text,mesg=nil)
261
- if mesg.nil? then
262
- assert_false( @@browser.pageContainsText(text), "found in body: [#{text}]")
263
- else
264
- assert_false( @@browser.pageContainsText(text), mesg)
265
- end
266
- end
267
-
268
-
269
- # Make a Test::Unit assertion that the given +text+ appears in the text
270
- # body.
271
- #
272
- # * text - +String+ or +RegExp+ - The text or regular expression to search for.
273
- # * mesg - +String+ - An optional assertion-failed message.
274
- def assert_text_in_body(text,mesg=nil)
275
- if mesg.nil? then
276
- assert(@@browser.pageContainsText(text), "couldn't find in body: [#{text}]")
277
- else
278
- assert(@@browser.pageContainsText(text), mesg)
279
- end
280
- end
281
-
282
-
283
- # This method returns true|false if the text/reg exp supplied is in a the text field "name".
284
- #
285
- # * name - +String+ - Name of field to examine.
286
- # * text - +String+ or +RegExp+ - The text or regular expression to search for.
287
- # * mesg - +String+ - An optional assertion-failed message.
288
- def assert_text_in_field(name, text, mesg=nil)
289
- if mesg.nil? then
290
- assert(@@browser.textField(:name, name).verify_contains(text), "couldn't find in field #{name}: [#{text}]")
291
- else
292
- assert(@@browser.textField(:name, name).verify_contains(text), mesg)
293
- end
294
- end
295
-
296
- #
297
- # * how - symbol - the way we look for the object. Supported values are
298
- # - :name
299
- # - :id
300
- # - :index
301
- # * what - string - What field, id or name to examine.
302
- # * text - string/Array of Strings - The string or array of strings to search for.
303
- # * mesg - Optional! string - Set this if you want to supply your own error message
304
- def assert_text_in_combobox_wrapper(how, what, text, mesg=nil)
305
- assert(@@browser.selectBox(how, what), "could not find a combobox with what: #{what} and how: #{how}")
306
- selectedItems = @@browser.selectBox(how, what).getSelectedItems
307
-
308
- if text.kind_of? String
309
- if mesg.nil? then
310
- assert(selectedItems[0] == text, "couldn't find text in combobox with #{how}: #{what} - [#{text}], had [#{selectedItems[0]}]")
311
- else
312
- assert(selectedItems[0] == text, mesg)
313
- end
314
-
315
- elsif text.kind_of? Array
316
- if mesg.nil? then
317
- text.each do |item|
318
- assert(selectedItems.include?(item), "couldn't find text in combobox with #{how}: #{what} - [#{text}], had [#{selectedItems}]")
319
- end
320
- else
321
- text.each do |item|
322
- assert(selectedItems.include?(item), mesg)
323
- end
324
- end
325
- end
326
- end
327
-
328
-
329
- # This method returns true|false if the text is selected in the combobox
330
- # with the supplied name.
331
- #
332
- # * name - string - Name of field to examine.
333
- # * text - string/Array of Strings - The string or array of strings to search for.
334
- # * mesg - Optional! string - Set this if you want to supply your own error message
335
- def assert_text_in_combobox_by_name(name, text, mesg=nil)
336
- assert_text_in_combobox_wrapper(:name, name, text, mesg)
337
- end
338
-
339
- # FIXME: how to use?
340
- # This method returns true|false if the text is selected in the combobox
341
- # with the supplied index.
342
- #
343
- # * index - string - Index of field to examine.
344
- # * text - string/Array of Strings - The string or array of strings to search for.
345
- # * mesg - Optional! string - Set this if you want to supply your own error message
346
- #def assert_text_in_combobox_by_index(index, text, mesg=nil)
347
- # assert_text_in_combobox_wrapper(:index, name, text, mesg)
348
- #end
349
-
350
- # This method returns true|false if the text is selected in the combobox
351
- # with the supplied id.
352
- #
353
- # * id - string - Id of field to examine.
354
- # * text - string/Array of Strings - The string or array of strings to search for.
355
- # * mesg - Optional! string - Set this if you want to supply your own error message
356
- def assert_text_in_combobox_by_id(id, text, mesg=nil)
357
- assert_text_in_combobox_wrapper(:id, name, text, mesg)
358
- end
359
-
360
-
361
-
362
- # Close the browser window. Useful for automated test suites to reduce
363
- # test interaction.
364
- def close_browser
365
- @@browser.getIE.quit
366
- sleep 2
367
- end
368
-
369
-
370
- # Tell the browser to cick the Back button.
371
- def go_back
372
- @@browser.back
373
- end
374
-
375
-
376
- # Tell the browser to cick the Forward button.
377
- def go_forward
378
- @@browser.forward
379
- end
380
-
381
-
382
- # Fill a series of text fields. This takes a hash of textfield names to
383
- # values for those fields.
384
- #
385
- # Example:
386
- #
387
- # fill_text_fields {
388
- # 'username' => 'joe',
389
- # 'password' => 'blahblah',
390
- # 'email' => 'joe@blahblah.com',
391
- # 'favorite_num' => 42
392
- # }
393
- def fill_text_fields(data)
394
- data.each do |field, value|
395
- @@browser.textField(:name, field).set(value)
396
- end
397
- end
398
-
399
-
400
- # Fill a single textfield with a value
401
- def fill_text_field(field_name, text)
402
- @@browser.textField(:name, field_name).set(text)
403
- end
404
-
405
-
406
- # Some browsers (i.e. IE) need to be waited on before more actions can be
407
- # performed. Most action methods in Watir::Simple already call this before
408
- # and after.
409
- def wait_for_browser
410
- @@browser.waitForIE
411
- end
412
-
413
-
414
- def combobox_default_selection(name)
415
- # FIXME _where_ is this used?
416
- @@browser.selectBox(:name, name).value
417
- end
418
-
419
-
420
- # Returns the number of times +text+ appears in the body text of the page.
421
- def count_instances_of(text)
422
- @@browser.getDocument.body.innerText.scan(text).size
423
- end
424
-
425
-
426
- # Make a Test::Unit assertion that an image exists on the page with the given
427
- # +src+ attribute.
428
- #
429
- # * mesg - +String+ - An optional assertion-failed message.
430
- def assert_image_with_src(src, mesg=nil)
431
- if mesg.nil? then
432
- assert( get_image_with_src(src) != nil, "image with src: [#{src}] is not present")
433
- else
434
- assert( get_image_with_src(src) != nil, mesg)
435
- end
436
- end
437
-
438
-
439
- # Make a Test::Unit assertion that an image exists on the page with the given
440
- # +id+ attribute. (Preferred method)
441
- #
442
- # * mesg - +String+ - An optional assertion-failed message.
443
- def assert_image_with_id(id, mesg=nil)
444
- if mesg.nil? then
445
- assert( get_image_with_id(id) != nil, "image with id: [#{id}] is not present")
446
- else
447
- assert( get_image_with_id(id) != nil, mesg)
448
- end
449
- end
450
-
451
-
452
- # A convenience method to wait at both ends of an operation for the browser
453
- # to catch up.
454
- def wait_before_and_after
455
- wait_for_browser
456
- yield
457
- wait_for_browser
458
- end
459
-
460
-
461
- #### PRIVATE METHODS BEYOND THIS POINT
462
- private
463
- ####
464
-
465
- def get_image_with_src(src)
466
- @@browser.image(:src, src)
467
- end
468
-
469
-
470
- def get_image_with_id(id)
471
- @@browser.image(:id, id)
472
- end
473
-
474
- end
475
- end
1
+ =begin
2
+ license
3
+ ---------------------------------------------------------------------------
4
+ Copyright (c) 2004-2005, Atomic Object LLC
5
+ All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are met:
9
+
10
+ 1. Redistributions of source code must retain the above copyright notice,
11
+ this list of conditions and the following disclaimer.
12
+
13
+ 2. Redistributions in binary form must reproduce the above copyright
14
+ notice, this list of conditions and the following disclaimer in the
15
+ documentation and/or other materials provided with the distribution.
16
+
17
+ 3. Neither the name "Atomic Object LLC" nor the names of contributors to
18
+ this software may be used to endorse or promote products derived from this
19
+ software without specific prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
22
+ IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
25
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ --------------------------------------------------------------------------
33
+ (based on BSD Open Source License)
34
+ =end
35
+
36
+ require 'test/unit/assertions'
37
+ require 'watir'
38
+
39
+ module Watir
40
+ # = Description
41
+ # Watir::Simple is a simple wrapper around the Watir module. It provides a
42
+ # similar set of operations while simplifying them and removing as much syntax
43
+ # and test-framework context code as possible.
44
+ # The goal is to allow toolsmiths to write domain-language frameworks on top of
45
+ # Watir, using Watir::Simple as an easier, lightweight interface to the power
46
+ # of Watir.
47
+ #
48
+ # = Note
49
+ # Most action methods in Watir::Simple will automatically wait for the browser
50
+ # not to be busy before and after they perform the specified action.
51
+ #--
52
+ # revision: $Revision$
53
+ module Simple
54
+
55
+ # Open up a browser and point it at a certain URL.
56
+ def new_browser_at(url)
57
+ @@browser = IE.new
58
+ @@browser.typingspeed = 0
59
+ @@browser.goto url
60
+ end
61
+
62
+
63
+ # Tell the browser to load a particular URL.
64
+ def navigate_to(url)
65
+ @@browser.goto url
66
+ end
67
+
68
+
69
+ # Much like click_link_with_url but navigates to link instead of clicking it,
70
+ # thereby not invoking OnClick for links.
71
+ def navigate_to_link_with_url(url)
72
+ # FIXME: this should be moved into Watir!
73
+ wait_before_and_after do
74
+ doc = @@browser.getDocument
75
+ links = doc.links
76
+ link = nil
77
+ links.each do |n|
78
+ match = false
79
+ case url
80
+ when Regexp
81
+ match = (n.invoke("href") =~ url)
82
+ when String
83
+ match = (n.invoke("href") == url)
84
+ end
85
+ if match
86
+ link = n
87
+ break
88
+ end
89
+ end
90
+ raise "Couldn't find link with url #{url}" unless link
91
+ @@browser.goto link
92
+ end
93
+ end
94
+
95
+ # Much like click_link_with_id but navigates to link instead of clicking it,
96
+ # thereby not invoking OnClick for links.
97
+ def navigate_to_link_with_id(id)
98
+ # FIXME: this should be moved into Watir!
99
+ wait_before_and_after do
100
+ doc = @@browser.getDocument
101
+ links = doc.links
102
+ link = nil
103
+ links.each do |n|
104
+ match = false
105
+ case id
106
+ when Regexp
107
+ match = (n.invoke("id") =~ id)
108
+ when String
109
+ match = (n.invoke("id") == id)
110
+ end
111
+ if match
112
+ link = n
113
+ break
114
+ end
115
+ end
116
+ raise "Couldn't find link with id #{id}" unless link
117
+ @@browser.goto link
118
+ end
119
+ end
120
+
121
+ # Tell the browser to click on the first link with the specified URL.
122
+ # This takes the address of the link instead of the text displayed.
123
+ # * url - can be a string to match exactly, or a regular expression.
124
+ #
125
+ # Example:
126
+ # click_link_with_url "http://google.com"
127
+ # or:
128
+ # click_link_with_url /goo*/
129
+ def click_link_with_url(url)
130
+ wait_before_and_after { @@browser.link(:url, url).click }
131
+ end
132
+
133
+
134
+ # Tell the browser to click on the first link with the specified id attribute
135
+ # (the preferred method.)
136
+ def click_link_with_id(id)
137
+ wait_before_and_after { @@browser.link(:id, id).click }
138
+ end
139
+
140
+
141
+ # Tell the browser to click on the first link with the specified name attribute
142
+ def click_link_with_name(name)
143
+ wait_before_and_after { @@browser.link(:name, name).click }
144
+ end
145
+
146
+
147
+ # Tell the browser to click on the specified link as determined by the
148
+ # sequential ordering of links on the document.
149
+ def click_link_with_index(index)
150
+ wait_before_and_after { @@browser.link(:index, index).click }
151
+ end
152
+
153
+
154
+ # Tell the browser to click on the first link with the specified text in the
155
+ # link body.
156
+ def click_link_with_text(text)
157
+ wait_before_and_after { @@browser.link(:text, text).click }
158
+ end
159
+
160
+
161
+ # Set the text of the field with a given name (the preferred method.)
162
+ # This only types characters into the field and does not submit the form.
163
+ def enter_text_into_field_with_name(name, text)
164
+ wait_before_and_after { @@browser.textField(:name, name).set(text) }
165
+ end
166
+
167
+
168
+ # Set the text of the field with a given id attribute (the preferred method.)
169
+ # This only types characters into the field and does not submit the form.
170
+ def enter_text_into_field_with_id(id, text)
171
+ wait_before_and_after { @@browser.textField(:id, id).set(text) }
172
+ end
173
+
174
+
175
+ # Set the text of the indexed field. This only types characters
176
+ # into the field and does not submit the form.
177
+ def enter_text_into_field_with_index(index, text)
178
+ wait_before_and_after { @@browser.textField(:index, index).set(text) }
179
+ end
180
+
181
+
182
+ # Select an item from a selectbox (a.k.a "combo box", or "pulldown")
183
+ # The selectbox is chose by matching its name attribute.
184
+ # The item is selected based on the text content of <tt><OPTION></tt> tags.
185
+ def select_from_combobox_with_name(name, text)
186
+ wait_before_and_after { @@browser.selectBox(:name, name).select(text) }
187
+ end
188
+
189
+
190
+ # Select an item from a selectbox (a.k.a "combo box", or "pulldown")
191
+ # The selectbox is chose by matching its id attribute.
192
+ # The item is selected based on the text content of <tt><OPTION></tt> tags.
193
+ def select_from_combobox_with_id(id, text)
194
+ wait_before_and_after { @@browser.selectBox(:id, id).select(text) }
195
+ end
196
+
197
+
198
+ # Select an item from a selectbox (a.k.a "combo box", or "pulldown")
199
+ # The selectbox is chose by matching its order of appearance in the
200
+ # document.
201
+ # The item is selected based on the text content of <tt><OPTION></tt> tags.
202
+ def select_from_combobox_with_index(index, text)
203
+ wait_before_and_after { @@browser.selectBox(:index, index).select(text) }
204
+ end
205
+
206
+
207
+ # Select an item (+value+) from the radio button collection with +name+.
208
+ def select_radio_button_with_name(name, value)
209
+ wait_before_and_after { @@browser.radio(:name, name, value).click }
210
+ end
211
+
212
+
213
+ # Select an item (+value+) from the +index+'th radio button collection.
214
+ def select_radio_button_with_name(index, value)
215
+ wait_before_and_after { @@browser.radio(:index, index, value).click }
216
+ end
217
+
218
+
219
+ # Select an item (+value+) from the radio button collection with a matching
220
+ # +id+ attribute.
221
+ def select_radio_button_with_id(id, value)
222
+ wait_before_and_after { @@browser.radio(:id, id, value).click }
223
+ end
224
+
225
+
226
+ # Tell the browser to click on a form button with +name+.
227
+ def click_button_with_name(name)
228
+ wait_before_and_after { @@browser.button(:name, name).click }
229
+ end
230
+
231
+
232
+ # Tell the browser to click on a form button with the specified id attribute.
233
+ def click_button_with_id(id)
234
+ wait_before_and_after { @@browser.button(:id, id).click }
235
+ end
236
+
237
+
238
+ # Tell the browser to click on a form button with the specified value attribute.
239
+ def click_button_with_value(value)
240
+ wait_before_and_after { @@browser.button(:value, value).click }
241
+ end
242
+
243
+
244
+ # Tell the browser to click on a form button with the specified caption text.
245
+ def click_button_with_caption(caption)
246
+ wait_before_and_after { @@browser.button(:caption, caption).click }
247
+ end
248
+
249
+
250
+ # Tell the browser to click on the +index+'th form button on the page.
251
+ def click_button_with_index(index)
252
+ wait_before_and_after { @@browser.button(:index, index).click }
253
+ end
254
+
255
+
256
+ # Make a Test::Unit assertion that the given +text+ does not appear in the text
257
+ # body.
258
+ #
259
+ # * mesg - An assertion-failed message.
260
+ def assert_text_not_in_body(text,mesg=nil)
261
+ if mesg.nil? then
262
+ assert_false( @@browser.pageContainsText(text), "found in body: [#{text}]")
263
+ else
264
+ assert_false( @@browser.pageContainsText(text), mesg)
265
+ end
266
+ end
267
+
268
+
269
+ # Make a Test::Unit assertion that the given +text+ appears in the text
270
+ # body.
271
+ #
272
+ # * text - +String+ or +RegExp+ - The text or regular expression to search for.
273
+ # * mesg - +String+ - An optional assertion-failed message.
274
+ def assert_text_in_body(text,mesg=nil)
275
+ if mesg.nil? then
276
+ assert(@@browser.pageContainsText(text), "couldn't find in body: [#{text}]")
277
+ else
278
+ assert(@@browser.pageContainsText(text), mesg)
279
+ end
280
+ end
281
+
282
+
283
+ # This method returns true|false if the text/reg exp supplied is in a the text field "name".
284
+ #
285
+ # * name - +String+ - Name of field to examine.
286
+ # * text - +String+ or +RegExp+ - The text or regular expression to search for.
287
+ # * mesg - +String+ - An optional assertion-failed message.
288
+ def assert_text_in_field(name, text, mesg=nil)
289
+ if mesg.nil? then
290
+ assert(@@browser.textField(:name, name).verify_contains(text), "couldn't find in field #{name}: [#{text}]")
291
+ else
292
+ assert(@@browser.textField(:name, name).verify_contains(text), mesg)
293
+ end
294
+ end
295
+
296
+ #
297
+ # * how - symbol - the way we look for the object. Supported values are
298
+ # - :name
299
+ # - :id
300
+ # - :index
301
+ # * what - string - What field, id or name to examine.
302
+ # * text - string/Array of Strings - The string or array of strings to search for.
303
+ # * mesg - Optional! string - Set this if you want to supply your own error message
304
+ def assert_text_in_combobox_wrapper(how, what, text, mesg=nil)
305
+ assert(@@browser.selectBox(how, what), "could not find a combobox with what: #{what} and how: #{how}")
306
+ selectedItems = @@browser.selectBox(how, what).getSelectedItems
307
+
308
+ if text.kind_of? String
309
+ if mesg.nil? then
310
+ assert(selectedItems[0] == text, "couldn't find text in combobox with #{how}: #{what} - [#{text}], had [#{selectedItems[0]}]")
311
+ else
312
+ assert(selectedItems[0] == text, mesg)
313
+ end
314
+
315
+ elsif text.kind_of? Array
316
+ if mesg.nil? then
317
+ text.each do |item|
318
+ assert(selectedItems.include?(item), "couldn't find text in combobox with #{how}: #{what} - [#{text}], had [#{selectedItems}]")
319
+ end
320
+ else
321
+ text.each do |item|
322
+ assert(selectedItems.include?(item), mesg)
323
+ end
324
+ end
325
+ end
326
+ end
327
+
328
+
329
+ # This method returns true|false if the text is selected in the combobox
330
+ # with the supplied name.
331
+ #
332
+ # * name - string - Name of field to examine.
333
+ # * text - string/Array of Strings - The string or array of strings to search for.
334
+ # * mesg - Optional! string - Set this if you want to supply your own error message
335
+ def assert_text_in_combobox_by_name(name, text, mesg=nil)
336
+ assert_text_in_combobox_wrapper(:name, name, text, mesg)
337
+ end
338
+
339
+ # FIXME: how to use?
340
+ # This method returns true|false if the text is selected in the combobox
341
+ # with the supplied index.
342
+ #
343
+ # * index - string - Index of field to examine.
344
+ # * text - string/Array of Strings - The string or array of strings to search for.
345
+ # * mesg - Optional! string - Set this if you want to supply your own error message
346
+ #def assert_text_in_combobox_by_index(index, text, mesg=nil)
347
+ # assert_text_in_combobox_wrapper(:index, name, text, mesg)
348
+ #end
349
+
350
+ # This method returns true|false if the text is selected in the combobox
351
+ # with the supplied id.
352
+ #
353
+ # * id - string - Id of field to examine.
354
+ # * text - string/Array of Strings - The string or array of strings to search for.
355
+ # * mesg - Optional! string - Set this if you want to supply your own error message
356
+ def assert_text_in_combobox_by_id(id, text, mesg=nil)
357
+ assert_text_in_combobox_wrapper(:id, name, text, mesg)
358
+ end
359
+
360
+
361
+
362
+ # Close the browser window. Useful for automated test suites to reduce
363
+ # test interaction.
364
+ def close_browser
365
+ @@browser.getIE.quit
366
+ sleep 2
367
+ end
368
+
369
+
370
+ # Tell the browser to cick the Back button.
371
+ def go_back
372
+ @@browser.back
373
+ end
374
+
375
+
376
+ # Tell the browser to cick the Forward button.
377
+ def go_forward
378
+ @@browser.forward
379
+ end
380
+
381
+
382
+ # Fill a series of text fields. This takes a hash of textfield names to
383
+ # values for those fields.
384
+ #
385
+ # Example:
386
+ #
387
+ # fill_text_fields {
388
+ # 'username' => 'joe',
389
+ # 'password' => 'blahblah',
390
+ # 'email' => 'joe@blahblah.com',
391
+ # 'favorite_num' => 42
392
+ # }
393
+ def fill_text_fields(data)
394
+ data.each do |field, value|
395
+ @@browser.textField(:name, field).set(value)
396
+ end
397
+ end
398
+
399
+
400
+ # Fill a single textfield with a value
401
+ def fill_text_field(field_name, text)
402
+ @@browser.textField(:name, field_name).set(text)
403
+ end
404
+
405
+
406
+ # Some browsers (i.e. IE) need to be waited on before more actions can be
407
+ # performed. Most action methods in Watir::Simple already call this before
408
+ # and after.
409
+ def wait_for_browser
410
+ @@browser.waitForIE
411
+ end
412
+
413
+
414
+ def combobox_default_selection(name)
415
+ # FIXME _where_ is this used?
416
+ @@browser.selectBox(:name, name).value
417
+ end
418
+
419
+
420
+ # Returns the number of times +text+ appears in the body text of the page.
421
+ def count_instances_of(text)
422
+ @@browser.getDocument.body.innerText.scan(text).size
423
+ end
424
+
425
+
426
+ # Make a Test::Unit assertion that an image exists on the page with the given
427
+ # +src+ attribute.
428
+ #
429
+ # * mesg - +String+ - An optional assertion-failed message.
430
+ def assert_image_with_src(src, mesg=nil)
431
+ if mesg.nil? then
432
+ assert( get_image_with_src(src) != nil, "image with src: [#{src}] is not present")
433
+ else
434
+ assert( get_image_with_src(src) != nil, mesg)
435
+ end
436
+ end
437
+
438
+
439
+ # Make a Test::Unit assertion that an image exists on the page with the given
440
+ # +id+ attribute. (Preferred method)
441
+ #
442
+ # * mesg - +String+ - An optional assertion-failed message.
443
+ def assert_image_with_id(id, mesg=nil)
444
+ if mesg.nil? then
445
+ assert( get_image_with_id(id) != nil, "image with id: [#{id}] is not present")
446
+ else
447
+ assert( get_image_with_id(id) != nil, mesg)
448
+ end
449
+ end
450
+
451
+
452
+ # A convenience method to wait at both ends of an operation for the browser
453
+ # to catch up.
454
+ def wait_before_and_after
455
+ wait_for_browser
456
+ yield
457
+ wait_for_browser
458
+ end
459
+
460
+
461
+ #### PRIVATE METHODS BEYOND THIS POINT
462
+ private
463
+ ####
464
+
465
+ def get_image_with_src(src)
466
+ @@browser.image(:src, src)
467
+ end
468
+
469
+
470
+ def get_image_with_id(id)
471
+ @@browser.image(:id, id)
472
+ end
473
+
474
+ end
475
+ end