watir 1.6.6 → 1.6.7.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +29 -0
- data/LICENSE +34 -0
- data/VERSION +1 -1
- data/lib/watir/container.rb +2 -1
- data/lib/watir/contrib/enabled_popup.rb +1 -1
- data/lib/watir/core.rb +6 -4
- data/lib/watir/element.rb +6 -1
- data/lib/watir/frame.rb +1 -1
- data/lib/watir/ie-class.rb +3 -2
- data/lib/watir/ie-process.rb +1 -1
- data/lib/watir/ie.rb +1 -39
- data/lib/watir/input_elements.rb +7 -1
- data/lib/watir/locator.rb +10 -3
- data/lib/watir/module.rb +1 -3
- data/lib/watir/winClicker.rb +0 -36
- data/rakefile.rb +0 -30
- data/unittests/buttons_xpath_test.rb +0 -1
- data/unittests/checkbox_test.rb +0 -1
- data/unittests/checkbox_xpath_test.rb +0 -1
- data/unittests/css_test.rb +0 -1
- data/unittests/defer_test.rb +0 -1
- data/unittests/dialog_test.rb +0 -1
- data/unittests/div2_xpath_test.rb +0 -1
- data/unittests/div_test.rb +0 -1
- data/unittests/div_xpath_test.rb +0 -1
- data/unittests/element_test.rb +0 -1
- data/unittests/errorchecker_test.rb +0 -1
- data/unittests/filefield_xpath_test.rb +0 -1
- data/unittests/form_test.rb +0 -1
- data/unittests/form_xpath_test.rb +0 -1
- data/unittests/frame_test.rb +73 -55
- data/unittests/google_form_test.rb +0 -1
- data/unittests/html/blankpage.html +0 -1
- data/unittests/html/buttons1.html +0 -1
- data/unittests/html/checkboxes1.html +0 -1
- data/unittests/html/complex_table.html +0 -1
- data/unittests/html/div.html +0 -1
- data/unittests/html/fileupload.html +0 -1
- data/unittests/html/formTest1.html +0 -1
- data/unittests/html/forms2.html +0 -1
- data/unittests/html/forms3.html +0 -1
- data/unittests/html/forms4.html +0 -1
- data/unittests/html/images1.html +0 -2
- data/unittests/html/links1.html +0 -1
- data/unittests/html/links_multi.html +0 -2
- data/unittests/html/map_test.html +0 -1
- data/unittests/html/popups1.html +0 -1
- data/unittests/html/radioButtons1.html +0 -1
- data/unittests/html/selectboxes1.html +0 -1
- data/unittests/html/simple_table.html +0 -1
- data/unittests/html/simple_table_columns.html +0 -1
- data/unittests/html/table1.html +0 -3
- data/unittests/html/textfields1.html +0 -2
- data/unittests/html/xpath_nbsp.html +0 -1
- data/unittests/ie_exists_test.rb +0 -1
- data/unittests/ie_test.rb +0 -1
- data/unittests/images_test.rb +0 -1
- data/unittests/images_xpath_test.rb +0 -1
- data/unittests/links_multi_test.rb +0 -1
- data/unittests/links_test.rb +0 -1
- data/unittests/links_xpath_test.rb +0 -1
- data/unittests/minmax_test.rb +0 -1
- data/unittests/navigate_test.rb +0 -1
- data/unittests/nbsp_xpath_test.rb +0 -1
- data/unittests/other/jscript_test.rb +0 -1
- data/unittests/other/navigate_exception_test.rb +0 -1
- data/unittests/other/screen_capture_test.rb +0 -1
- data/unittests/other/wait_until_test.rb +3 -0
- data/unittests/pagecontainstext_test.rb +0 -1
- data/unittests/popups_test.rb +0 -2
- data/unittests/pre_test.rb +0 -1
- data/unittests/radios_test.rb +0 -1
- data/unittests/radios_xpath_test.rb +0 -1
- data/unittests/selectbox_test.rb +0 -1
- data/unittests/selectbox_xpath_test.rb +0 -1
- data/unittests/setup.rb +1 -1
- data/unittests/speed_settings_test.rb +0 -1
- data/unittests/table_cell_using_xpath_test.rb +0 -1
- data/unittests/table_test.rb +0 -2
- data/unittests/table_xpath_test.rb +0 -1
- data/unittests/textarea_test.rb +0 -1
- data/unittests/textarea_xpath_test.rb +0 -1
- data/unittests/textfields_test.rb +0 -1
- data/unittests/textfields_xpath_test.rb +0 -1
- data/unittests/windows/attach_to_existing_window_test.rb +0 -1
- data/unittests/windows/attach_to_new_window_test.rb +0 -1
- data/unittests/windows/close_window_test.rb +0 -1
- data/unittests/windows/frame_links_test.rb +1 -3
- data/unittests/windows/ie-each_test.rb +1 -3
- data/unittests/windows/iedialog_test.rb +0 -1
- data/unittests/windows/js_events_test.rb +0 -1
- data/unittests/windows/modal_dialog_test.rb +0 -1
- data/unittests/windows/send_keys_test.rb +0 -1
- data/watir.gemspec +2 -2
- metadata +21 -17
- data/lib/watir/datahandler.rb +0 -107
- data/lib/watir/watir_simple.rb +0 -475
data/lib/watir/datahandler.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'watir/win32ole'
|
2
|
-
|
3
|
-
class String
|
4
|
-
|
5
|
-
def pred
|
6
|
-
self[0..-2] << (self[-1]-1).chr
|
7
|
-
end
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
class DataHandler
|
12
|
-
|
13
|
-
# This allows you to put data in a csv file or an xls file and access it in your scripts for
|
14
|
-
# a data driven approach.
|
15
|
-
#
|
16
|
-
# You can supply a file with extension csv or xls and it will just work
|
17
|
-
#
|
18
|
-
# e.g.
|
19
|
-
# require 'datahandler'
|
20
|
-
# d = DataHandler.new("data.csv")
|
21
|
-
# loginId = d.data[0].LoginId --> line 1 of the csv file and column LoginId
|
22
|
-
# pin = d.data[0].Pin --> line 1 of the cvs file and column Pin
|
23
|
-
#
|
24
|
-
# b = Datahandler.new("data.xls")
|
25
|
-
# loginId = b.data[0].LoginId --> line 1 of workbook 1 of the xls file with column LoginId
|
26
|
-
#
|
27
|
-
# Remember that line 1 of the data is referenced by using 0 - and this excludes the header line.
|
28
|
-
#
|
29
|
-
def initialize(datafile)
|
30
|
-
|
31
|
-
# if the data files are in the same dir as the one you execute from this works
|
32
|
-
directory = `dir`
|
33
|
-
directory.match(/Directory of(.+)$/)
|
34
|
-
working_directory = $1.to_s.gsub(/\\/,"/").gsub(/^\s/,"")
|
35
|
-
file = "#{working_directory.chomp}\\#{datafile}"
|
36
|
-
|
37
|
-
# otherwise it will take the location you specify
|
38
|
-
if File.exists?(file)
|
39
|
-
@datafile = file
|
40
|
-
else
|
41
|
-
@datafile = datafile
|
42
|
-
end
|
43
|
-
|
44
|
-
@excel = WIN32OLE::new('excel.Application')
|
45
|
-
@workbook = @excel.Workbooks.Open(@datafile)
|
46
|
-
@worksheet = @workbook.Worksheets(1)
|
47
|
-
@excel['Visible'] = false
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
def csv_data
|
52
|
-
csv_data = File.readlines(@datafile)
|
53
|
-
header = csv_data[0].split(",")
|
54
|
-
header.each{|z| z.chomp!}
|
55
|
-
data = Struct.new("Data", *header)
|
56
|
-
csv_data.shift
|
57
|
-
data_array = []
|
58
|
-
csv_data.each do |line|
|
59
|
-
line.each{|z| line.chomp!}
|
60
|
-
data_array << data.new(*line.split(","))
|
61
|
-
end
|
62
|
-
return data_array
|
63
|
-
end
|
64
|
-
|
65
|
-
def number_columns
|
66
|
-
column = last_column = "a"
|
67
|
-
while @worksheet.Range("a1:#{column}1")['Value']
|
68
|
-
if !@worksheet.Range("#{column}1")['Value']
|
69
|
-
last_column = column.pred
|
70
|
-
break
|
71
|
-
end
|
72
|
-
column.succ!
|
73
|
-
end
|
74
|
-
last_column
|
75
|
-
end
|
76
|
-
|
77
|
-
def xls_data
|
78
|
-
line = "1"
|
79
|
-
data = []
|
80
|
-
while @worksheet.Range("a#{line}")['Value']
|
81
|
-
data << @worksheet.Range("a#{line}:#{number_columns}#{line}")['Value']
|
82
|
-
line.succ!
|
83
|
-
end
|
84
|
-
|
85
|
-
header = data[0].flatten
|
86
|
-
dataObject = Struct.new("DataObject", *header)
|
87
|
-
data.shift
|
88
|
-
data_array = []
|
89
|
-
data.each do |line|
|
90
|
-
data_array << dataObject.new(*line.flatten)
|
91
|
-
end
|
92
|
-
@excel.Quit
|
93
|
-
@excel = nil
|
94
|
-
GC.start
|
95
|
-
data_array
|
96
|
-
end
|
97
|
-
|
98
|
-
def data
|
99
|
-
extension = @datafile.split(".")[-1]
|
100
|
-
if extension == "xls"
|
101
|
-
xls_data
|
102
|
-
elsif extension == "csv"
|
103
|
-
csv_data
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
data/lib/watir/watir_simple.rb
DELETED
@@ -1,475 +0,0 @@
|
|
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
|