watir 1.6.2 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +326 -188
- data/bin/watir-console +7 -8
- data/lib/changes.rb +3 -3
- data/lib/license.rb +38 -38
- data/lib/readme.rb +140 -140
- data/lib/watir/WindowHelper.rb +49 -49
- data/lib/watir/camel_case.rb +66 -45
- data/lib/watir/clickJSDialog.rb +19 -19
- data/lib/watir/close_all.rb +37 -37
- data/lib/watir/collections.rb +344 -312
- data/lib/watir/container.rb +815 -753
- data/lib/watir/contrib/enabled_popup.rb +20 -20
- data/lib/watir/contrib/ie-new-process.rb +27 -27
- data/lib/watir/contrib/page_checker.rb +29 -29
- data/lib/watir/cookiemanager.rb +55 -55
- data/lib/watir/core_ext.rb +18 -0
- data/lib/watir/datahandler.rb +107 -107
- data/lib/watir/dialog.rb +46 -46
- data/lib/watir/element.rb +343 -312
- data/lib/watir/element_collections.rb +97 -81
- data/lib/watir/form.rb +170 -170
- data/lib/watir/frame.rb +59 -59
- data/lib/watir/ie-class.rb +1009 -1003
- data/lib/watir/ie-process.rb +39 -39
- data/lib/watir/ie.rb +133 -132
- data/lib/watir/image.rb +130 -130
- data/lib/watir/input_elements.rb +572 -539
- data/lib/watir/irb-history.rb +30 -30
- data/lib/watir/link.rb +64 -64
- data/lib/watir/locator.rb +176 -161
- data/lib/watir/logger.rb +19 -19
- data/lib/watir/modal_dialog.rb +122 -122
- data/lib/watir/non_control_elements.rb +145 -127
- data/lib/watir/page-container.rb +107 -105
- data/lib/watir/popup.rb +29 -29
- data/lib/watir/process.rb +19 -19
- data/lib/watir/screen_capture.rb +115 -115
- data/lib/watir/setFileDialog.rb +16 -16
- data/lib/watir/table.rb +362 -362
- data/lib/watir/utils.rb +19 -19
- data/lib/watir/version.rb +5 -5
- data/lib/watir/watir_simple.rb +475 -475
- data/lib/watir/win32.rb +35 -28
- data/lib/watir/win32ole.rb +14 -6
- data/lib/watir/winClicker.rb +496 -479
- data/unittests/all_tests.rb +10 -10
- data/unittests/buttons_xpath_test.rb +69 -69
- data/unittests/checkbox_test.rb +179 -176
- data/unittests/checkbox_xpath_test.rb +107 -107
- data/unittests/core_tests.rb +17 -16
- data/unittests/css_test.rb +35 -35
- data/unittests/defer_test.rb +46 -46
- data/unittests/dialog_test.rb +77 -77
- data/unittests/div2_xpath_test.rb +21 -21
- data/unittests/div_test.rb +188 -183
- data/unittests/div_xpath_test.rb +96 -96
- data/unittests/errorchecker_test.rb +22 -22
- data/unittests/filefield_test.rb +39 -40
- data/unittests/filefield_xpath_test.rb +33 -33
- data/unittests/form_test.rb +280 -293
- data/unittests/form_xpath_test.rb +252 -253
- data/unittests/frame_test.rb +155 -157
- data/unittests/google_form_test.rb +15 -15
- data/unittests/html/JavascriptClick.html +39 -39
- data/unittests/html/blankpage.html +11 -11
- data/unittests/html/buttons1.html +40 -40
- data/unittests/html/checkboxes1.html +89 -89
- data/unittests/html/complex_table.html +36 -36
- data/unittests/html/cssTest.html +42 -42
- data/unittests/html/depot_store.html +51 -51
- data/unittests/html/div.html +93 -93
- data/unittests/html/div_xml.html +20 -20
- data/unittests/html/fileupload.html +45 -45
- data/unittests/html/formTest1.html +38 -38
- data/unittests/html/forms2.html +44 -44
- data/unittests/html/forms3.html +131 -131
- data/unittests/html/forms4.html +27 -27
- data/unittests/html/frame_buttons.html +3 -3
- data/unittests/html/frame_links.html +3 -3
- data/unittests/html/frame_multi.html +4 -4
- data/unittests/html/google_india.html +107 -107
- data/unittests/html/iframeTest.html +12 -12
- data/unittests/html/iframeTest1.html +6 -6
- data/unittests/html/iframeTest2.html +5 -5
- data/unittests/html/images1.html +66 -66
- data/unittests/html/javascriptevents.html +35 -35
- data/unittests/html/link_pass.html +10 -10
- data/unittests/html/links1.html +38 -38
- data/unittests/html/links2.html +10 -10
- data/unittests/html/links_multi.html +14 -14
- data/unittests/html/list_matters.html +720 -720
- data/unittests/html/lists.html +17 -17
- data/unittests/html/map_test.html +31 -31
- data/unittests/html/modal_dialog.html +10 -10
- data/unittests/html/modal_dialog_launcher.html +11 -11
- data/unittests/html/nestedFrames.html +6 -6
- data/unittests/html/new_browser.html +16 -16
- data/unittests/html/pass.html +12 -12
- data/unittests/html/popups1.html +59 -59
- data/unittests/html/pre.html +27 -27
- data/unittests/html/radioButtons1.html +71 -71
- data/unittests/html/select_tealeaf.html +54 -54
- data/unittests/html/selectboxes1.html +52 -55
- data/unittests/html/simple_table.html +26 -26
- data/unittests/html/simple_table_buttons.html +104 -104
- data/unittests/html/simple_table_columns.html +76 -76
- data/unittests/html/table1.html +181 -181
- data/unittests/html/tableCell_using_xpath.html +19 -19
- data/unittests/html/textarea.html +30 -30
- data/unittests/html/textfields1.html +88 -88
- data/unittests/html/textsearch.html +44 -44
- data/unittests/html/wallofcheckboxes.html +1003 -1003
- data/unittests/html/xpath_nbsp.html +12 -12
- data/unittests/ie_exists_test.rb +33 -33
- data/unittests/ie_mock.rb +94 -94
- data/unittests/ie_test.rb +51 -50
- data/unittests/images_test.rb +157 -157
- data/unittests/images_xpath_test.rb +91 -91
- data/unittests/links_multi_test.rb +48 -48
- data/unittests/links_test.rb +175 -177
- data/unittests/links_xpath_test.rb +39 -39
- data/unittests/map_test.rb +98 -98
- data/unittests/minmax_test.rb +31 -31
- data/unittests/navigate_test.rb +39 -39
- data/unittests/nbsp_xpath_test.rb +16 -16
- data/unittests/non_core_tests.rb +12 -12
- data/unittests/other/WindowLogonExample.rb +27 -27
- data/unittests/other/WindowLogonExtra.rb +6 -6
- data/unittests/other/all_tests_concurrent.rb +57 -57
- data/unittests/{windows → other}/jscriptExtraAlert.rb +6 -6
- data/unittests/{windows → other}/jscriptExtraConfirmCancel.rb +6 -6
- data/unittests/{windows → other}/jscriptExtraConfirmOk.rb +6 -6
- data/unittests/{windows → other}/jscriptPushButton.rb +6 -6
- data/unittests/{windows → other}/jscript_test.rb +63 -63
- data/unittests/other/navigate_exception_test.rb +24 -24
- data/unittests/other/rexml_unit_test.rb +27 -24
- data/unittests/other/screen_capture_test.rb +54 -54
- data/unittests/other/testcase_method_order_test.rb +35 -35
- data/unittests/other/testcase_verify_test.rb +24 -24
- data/unittests/other/wait_until_test.rb +99 -99
- data/unittests/pagecontainstext_test.rb +69 -69
- data/unittests/parent_child_test.rb +43 -43
- data/unittests/perf_test.rb +20 -20
- data/unittests/popups_test.rb +43 -43
- data/unittests/pre_test.rb +53 -53
- data/unittests/radios_test.rb +212 -212
- data/unittests/radios_xpath_test.rb +101 -101
- data/unittests/security_setting_test.rb +23 -23
- data/unittests/selectbox_test.rb +148 -139
- data/unittests/selectbox_xpath_test.rb +113 -113
- data/unittests/setup.rb +77 -75
- data/unittests/speed_settings_test.rb +67 -65
- data/unittests/table_cell_using_xpath_test.rb +35 -35
- data/unittests/table_test.rb +376 -362
- data/unittests/table_xpath_test.rb +110 -110
- data/unittests/test_tests.rb +9 -9
- data/unittests/textarea_test.rb +92 -92
- data/unittests/textarea_xpath_test.rb +78 -78
- data/unittests/textfield_for_ch_char_test.rb +31 -29
- data/unittests/textfields_test.rb +218 -218
- data/unittests/textfields_xpath_test.rb +111 -111
- data/unittests/window_tests.rb +10 -7
- data/unittests/windows/attach_to_existing_window_test.rb +53 -52
- data/unittests/windows/attach_to_new_window_test.rb +83 -82
- data/unittests/windows/close_window_test.rb +20 -20
- data/unittests/windows/frame_links_test.rb +25 -25
- data/unittests/windows/ie-each_test.rb +47 -47
- data/unittests/windows/iedialog_test.rb +54 -54
- data/unittests/windows/js_events_test.rb +55 -55
- data/unittests/windows/modal_dialog_test.rb +128 -126
- data/unittests/windows/new_test.rb +57 -55
- data/unittests/windows/open_close_test.rb +18 -18
- data/unittests/windows/send_keys_test.rb +33 -32
- data/unittests/xpath_tests.rb +10 -10
- metadata +20 -20
- data/lib/watir/contrib/visible.rb +0 -47
- data/unittests/iostring.rb +0 -30
- data/unittests/iostring_test.rb +0 -48
data/lib/watir/utils.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
# watir/utils.rb
|
2
|
-
|
3
|
-
module Watir
|
4
|
-
module Utils
|
5
|
-
|
6
|
-
# Eval the provided block. If a WIN32OLERuntimeError is raised by the block,
|
7
|
-
# return false.
|
8
|
-
def suppress_ole_error
|
9
|
-
begin
|
10
|
-
yield
|
11
|
-
true
|
12
|
-
rescue WIN32OLERuntimeError
|
13
|
-
false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
1
|
+
# watir/utils.rb
|
2
|
+
|
3
|
+
module Watir
|
4
|
+
module Utils
|
5
|
+
|
6
|
+
# Eval the provided block. If a WIN32OLERuntimeError is raised by the block,
|
7
|
+
# return false.
|
8
|
+
def suppress_ole_error
|
9
|
+
begin
|
10
|
+
yield
|
11
|
+
true
|
12
|
+
rescue WIN32OLERuntimeError
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
20
|
|
data/lib/watir/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module Watir
|
2
|
-
class IE
|
3
|
-
VERSION = '1.6.
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Watir
|
2
|
+
class IE
|
3
|
+
VERSION = '1.6.5'
|
4
|
+
end
|
5
|
+
end
|
data/lib/watir/watir_simple.rb
CHANGED
@@ -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 <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
|