awetestlib 0.1.29pre3 → 0.1.29pre4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +16 -8
- data/awetestlib.windows.gemspec +42 -41
- data/awetestlib_osx.gemspec +41 -47
- data/bin/awetestlib-android-setup.rb +2 -1
- data/bin/awetestlib-cucumber-setup.rb +2 -1
- data/bin/awetestlib-driver-setup.rb +1 -0
- data/bin/awetestlib-helpers.rb +2 -2
- data/bin/awetestlib-mobile-app-setup.rb +1 -0
- data/bin/awetestlib-netbeans-setup.rb +2 -1
- data/bin/awetestlib-regression-setup.rb +26 -12
- data/bin/awetestlib-rubymine-setup.rb +9 -4
- data/images/netbeans1.jpg +0 -0
- data/images/netbeans2.jpg +0 -0
- data/images/netbeans3.jpg +0 -0
- data/images/netbeans4.jpg +0 -0
- data/images/netbeans5.jpg +0 -0
- data/images/rubymine1.jpg +0 -0
- data/images/rubymine2.jpg +0 -0
- data/images/rubymine3.jpg +0 -0
- data/images/rubymine4.jpg +0 -0
- data/images/scripting1.png +0 -0
- data/images/scripting2.png +0 -0
- data/images/scripting3.png +0 -0
- data/images/scripting4.png +0 -0
- data/lib/awetestlib/logging.rb +6 -6
- data/lib/awetestlib/regression/browser.rb +15 -12
- data/lib/awetestlib/regression/drag_and_drop.rb +421 -421
- data/lib/awetestlib/regression/runner.rb +311 -307
- data/lib/awetestlib/regression/tables.rb +627 -627
- data/lib/awetestlib/regression/user_input.rb +576 -576
- data/lib/awetestlib/regression/utilities.rb +1056 -1046
- data/lib/awetestlib/regression/validations.rb +2 -1
- data/lib/version.rb +2 -2
- data/netbeans_setup.md +30 -30
- data/rubymine_setup.md +24 -24
- data/setup_samples/sample_cucumber/features/step_definitions/predefined_steps.rb +303 -25
- metadata +160 -34
- checksums.yaml +0 -7
@@ -1,576 +1,576 @@
|
|
1
|
-
module Awetestlib
|
2
|
-
# Awetest DSL for browser based testing.
|
3
|
-
module Regression
|
4
|
-
# Methods covering user interactions with the browser.
|
5
|
-
module UserInput
|
6
|
-
|
7
|
-
# Click a specific DOM element identified by one of its attributes (*how*) and that attribute's value (*what*).
|
8
|
-
#
|
9
|
-
# @example
|
10
|
-
# # html for a link element:
|
11
|
-
# # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
|
12
|
-
#
|
13
|
-
# click(browser, :link, :text, 'Pickaxe')
|
14
|
-
#
|
15
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
16
|
-
# @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
|
17
|
-
# Some common values are :link, :button, :image, :div, :span.
|
18
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
19
|
-
# Valid values depend on the kind of element.
|
20
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
21
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
22
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
23
|
-
# @return [Boolean] True if the Watir or Watir-webdriver function does not throw an exception.
|
24
|
-
#
|
25
|
-
def click(browser, element, how, what, desc = '')
|
26
|
-
#debug_to_log("#{__method__}: #{element}, #{how}, #{what}")
|
27
|
-
msg = build_message("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc)
|
28
|
-
case element
|
29
|
-
when :link
|
30
|
-
browser.link(how, what).click
|
31
|
-
when :button
|
32
|
-
browser.button(how, what).click
|
33
|
-
when :image
|
34
|
-
browser.image(how, what).click
|
35
|
-
when :radio
|
36
|
-
case how
|
37
|
-
when :index
|
38
|
-
set_radio_by_index(browser, what, desc)
|
39
|
-
else
|
40
|
-
browser.radio(how, what).set
|
41
|
-
end
|
42
|
-
when :span
|
43
|
-
browser.span(how, what).click
|
44
|
-
when :div
|
45
|
-
browser.div(how, what).click
|
46
|
-
when :cell
|
47
|
-
browser.cell(how, what).click
|
48
|
-
else
|
49
|
-
browser.element(how, what).click
|
50
|
-
end
|
51
|
-
passed_to_log(msg)
|
52
|
-
true
|
53
|
-
rescue
|
54
|
-
failed_to_log("Unable to #{msg}. '#{$!}'")
|
55
|
-
end
|
56
|
-
|
57
|
-
# Click a specific DOM element by one of its attributes (*how) and that attribute's value (*what) and
|
58
|
-
# do not wait for the browser to finish reloading. Used when a modal popup or alert is expected. Allows the script
|
59
|
-
# to keep running so the popup can be handled.
|
60
|
-
# @todo handle using Watir Webdriver which does not need no_wait.
|
61
|
-
#
|
62
|
-
# @example
|
63
|
-
# # html for a link element:
|
64
|
-
# # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
|
65
|
-
#
|
66
|
-
# click_no_wait(browser, :link, :text, 'Pickaxe')
|
67
|
-
#
|
68
|
-
# @see #click
|
69
|
-
#
|
70
|
-
# @param (see #click)
|
71
|
-
# @return (see #click)
|
72
|
-
#
|
73
|
-
def click_no_wait(browser, element, how, what, desc = '')
|
74
|
-
msg = build_message("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc)
|
75
|
-
begin
|
76
|
-
case element
|
77
|
-
when :link
|
78
|
-
browser.link(how, what).click_no_wait
|
79
|
-
when :button
|
80
|
-
browser.button(how, what).click_no_wait
|
81
|
-
when :image
|
82
|
-
browser.image(how, what).click_no_wait
|
83
|
-
when :radio
|
84
|
-
case how
|
85
|
-
when :index
|
86
|
-
set_radio_no_wait_by_index(browser, what, desc)
|
87
|
-
else
|
88
|
-
browser.radio(how, what).click_no_wait
|
89
|
-
end
|
90
|
-
when :span
|
91
|
-
browser.span(how, what).click_no_wait
|
92
|
-
when :div
|
93
|
-
browser.div(how, what).click_no_wait
|
94
|
-
when :checkbox
|
95
|
-
browser.checkbox(how, what).click_no_wait
|
96
|
-
when :cell
|
97
|
-
browser.cell(how, what).click_no_wait
|
98
|
-
else
|
99
|
-
browser.element(how, what).click_no_wait
|
100
|
-
end
|
101
|
-
rescue => e
|
102
|
-
unless rescue_me(e, __method__, rescue_me_command(element, how, what, :click_no_wait), "#{browser.class}")
|
103
|
-
raise e
|
104
|
-
end
|
105
|
-
end
|
106
|
-
passed_to_log(msg)
|
107
|
-
true
|
108
|
-
rescue
|
109
|
-
failed_to_log("Unable to #{msg} '#{$!}'")
|
110
|
-
sleep_for(1)
|
111
|
-
end
|
112
|
-
|
113
|
-
# Click an image element identified by the value of its *:src* attribute and its index
|
114
|
-
# within the array of image elements with src containing <b>*what*</b> and
|
115
|
-
# within the container referred to by <b>*browser*</b>.
|
116
|
-
# @param [Watir::Browser, Watir::Container] browser A reference to the browser window or container element to be tested.
|
117
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
118
|
-
# @param [Fixnum] index An integer that indicates the index of the element within the array of image elements with src containing <b>*what*</b>.
|
119
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
120
|
-
# @return (see #click)
|
121
|
-
def click_img_by_src_and_index(browser, what, index, desc = '')
|
122
|
-
msg = "Click image by src='#{what}' and index=#{index}"
|
123
|
-
msg << " #{desc}" if desc.length > 0
|
124
|
-
browser.image(:src => what, :index => index).click
|
125
|
-
passed_to_log(msg)
|
126
|
-
true
|
127
|
-
rescue
|
128
|
-
failed_to_log("Unable to #{msg} '#{$!}'")
|
129
|
-
end
|
130
|
-
|
131
|
-
# Click the first row which contains a particular string in a table identified by attribute and value.
|
132
|
-
# A specific column in the table can also be specified.
|
133
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
134
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
135
|
-
# Valid values depend on the kind of element.
|
136
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
137
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
138
|
-
# @param [String] text Full text string to be found in the table row.
|
139
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
140
|
-
# @param [Fixnum] column Integer indicating the column to search for the text string.
|
141
|
-
# If not supplied all columns will be checked.
|
142
|
-
# @return (see #click)
|
143
|
-
#
|
144
|
-
def click_table_row_with_text(browser, how, what, text, desc = '', column = nil)
|
145
|
-
msg = build_message("Click row with text #{text} in table :#{how}=>'#{what}.", desc)
|
146
|
-
table = get_table(browser, how, what, desc)
|
147
|
-
if table
|
148
|
-
index = get_index_of_row_with_text(table, text, column)
|
149
|
-
if index
|
150
|
-
table[index].click
|
151
|
-
passed_to_log(msg)
|
152
|
-
index
|
153
|
-
else
|
154
|
-
failed_to_log("#{msg} Row not found.")
|
155
|
-
end
|
156
|
-
else
|
157
|
-
failed_to_log("#{msg} Table not found.")
|
158
|
-
end
|
159
|
-
rescue
|
160
|
-
failed_to_log("Unable to #{msg}: '#{$!}'")
|
161
|
-
end
|
162
|
-
|
163
|
-
# Double click the first row which contains a particular string in a table identified by attribute and value.
|
164
|
-
# A specific column in the table can also be specified.
|
165
|
-
# Uses fire_event method in Watir to send 'onDblClick' event.
|
166
|
-
# @param (see #click_table_row_with_text)
|
167
|
-
# @return (see #click)
|
168
|
-
#
|
169
|
-
def double_click_table_row_with_text(browser, how, what, text, desc = '', column = nil)
|
170
|
-
msg = build_message("Double click row with text #{text} in table :#{how}=>'#{what}.", desc)
|
171
|
-
table = get_table(browser, how, what, desc)
|
172
|
-
if table
|
173
|
-
index = get_index_of_row_with_text(table, text, column)
|
174
|
-
if index
|
175
|
-
table[index].fire_event('ondblclick')
|
176
|
-
passed_to_log(msg)
|
177
|
-
index
|
178
|
-
else
|
179
|
-
failed_to_log("#{msg} Row not found.")
|
180
|
-
end
|
181
|
-
else
|
182
|
-
failed_to_log("#{msg} Table not found.")
|
183
|
-
end
|
184
|
-
rescue
|
185
|
-
failed_to_log("Unable to #{msg}: '#{$!}'")
|
186
|
-
end
|
187
|
-
|
188
|
-
# Click a specifific button on a popup window.
|
189
|
-
# (Windows only)
|
190
|
-
# @param [String] title A string starting at the beginning of the title which uniquely identifies the popup window.
|
191
|
-
# @param [String] button The value displayed for the button (e.g. OK, Yes, Cancel, etc)
|
192
|
-
# @param [Fixnum] wait Integer indicating the number of seconds to wait for the popup window to appear.
|
193
|
-
# @return (see #click)
|
194
|
-
def click_popup_button(title, button, wait= 9, user_input=nil)
|
195
|
-
#TODO: is winclicker still viable/available?
|
196
|
-
wc = WinClicker.new
|
197
|
-
if wc.clickWindowsButton(title, button, wait)
|
198
|
-
passed_to_log("Window '#{title}' button '#{button}' found and clicked.")
|
199
|
-
true
|
200
|
-
else
|
201
|
-
failed_to_log("Window '#{title}' button '#{button}' not found. (#{__LINE__})")
|
202
|
-
end
|
203
|
-
wc = nil
|
204
|
-
# get a handle if one exists
|
205
|
-
# hwnd = $ie.enabled_popup(wait)
|
206
|
-
# if (hwnd) # yes there is a popup
|
207
|
-
# w = WinClicker.new
|
208
|
-
# if ( user_input )
|
209
|
-
# w.setTextValueForFileNameField( hwnd, "#{user_input}" )
|
210
|
-
# end
|
211
|
-
# # I put this in to see the text being input it is not necessary to work
|
212
|
-
# sleep 3
|
213
|
-
# # "OK" or whatever the name on the button is
|
214
|
-
# w.clickWindowsButton_hwnd( hwnd, "#{button}" )
|
215
|
-
# #
|
216
|
-
# # this is just cleanup
|
217
|
-
# w=nil
|
218
|
-
# end
|
219
|
-
end
|
220
|
-
|
221
|
-
# Select option from select list (dropdown) already identified and passed to the method. Selection can be by *:text* or *:value*.
|
222
|
-
# @param [Watir::SelectList] list A reference to the specific select list object.
|
223
|
-
# @param [Symbol] how Either :text or :value.
|
224
|
-
# @param [String/Rexexp] what A string or regular expression that will uniquely identify the option to select.
|
225
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
226
|
-
# @param [Boolean] nofail If true do not log a failed message if the option is not found in the select list.
|
227
|
-
# @return (see #click)
|
228
|
-
def select_option_from_list(list, how, what, desc = '', nofail = false)
|
229
|
-
msg = build_message("Select :#{how}=>'#{what}'", desc)
|
230
|
-
ok = true
|
231
|
-
if list
|
232
|
-
case how
|
233
|
-
when :text
|
234
|
-
list.select(what) #TODO: regex?
|
235
|
-
when :value
|
236
|
-
list.select_value(what) #TODO: regex?
|
237
|
-
when :index
|
238
|
-
list.select(list.getAllContents[what.to_i])
|
239
|
-
else
|
240
|
-
failed_to_log("#{msg} Select by #{how} not supported.")
|
241
|
-
ok = false
|
242
|
-
end
|
243
|
-
if ok
|
244
|
-
passed_to_log(msg)
|
245
|
-
true
|
246
|
-
else
|
247
|
-
if nofail
|
248
|
-
passed_to_log("#{msg} Option not found. No Fail specified.")
|
249
|
-
true
|
250
|
-
else
|
251
|
-
failed_to_log("#{msg} Option not found.")
|
252
|
-
end
|
253
|
-
end
|
254
|
-
else
|
255
|
-
failed_to_log("#{msg} Select list not found.")
|
256
|
-
end
|
257
|
-
rescue
|
258
|
-
failed_to_log("Unable to #{msg} '#{$!}'")
|
259
|
-
end
|
260
|
-
|
261
|
-
# Select option from select list identified by *how* and *what*. Option is identified by *which* and *value*
|
262
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
263
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
264
|
-
# Valid values depend on the kind of element.
|
265
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
266
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
267
|
-
# @param [Symbol] which Either :text or :value.
|
268
|
-
# @param [String/Rexexp] option A string or regular expression that will uniquely identify the option to select.
|
269
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
270
|
-
# @param [Boolean] nofail If true do not log a failed message if the option is not found in the select list.
|
271
|
-
# @return (see #click)
|
272
|
-
def select_option(browser, how, what, which, option, desc = '', nofail = false)
|
273
|
-
list = browser.select_list(how, what)
|
274
|
-
msg = build_message("from list with :#{how}=>'#{what}", desc)
|
275
|
-
select_option_from_list(list, which, option, msg, nofail)
|
276
|
-
end
|
277
|
-
|
278
|
-
# Set radio button or checkbox to selected.
|
279
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
280
|
-
# @param [Symbol] element The kind of element to click. Must be either :radio or :checkbox.
|
281
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
282
|
-
# Valid values depend on the kind of element.
|
283
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
284
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
285
|
-
# @param [String, Regexp] value A string or a regular expression to be found in the *:value* attribute of the radio or checkbox.
|
286
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
287
|
-
# @return (see #click)
|
288
|
-
def set(browser, element, how, what, value = nil, desc = '')
|
289
|
-
msg = "Set #{element} #{how}=>'#{what}' "
|
290
|
-
msg << ", :value=>#{value} " if value
|
291
|
-
msg << " '#{desc}' " if desc.length > 0
|
292
|
-
case element
|
293
|
-
when :radio
|
294
|
-
browser.radio(how, what).set
|
295
|
-
when :checkbox
|
296
|
-
browser.checkbox(how, what).set
|
297
|
-
else
|
298
|
-
failed_to_log("#{__method__}: #{element} not supported")
|
299
|
-
end
|
300
|
-
passed_to_log(msg)
|
301
|
-
true
|
302
|
-
rescue
|
303
|
-
failed_to_log("#{msg} '#{$!}'")
|
304
|
-
end
|
305
|
-
|
306
|
-
# Set file field element, identified by *how* and *what*, to a specified file path and name.
|
307
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
308
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
309
|
-
# Valid values depend on the kind of element.
|
310
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
311
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
312
|
-
# @param [String] filespec The full path and name of the target file.
|
313
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
314
|
-
# @return (see #click)
|
315
|
-
def set_file_field(browser, how, what, filespec, desc = '')
|
316
|
-
msg = build_message("#{__method__.to_s.humanize} #{how}=>#{what} to '#{filespec}.", desc)
|
317
|
-
ff = browser.file_field(how, what)
|
318
|
-
if ff
|
319
|
-
ff.set filespec
|
320
|
-
sleep_for(8)
|
321
|
-
passed_to_log(msg)
|
322
|
-
true
|
323
|
-
else
|
324
|
-
failed_to_log("#{msg} File field not found.")
|
325
|
-
end
|
326
|
-
rescue
|
327
|
-
failed_to_log("Unable to #{msg} '#{$!}'")
|
328
|
-
end
|
329
|
-
|
330
|
-
# Set radio button as selected using two element attributes.
|
331
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
332
|
-
# @param [Symbol] how1 The first element attribute used to identify the specific element.
|
333
|
-
# Valid values depend on the kind of element.
|
334
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
335
|
-
# @param [String, Regexp] what1 A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
336
|
-
# @param [Symbol] how2 The second element attribute used to identify the specific element.
|
337
|
-
# @param [String, Regexp] what2 A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
338
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
339
|
-
# @return (see #click)
|
340
|
-
def set_radio_two_attributes(browser, how1, what1, how2, what2, desc = '')
|
341
|
-
msg = build_message("Set radio #{how1}='#{what1}', #{how2}= #{what2}", desc)
|
342
|
-
browser.radio(how1 => what1, how2 => what2).set
|
343
|
-
passed_to_log(msg)
|
344
|
-
true
|
345
|
-
rescue
|
346
|
-
failed_to_log("#{msg} '#{$!}'")
|
347
|
-
end
|
348
|
-
|
349
|
-
#def set_radio_no_wait_by_index(browser, index, desc = '')
|
350
|
-
# #TODO: Not supported by Watir 1.8.x
|
351
|
-
# msg = "Radio :index=#{index} "
|
352
|
-
# radios = browser.radios
|
353
|
-
# debug_to_log("\n#{radios}")
|
354
|
-
# radio = radios[index]
|
355
|
-
# debug_to_log("\n#{radio}")
|
356
|
-
# radio.click_no_wait
|
357
|
-
# msg << 'set ' + desc
|
358
|
-
# passed_to_log(msg)
|
359
|
-
# true
|
360
|
-
#rescue
|
361
|
-
# msg << 'not found ' + desc
|
362
|
-
# failed_to_log("#{msg} (#{__LINE__})")
|
363
|
-
#end
|
364
|
-
|
365
|
-
# Clear (unset) radio, checkbox or text field as identified by the attribute specified in *how* with value *what*.
|
366
|
-
# It's *:value* attribute can also be used when needed by specifying *value* (Ignored for text_field).
|
367
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
368
|
-
# @param [Symbol] element The kind of element to clear. Must be :radio, :checkbox or :text_field.
|
369
|
-
# @param [Symbol] how The element attribute used to identify the specific checkbox.
|
370
|
-
# Valid values depend on the kind of element.
|
371
|
-
# Common values: :text, :id, :title, :name, :class.
|
372
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
373
|
-
# @param [String, Regexp] value A string or a regular expression to be found in the *:value* attribute of the element.
|
374
|
-
# In the case of text_field this is the string to be entered in the field.
|
375
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
376
|
-
# @return (see #click)
|
377
|
-
def clear(browser, element, how, what, value = nil, desc = '')
|
378
|
-
msg = "Clear #{element} #{how}=>'#{what}' "
|
379
|
-
msg << ", value=>#{value} " if value
|
380
|
-
msg << " '#{desc}' " if desc.length > 0
|
381
|
-
case element
|
382
|
-
when :radio
|
383
|
-
browser.radio(how, what).clear
|
384
|
-
when :checkbox
|
385
|
-
browser.checkbox(how, what).clear
|
386
|
-
when :text_field
|
387
|
-
browser.text_field(how, what).set('')
|
388
|
-
else
|
389
|
-
failed_to_log("#{__method__}: #{element} not supported")
|
390
|
-
end
|
391
|
-
passed_to_log(msg)
|
392
|
-
true
|
393
|
-
rescue
|
394
|
-
failed_to_log("#{msg} '#{$!}'")
|
395
|
-
end
|
396
|
-
|
397
|
-
# Set text field as identified by the attribute specified in *how* with value in *what* to the string specified in *value*.
|
398
|
-
# This method differs from set() in that it validates that the text field has been set to the specified value.
|
399
|
-
# The value verification can be turned off by setting *skip_value_check* to true.
|
400
|
-
# This is useful when the text_field performs formatting on the entered string. See set_text_field_and_validate()
|
401
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
402
|
-
# @param [Symbol] how The element attribute used to identify the specific checkbox.
|
403
|
-
# Valid values depend on the kind of element.
|
404
|
-
# Common values: :text, :id, :title, :name, :class.
|
405
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
406
|
-
# @param [String] value A string to enter into the text field.
|
407
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
408
|
-
# @param [Boolean] skip_value_check Forces verification of value in text field to pass.
|
409
|
-
# @return (see #click)
|
410
|
-
def set_text_field(browser, how, what, value, desc = '', skip_value_check = false)
|
411
|
-
#TODO: fix this to handle Safari password field
|
412
|
-
msg = build_message("#{__method__.to_s.humanize} #{how}='#{what}' to '#{value}'", desc)
|
413
|
-
msg << " (Skip value check)" if skip_value_check
|
414
|
-
if browser.text_field(how, what).exists?
|
415
|
-
tf = browser.text_field(how, what)
|
416
|
-
tf.set(value)
|
417
|
-
if skip_value_check
|
418
|
-
passed_to_log(msg)
|
419
|
-
true
|
420
|
-
else
|
421
|
-
if tf.value == value
|
422
|
-
passed_to_log(msg)
|
423
|
-
true
|
424
|
-
else
|
425
|
-
failed_to_log("#{msg}: Found:'#{tf.value}'.")
|
426
|
-
end
|
427
|
-
end
|
428
|
-
else
|
429
|
-
failed_to_log("#{msg}: Textfield not found")
|
430
|
-
end
|
431
|
-
rescue
|
432
|
-
failed_to_log("Unable to '#{msg}': '#{$!}'")
|
433
|
-
end
|
434
|
-
|
435
|
-
alias set_textfield set_text_field
|
436
|
-
|
437
|
-
# Clear text field as identified by the attribute specified in *how* with value in *what* to the string specified in *value*.
|
438
|
-
# This method differs from set() in that 1( it uses the Watir #clear method, 2( it validates that the text field has been
|
439
|
-
# set to the specified value.
|
440
|
-
# The value verification can be turned off by setting *skip_value_check* to true.
|
441
|
-
# This is useful when the text_field performs formatting on the entered string. See set_text_field_and_validate()
|
442
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
443
|
-
# @param [Symbol] how The element attribute used to identify the specific checkbox.
|
444
|
-
# Valid values depend on the kind of element.
|
445
|
-
# Common values: :text, :id, :title, :name, :class.
|
446
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
447
|
-
# @param [Boolean] skip_value_check Forces verification of value in text field to pass.
|
448
|
-
# @return (see #click)
|
449
|
-
def clear_textfield(browser, how, what, skip_value_check = false)
|
450
|
-
msg1 = "Skip value check." if skip_value_check
|
451
|
-
msg = build_message("#{__method__.to_s.humanize} #{how}='#{what}'.", msg1)
|
452
|
-
if browser.text_field(how, what).exists?
|
453
|
-
tf = browser.text_field(how, what)
|
454
|
-
tf.clear
|
455
|
-
if tf.value == ''
|
456
|
-
passed_to_log(msg)
|
457
|
-
true
|
458
|
-
elsif skip_value_check
|
459
|
-
passed_to_log(msg)
|
460
|
-
true
|
461
|
-
else
|
462
|
-
failed_to_log("#{msg} Found:'#{tf.value}'.")
|
463
|
-
end
|
464
|
-
else
|
465
|
-
failed_to_log("#{msg} Textfield not found.")
|
466
|
-
end
|
467
|
-
rescue
|
468
|
-
failed_to_log("Unable to #{msg} '#{$!}'.")
|
469
|
-
end
|
470
|
-
|
471
|
-
#Enter a string into a text field element identified by an attribute type and a value.
|
472
|
-
#After the entry the value in the text field is validated against the *valid_value*. Use when the application reformats
|
473
|
-
#or performs edits on the input value.
|
474
|
-
|
475
|
-
# Set text field as identified by the attribute specified in *how* with value in *what* to the string specified in *value*.
|
476
|
-
# and verify that the text field is set to the string in *valid_value*.
|
477
|
-
#
|
478
|
-
# @example
|
479
|
-
# set_text_field_and_validate(browser, :id, 'text field id', '99999', 'Dollar format', '$99,999.00')
|
480
|
-
#
|
481
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
482
|
-
# @param [Symbol] how The element attribute used to identify the specific checkbox.
|
483
|
-
# Valid values depend on the kind of element.
|
484
|
-
# Common values: :text, :id, :title, :name, :class.
|
485
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
486
|
-
# @param [String] value A string to enter into the text field.
|
487
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output. Required in this method.
|
488
|
-
# @param [String] valid_value The expected value of the text field, e.g., following reformatting.
|
489
|
-
# @return (see #click)
|
490
|
-
def set_text_field_and_validate(browser, how, what, value, valid_value = nil, desc ='')
|
491
|
-
#NOTE: use when value and valid_value differ as with dollar reformatting
|
492
|
-
if set_text_field(browser, how, what, value, desc, true)
|
493
|
-
expected = valid_value ? valid_value : value
|
494
|
-
validate_textfield_value(browser, how, what, expected, desc)
|
495
|
-
end
|
496
|
-
rescue
|
497
|
-
failed_to_log("Unable to '#{msg}': '#{$!}'")
|
498
|
-
end
|
499
|
-
|
500
|
-
#def set_password_by_name(browser, name, value, desc = '', skip_value_check = false)
|
501
|
-
# set_text_field(browser, how, what, value, desc, skip_value_check)
|
502
|
-
# if browser.text_field(:name, name).exists?
|
503
|
-
# tf = browser.text_field(:name, name)
|
504
|
-
# # Workaround because browser.text_field doesn't work for password fields in Safari
|
505
|
-
# elsif @browserAbbrev.eql?("S")
|
506
|
-
# tf = browser.password(:name, name)
|
507
|
-
# end
|
508
|
-
# if tf.exists?
|
509
|
-
# tf.set(value)
|
510
|
-
# if tf.value == value
|
511
|
-
# passed_to_log("Set textfield name='#{name}' to '#{value}' #{desc}")
|
512
|
-
# true
|
513
|
-
# elsif skip_value_check
|
514
|
-
# passed_to_log("Set textfield name='#{name}' to '#{value}' #{desc} (skip value check)")
|
515
|
-
# true
|
516
|
-
# else
|
517
|
-
# failed_to_log("Set textfield name='#{name}' to '#{value}': Found:'#{tf.value}'. #{desc} (#{__LINE__})")
|
518
|
-
# end
|
519
|
-
# else
|
520
|
-
# failed_to_log("Textfield name='#{name}' not found to set to '#{value}'. #{desc} (#{__LINE__})")
|
521
|
-
# end
|
522
|
-
#rescue
|
523
|
-
# failed_to_log("Textfield name='#{name}' could not be set to '#{value}': '#{$!}'. #{desc} (#{__LINE__})")
|
524
|
-
#end
|
525
|
-
|
526
|
-
# Fire an event on a specific DOM element identified by one of its attributes and that attribute's value.
|
527
|
-
#
|
528
|
-
# @example
|
529
|
-
# # html for a link element:
|
530
|
-
# # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
|
531
|
-
#
|
532
|
-
# fire_event(browser, :link, :text, 'Pickaxe', 'onMouseOver')
|
533
|
-
#
|
534
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
535
|
-
# @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
|
536
|
-
# Some common values are :link, :button, :image, :div, :span.
|
537
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
538
|
-
# Valid values depend on the kind of element.
|
539
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
540
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
541
|
-
# @param [String] event A string identifying the event to be fired.
|
542
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
543
|
-
# @return (see #click)
|
544
|
-
#
|
545
|
-
def fire_event(browser, element, how, what, event, desc = '')
|
546
|
-
msg = build_message("#{element.to_s.titlecase}: #{how}=>'#{what}' event:'#{event}'", desc)
|
547
|
-
begin
|
548
|
-
case element
|
549
|
-
when :link
|
550
|
-
browser.link(how, what).fire_event(event)
|
551
|
-
when :button
|
552
|
-
browser.button(how, what).fire_event(event)
|
553
|
-
when :image
|
554
|
-
browser.image(how, what).fire_event(event)
|
555
|
-
when :span
|
556
|
-
browser.span(how, what).fire_event(event)
|
557
|
-
when :div
|
558
|
-
browser.div(how, what).fire_event(event)
|
559
|
-
else
|
560
|
-
browser.element(how, what).fire_event(event)
|
561
|
-
end
|
562
|
-
rescue => e
|
563
|
-
unless rescue_me(e, __method__, rescue_me_command(element, how, what, __method__.to_s, event), "#{browser.class}")
|
564
|
-
raise e
|
565
|
-
end
|
566
|
-
end
|
567
|
-
passed_to_log("Fire event: #{msg}. #{desc}")
|
568
|
-
true
|
569
|
-
rescue
|
570
|
-
failed_to_log("Unable to fire event: #{msg}. '#{$!}' #{desc}")
|
571
|
-
end
|
572
|
-
|
573
|
-
end
|
574
|
-
end
|
575
|
-
end
|
576
|
-
|
1
|
+
module Awetestlib
|
2
|
+
# Awetest DSL for browser based testing.
|
3
|
+
module Regression
|
4
|
+
# Methods covering user interactions with the browser.
|
5
|
+
module UserInput
|
6
|
+
|
7
|
+
# Click a specific DOM element identified by one of its attributes (*how*) and that attribute's value (*what*).
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # html for a link element:
|
11
|
+
# # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
|
12
|
+
#
|
13
|
+
# click(browser, :link, :text, 'Pickaxe')
|
14
|
+
#
|
15
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
16
|
+
# @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
|
17
|
+
# Some common values are :link, :button, :image, :div, :span.
|
18
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
19
|
+
# Valid values depend on the kind of element.
|
20
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
21
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
22
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
23
|
+
# @return [Boolean] True if the Watir or Watir-webdriver function does not throw an exception.
|
24
|
+
#
|
25
|
+
def click(browser, element, how, what, desc = '')
|
26
|
+
#debug_to_log("#{__method__}: #{element}, #{how}, #{what}")
|
27
|
+
msg = build_message("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc)
|
28
|
+
case element
|
29
|
+
when :link
|
30
|
+
browser.link(how, what).click
|
31
|
+
when :button
|
32
|
+
browser.button(how, what).click
|
33
|
+
when :image
|
34
|
+
browser.image(how, what).click
|
35
|
+
when :radio
|
36
|
+
case how
|
37
|
+
when :index
|
38
|
+
set_radio_by_index(browser, what, desc)
|
39
|
+
else
|
40
|
+
browser.radio(how, what).set
|
41
|
+
end
|
42
|
+
when :span
|
43
|
+
browser.span(how, what).click
|
44
|
+
when :div
|
45
|
+
browser.div(how, what).click
|
46
|
+
when :cell
|
47
|
+
browser.cell(how, what).click
|
48
|
+
else
|
49
|
+
browser.element(how, what).click
|
50
|
+
end
|
51
|
+
passed_to_log(msg)
|
52
|
+
true
|
53
|
+
rescue
|
54
|
+
failed_to_log("Unable to #{msg}. '#{$!}'")
|
55
|
+
end
|
56
|
+
|
57
|
+
# Click a specific DOM element by one of its attributes (*how) and that attribute's value (*what) and
|
58
|
+
# do not wait for the browser to finish reloading. Used when a modal popup or alert is expected. Allows the script
|
59
|
+
# to keep running so the popup can be handled.
|
60
|
+
# @todo handle using Watir Webdriver which does not need no_wait.
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# # html for a link element:
|
64
|
+
# # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
|
65
|
+
#
|
66
|
+
# click_no_wait(browser, :link, :text, 'Pickaxe')
|
67
|
+
#
|
68
|
+
# @see #click
|
69
|
+
#
|
70
|
+
# @param (see #click)
|
71
|
+
# @return (see #click)
|
72
|
+
#
|
73
|
+
def click_no_wait(browser, element, how, what, desc = '')
|
74
|
+
msg = build_message("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc)
|
75
|
+
begin
|
76
|
+
case element
|
77
|
+
when :link
|
78
|
+
browser.link(how, what).click_no_wait
|
79
|
+
when :button
|
80
|
+
browser.button(how, what).click_no_wait
|
81
|
+
when :image
|
82
|
+
browser.image(how, what).click_no_wait
|
83
|
+
when :radio
|
84
|
+
case how
|
85
|
+
when :index
|
86
|
+
set_radio_no_wait_by_index(browser, what, desc)
|
87
|
+
else
|
88
|
+
browser.radio(how, what).click_no_wait
|
89
|
+
end
|
90
|
+
when :span
|
91
|
+
browser.span(how, what).click_no_wait
|
92
|
+
when :div
|
93
|
+
browser.div(how, what).click_no_wait
|
94
|
+
when :checkbox
|
95
|
+
browser.checkbox(how, what).click_no_wait
|
96
|
+
when :cell
|
97
|
+
browser.cell(how, what).click_no_wait
|
98
|
+
else
|
99
|
+
browser.element(how, what).click_no_wait
|
100
|
+
end
|
101
|
+
rescue => e
|
102
|
+
unless rescue_me(e, __method__, rescue_me_command(element, how, what, :click_no_wait), "#{browser.class}")
|
103
|
+
raise e
|
104
|
+
end
|
105
|
+
end
|
106
|
+
passed_to_log(msg)
|
107
|
+
true
|
108
|
+
rescue
|
109
|
+
failed_to_log("Unable to #{msg} '#{$!}'")
|
110
|
+
sleep_for(1)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Click an image element identified by the value of its *:src* attribute and its index
|
114
|
+
# within the array of image elements with src containing <b>*what*</b> and
|
115
|
+
# within the container referred to by <b>*browser*</b>.
|
116
|
+
# @param [Watir::Browser, Watir::Container] browser A reference to the browser window or container element to be tested.
|
117
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
118
|
+
# @param [Fixnum] index An integer that indicates the index of the element within the array of image elements with src containing <b>*what*</b>.
|
119
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
120
|
+
# @return (see #click)
|
121
|
+
def click_img_by_src_and_index(browser, what, index, desc = '')
|
122
|
+
msg = "Click image by src='#{what}' and index=#{index}"
|
123
|
+
msg << " #{desc}" if desc.length > 0
|
124
|
+
browser.image(:src => what, :index => index).click
|
125
|
+
passed_to_log(msg)
|
126
|
+
true
|
127
|
+
rescue
|
128
|
+
failed_to_log("Unable to #{msg} '#{$!}'")
|
129
|
+
end
|
130
|
+
|
131
|
+
# Click the first row which contains a particular string in a table identified by attribute and value.
|
132
|
+
# A specific column in the table can also be specified.
|
133
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
134
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
135
|
+
# Valid values depend on the kind of element.
|
136
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
137
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
138
|
+
# @param [String] text Full text string to be found in the table row.
|
139
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
140
|
+
# @param [Fixnum] column Integer indicating the column to search for the text string.
|
141
|
+
# If not supplied all columns will be checked.
|
142
|
+
# @return (see #click)
|
143
|
+
#
|
144
|
+
def click_table_row_with_text(browser, how, what, text, desc = '', column = nil)
|
145
|
+
msg = build_message("Click row with text #{text} in table :#{how}=>'#{what}.", desc)
|
146
|
+
table = get_table(browser, how, what, desc)
|
147
|
+
if table
|
148
|
+
index = get_index_of_row_with_text(table, text, column)
|
149
|
+
if index
|
150
|
+
table[index].click
|
151
|
+
passed_to_log(msg)
|
152
|
+
index
|
153
|
+
else
|
154
|
+
failed_to_log("#{msg} Row not found.")
|
155
|
+
end
|
156
|
+
else
|
157
|
+
failed_to_log("#{msg} Table not found.")
|
158
|
+
end
|
159
|
+
rescue
|
160
|
+
failed_to_log("Unable to #{msg}: '#{$!}'")
|
161
|
+
end
|
162
|
+
|
163
|
+
# Double click the first row which contains a particular string in a table identified by attribute and value.
|
164
|
+
# A specific column in the table can also be specified.
|
165
|
+
# Uses fire_event method in Watir to send 'onDblClick' event.
|
166
|
+
# @param (see #click_table_row_with_text)
|
167
|
+
# @return (see #click)
|
168
|
+
#
|
169
|
+
def double_click_table_row_with_text(browser, how, what, text, desc = '', column = nil)
|
170
|
+
msg = build_message("Double click row with text #{text} in table :#{how}=>'#{what}.", desc)
|
171
|
+
table = get_table(browser, how, what, desc)
|
172
|
+
if table
|
173
|
+
index = get_index_of_row_with_text(table, text, column)
|
174
|
+
if index
|
175
|
+
table[index].fire_event('ondblclick')
|
176
|
+
passed_to_log(msg)
|
177
|
+
index
|
178
|
+
else
|
179
|
+
failed_to_log("#{msg} Row not found.")
|
180
|
+
end
|
181
|
+
else
|
182
|
+
failed_to_log("#{msg} Table not found.")
|
183
|
+
end
|
184
|
+
rescue
|
185
|
+
failed_to_log("Unable to #{msg}: '#{$!}'")
|
186
|
+
end
|
187
|
+
|
188
|
+
# Click a specifific button on a popup window.
|
189
|
+
# (Windows only)
|
190
|
+
# @param [String] title A string starting at the beginning of the title which uniquely identifies the popup window.
|
191
|
+
# @param [String] button The value displayed for the button (e.g. OK, Yes, Cancel, etc)
|
192
|
+
# @param [Fixnum] wait Integer indicating the number of seconds to wait for the popup window to appear.
|
193
|
+
# @return (see #click)
|
194
|
+
def click_popup_button(title, button, wait= 9, user_input=nil)
|
195
|
+
#TODO: is winclicker still viable/available?
|
196
|
+
wc = WinClicker.new
|
197
|
+
if wc.clickWindowsButton(title, button, wait)
|
198
|
+
passed_to_log("Window '#{title}' button '#{button}' found and clicked.")
|
199
|
+
true
|
200
|
+
else
|
201
|
+
failed_to_log("Window '#{title}' button '#{button}' not found. (#{__LINE__})")
|
202
|
+
end
|
203
|
+
wc = nil
|
204
|
+
# get a handle if one exists
|
205
|
+
# hwnd = $ie.enabled_popup(wait)
|
206
|
+
# if (hwnd) # yes there is a popup
|
207
|
+
# w = WinClicker.new
|
208
|
+
# if ( user_input )
|
209
|
+
# w.setTextValueForFileNameField( hwnd, "#{user_input}" )
|
210
|
+
# end
|
211
|
+
# # I put this in to see the text being input it is not necessary to work
|
212
|
+
# sleep 3
|
213
|
+
# # "OK" or whatever the name on the button is
|
214
|
+
# w.clickWindowsButton_hwnd( hwnd, "#{button}" )
|
215
|
+
# #
|
216
|
+
# # this is just cleanup
|
217
|
+
# w=nil
|
218
|
+
# end
|
219
|
+
end
|
220
|
+
|
221
|
+
# Select option from select list (dropdown) already identified and passed to the method. Selection can be by *:text* or *:value*.
|
222
|
+
# @param [Watir::SelectList] list A reference to the specific select list object.
|
223
|
+
# @param [Symbol] how Either :text or :value.
|
224
|
+
# @param [String/Rexexp] what A string or regular expression that will uniquely identify the option to select.
|
225
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
226
|
+
# @param [Boolean] nofail If true do not log a failed message if the option is not found in the select list.
|
227
|
+
# @return (see #click)
|
228
|
+
def select_option_from_list(list, how, what, desc = '', nofail = false)
|
229
|
+
msg = build_message("Select :#{how}=>'#{what}'", desc)
|
230
|
+
ok = true
|
231
|
+
if list
|
232
|
+
case how
|
233
|
+
when :text
|
234
|
+
list.select(what) #TODO: regex?
|
235
|
+
when :value
|
236
|
+
list.select_value(what) #TODO: regex?
|
237
|
+
when :index
|
238
|
+
list.select(list.getAllContents[what.to_i])
|
239
|
+
else
|
240
|
+
failed_to_log("#{msg} Select by #{how} not supported.")
|
241
|
+
ok = false
|
242
|
+
end
|
243
|
+
if ok
|
244
|
+
passed_to_log(msg)
|
245
|
+
true
|
246
|
+
else
|
247
|
+
if nofail
|
248
|
+
passed_to_log("#{msg} Option not found. No Fail specified.")
|
249
|
+
true
|
250
|
+
else
|
251
|
+
failed_to_log("#{msg} Option not found.")
|
252
|
+
end
|
253
|
+
end
|
254
|
+
else
|
255
|
+
failed_to_log("#{msg} Select list not found.")
|
256
|
+
end
|
257
|
+
rescue
|
258
|
+
failed_to_log("Unable to #{msg} '#{$!}'")
|
259
|
+
end
|
260
|
+
|
261
|
+
# Select option from select list identified by *how* and *what*. Option is identified by *which* and *value*
|
262
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
263
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
264
|
+
# Valid values depend on the kind of element.
|
265
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
266
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
267
|
+
# @param [Symbol] which Either :text or :value.
|
268
|
+
# @param [String/Rexexp] option A string or regular expression that will uniquely identify the option to select.
|
269
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
270
|
+
# @param [Boolean] nofail If true do not log a failed message if the option is not found in the select list.
|
271
|
+
# @return (see #click)
|
272
|
+
def select_option(browser, how, what, which, option, desc = '', nofail = false)
|
273
|
+
list = browser.select_list(how, what)
|
274
|
+
msg = build_message("from list with :#{how}=>'#{what}", desc)
|
275
|
+
select_option_from_list(list, which, option, msg, nofail)
|
276
|
+
end
|
277
|
+
|
278
|
+
# Set radio button or checkbox to selected.
|
279
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
280
|
+
# @param [Symbol] element The kind of element to click. Must be either :radio or :checkbox.
|
281
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
282
|
+
# Valid values depend on the kind of element.
|
283
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
284
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
285
|
+
# @param [String, Regexp] value A string or a regular expression to be found in the *:value* attribute of the radio or checkbox.
|
286
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
287
|
+
# @return (see #click)
|
288
|
+
def set(browser, element, how, what, value = nil, desc = '')
|
289
|
+
msg = "Set #{element} #{how}=>'#{what}' "
|
290
|
+
msg << ", :value=>#{value} " if value
|
291
|
+
msg << " '#{desc}' " if desc.length > 0
|
292
|
+
case element
|
293
|
+
when :radio
|
294
|
+
browser.radio(how, what).set
|
295
|
+
when :checkbox
|
296
|
+
browser.checkbox(how, what).set
|
297
|
+
else
|
298
|
+
failed_to_log("#{__method__}: #{element} not supported")
|
299
|
+
end
|
300
|
+
passed_to_log(msg)
|
301
|
+
true
|
302
|
+
rescue
|
303
|
+
failed_to_log("#{msg} '#{$!}'")
|
304
|
+
end
|
305
|
+
|
306
|
+
# Set file field element, identified by *how* and *what*, to a specified file path and name.
|
307
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
308
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
309
|
+
# Valid values depend on the kind of element.
|
310
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
311
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
312
|
+
# @param [String] filespec The full path and name of the target file.
|
313
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
314
|
+
# @return (see #click)
|
315
|
+
def set_file_field(browser, how, what, filespec, desc = '')
|
316
|
+
msg = build_message("#{__method__.to_s.humanize} #{how}=>#{what} to '#{filespec}.", desc)
|
317
|
+
ff = browser.file_field(how, what)
|
318
|
+
if ff
|
319
|
+
ff.set filespec
|
320
|
+
sleep_for(8)
|
321
|
+
passed_to_log(msg)
|
322
|
+
true
|
323
|
+
else
|
324
|
+
failed_to_log("#{msg} File field not found.")
|
325
|
+
end
|
326
|
+
rescue
|
327
|
+
failed_to_log("Unable to #{msg} '#{$!}'")
|
328
|
+
end
|
329
|
+
|
330
|
+
# Set radio button as selected using two element attributes.
|
331
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
332
|
+
# @param [Symbol] how1 The first element attribute used to identify the specific element.
|
333
|
+
# Valid values depend on the kind of element.
|
334
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
335
|
+
# @param [String, Regexp] what1 A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
336
|
+
# @param [Symbol] how2 The second element attribute used to identify the specific element.
|
337
|
+
# @param [String, Regexp] what2 A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
338
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
339
|
+
# @return (see #click)
|
340
|
+
def set_radio_two_attributes(browser, how1, what1, how2, what2, desc = '')
|
341
|
+
msg = build_message("Set radio #{how1}='#{what1}', #{how2}= #{what2}", desc)
|
342
|
+
browser.radio(how1 => what1, how2 => what2).set
|
343
|
+
passed_to_log(msg)
|
344
|
+
true
|
345
|
+
rescue
|
346
|
+
failed_to_log("#{msg} '#{$!}'")
|
347
|
+
end
|
348
|
+
|
349
|
+
#def set_radio_no_wait_by_index(browser, index, desc = '')
|
350
|
+
# #TODO: Not supported by Watir 1.8.x
|
351
|
+
# msg = "Radio :index=#{index} "
|
352
|
+
# radios = browser.radios
|
353
|
+
# debug_to_log("\n#{radios}")
|
354
|
+
# radio = radios[index]
|
355
|
+
# debug_to_log("\n#{radio}")
|
356
|
+
# radio.click_no_wait
|
357
|
+
# msg << 'set ' + desc
|
358
|
+
# passed_to_log(msg)
|
359
|
+
# true
|
360
|
+
#rescue
|
361
|
+
# msg << 'not found ' + desc
|
362
|
+
# failed_to_log("#{msg} (#{__LINE__})")
|
363
|
+
#end
|
364
|
+
|
365
|
+
# Clear (unset) radio, checkbox or text field as identified by the attribute specified in *how* with value *what*.
|
366
|
+
# It's *:value* attribute can also be used when needed by specifying *value* (Ignored for text_field).
|
367
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
368
|
+
# @param [Symbol] element The kind of element to clear. Must be :radio, :checkbox or :text_field.
|
369
|
+
# @param [Symbol] how The element attribute used to identify the specific checkbox.
|
370
|
+
# Valid values depend on the kind of element.
|
371
|
+
# Common values: :text, :id, :title, :name, :class.
|
372
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
373
|
+
# @param [String, Regexp] value A string or a regular expression to be found in the *:value* attribute of the element.
|
374
|
+
# In the case of text_field this is the string to be entered in the field.
|
375
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
376
|
+
# @return (see #click)
|
377
|
+
def clear(browser, element, how, what, value = nil, desc = '')
|
378
|
+
msg = "Clear #{element} #{how}=>'#{what}' "
|
379
|
+
msg << ", value=>#{value} " if value
|
380
|
+
msg << " '#{desc}' " if desc.length > 0
|
381
|
+
case element
|
382
|
+
when :radio
|
383
|
+
browser.radio(how, what).clear
|
384
|
+
when :checkbox
|
385
|
+
browser.checkbox(how, what).clear
|
386
|
+
when :text_field
|
387
|
+
browser.text_field(how, what).set('')
|
388
|
+
else
|
389
|
+
failed_to_log("#{__method__}: #{element} not supported")
|
390
|
+
end
|
391
|
+
passed_to_log(msg)
|
392
|
+
true
|
393
|
+
rescue
|
394
|
+
failed_to_log("#{msg} '#{$!}'")
|
395
|
+
end
|
396
|
+
|
397
|
+
# Set text field as identified by the attribute specified in *how* with value in *what* to the string specified in *value*.
|
398
|
+
# This method differs from set() in that it validates that the text field has been set to the specified value.
|
399
|
+
# The value verification can be turned off by setting *skip_value_check* to true.
|
400
|
+
# This is useful when the text_field performs formatting on the entered string. See set_text_field_and_validate()
|
401
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
402
|
+
# @param [Symbol] how The element attribute used to identify the specific checkbox.
|
403
|
+
# Valid values depend on the kind of element.
|
404
|
+
# Common values: :text, :id, :title, :name, :class.
|
405
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
406
|
+
# @param [String] value A string to enter into the text field.
|
407
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
408
|
+
# @param [Boolean] skip_value_check Forces verification of value in text field to pass.
|
409
|
+
# @return (see #click)
|
410
|
+
def set_text_field(browser, how, what, value, desc = '', skip_value_check = false)
|
411
|
+
#TODO: fix this to handle Safari password field
|
412
|
+
msg = build_message("#{__method__.to_s.humanize} #{how}='#{what}' to '#{value}'", desc)
|
413
|
+
msg << " (Skip value check)" if skip_value_check
|
414
|
+
if browser.text_field(how, what).exists?
|
415
|
+
tf = browser.text_field(how, what)
|
416
|
+
tf.set(value)
|
417
|
+
if skip_value_check
|
418
|
+
passed_to_log(msg)
|
419
|
+
true
|
420
|
+
else
|
421
|
+
if tf.value == value
|
422
|
+
passed_to_log(msg)
|
423
|
+
true
|
424
|
+
else
|
425
|
+
failed_to_log("#{msg}: Found:'#{tf.value}'.")
|
426
|
+
end
|
427
|
+
end
|
428
|
+
else
|
429
|
+
failed_to_log("#{msg}: Textfield not found")
|
430
|
+
end
|
431
|
+
rescue
|
432
|
+
failed_to_log("Unable to '#{msg}': '#{$!}'")
|
433
|
+
end
|
434
|
+
|
435
|
+
alias set_textfield set_text_field
|
436
|
+
|
437
|
+
# Clear text field as identified by the attribute specified in *how* with value in *what* to the string specified in *value*.
|
438
|
+
# This method differs from set() in that 1( it uses the Watir #clear method, 2( it validates that the text field has been
|
439
|
+
# set to the specified value.
|
440
|
+
# The value verification can be turned off by setting *skip_value_check* to true.
|
441
|
+
# This is useful when the text_field performs formatting on the entered string. See set_text_field_and_validate()
|
442
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
443
|
+
# @param [Symbol] how The element attribute used to identify the specific checkbox.
|
444
|
+
# Valid values depend on the kind of element.
|
445
|
+
# Common values: :text, :id, :title, :name, :class.
|
446
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
447
|
+
# @param [Boolean] skip_value_check Forces verification of value in text field to pass.
|
448
|
+
# @return (see #click)
|
449
|
+
def clear_textfield(browser, how, what, skip_value_check = false)
|
450
|
+
msg1 = "Skip value check." if skip_value_check
|
451
|
+
msg = build_message("#{__method__.to_s.humanize} #{how}='#{what}'.", msg1)
|
452
|
+
if browser.text_field(how, what).exists?
|
453
|
+
tf = browser.text_field(how, what)
|
454
|
+
tf.clear
|
455
|
+
if tf.value == ''
|
456
|
+
passed_to_log(msg)
|
457
|
+
true
|
458
|
+
elsif skip_value_check
|
459
|
+
passed_to_log(msg)
|
460
|
+
true
|
461
|
+
else
|
462
|
+
failed_to_log("#{msg} Found:'#{tf.value}'.")
|
463
|
+
end
|
464
|
+
else
|
465
|
+
failed_to_log("#{msg} Textfield not found.")
|
466
|
+
end
|
467
|
+
rescue
|
468
|
+
failed_to_log("Unable to #{msg} '#{$!}'.")
|
469
|
+
end
|
470
|
+
|
471
|
+
#Enter a string into a text field element identified by an attribute type and a value.
|
472
|
+
#After the entry the value in the text field is validated against the *valid_value*. Use when the application reformats
|
473
|
+
#or performs edits on the input value.
|
474
|
+
|
475
|
+
# Set text field as identified by the attribute specified in *how* with value in *what* to the string specified in *value*.
|
476
|
+
# and verify that the text field is set to the string in *valid_value*.
|
477
|
+
#
|
478
|
+
# @example
|
479
|
+
# set_text_field_and_validate(browser, :id, 'text field id', '99999', 'Dollar format', '$99,999.00')
|
480
|
+
#
|
481
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
482
|
+
# @param [Symbol] how The element attribute used to identify the specific checkbox.
|
483
|
+
# Valid values depend on the kind of element.
|
484
|
+
# Common values: :text, :id, :title, :name, :class.
|
485
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
|
486
|
+
# @param [String] value A string to enter into the text field.
|
487
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output. Required in this method.
|
488
|
+
# @param [String] valid_value The expected value of the text field, e.g., following reformatting.
|
489
|
+
# @return (see #click)
|
490
|
+
def set_text_field_and_validate(browser, how, what, value, valid_value = nil, desc ='')
|
491
|
+
#NOTE: use when value and valid_value differ as with dollar reformatting
|
492
|
+
if set_text_field(browser, how, what, value, desc, true)
|
493
|
+
expected = valid_value ? valid_value : value
|
494
|
+
validate_textfield_value(browser, how, what, expected, desc)
|
495
|
+
end
|
496
|
+
rescue
|
497
|
+
failed_to_log("Unable to '#{msg}': '#{$!}'")
|
498
|
+
end
|
499
|
+
|
500
|
+
#def set_password_by_name(browser, name, value, desc = '', skip_value_check = false)
|
501
|
+
# set_text_field(browser, how, what, value, desc, skip_value_check)
|
502
|
+
# if browser.text_field(:name, name).exists?
|
503
|
+
# tf = browser.text_field(:name, name)
|
504
|
+
# # Workaround because browser.text_field doesn't work for password fields in Safari
|
505
|
+
# elsif @browserAbbrev.eql?("S")
|
506
|
+
# tf = browser.password(:name, name)
|
507
|
+
# end
|
508
|
+
# if tf.exists?
|
509
|
+
# tf.set(value)
|
510
|
+
# if tf.value == value
|
511
|
+
# passed_to_log("Set textfield name='#{name}' to '#{value}' #{desc}")
|
512
|
+
# true
|
513
|
+
# elsif skip_value_check
|
514
|
+
# passed_to_log("Set textfield name='#{name}' to '#{value}' #{desc} (skip value check)")
|
515
|
+
# true
|
516
|
+
# else
|
517
|
+
# failed_to_log("Set textfield name='#{name}' to '#{value}': Found:'#{tf.value}'. #{desc} (#{__LINE__})")
|
518
|
+
# end
|
519
|
+
# else
|
520
|
+
# failed_to_log("Textfield name='#{name}' not found to set to '#{value}'. #{desc} (#{__LINE__})")
|
521
|
+
# end
|
522
|
+
#rescue
|
523
|
+
# failed_to_log("Textfield name='#{name}' could not be set to '#{value}': '#{$!}'. #{desc} (#{__LINE__})")
|
524
|
+
#end
|
525
|
+
|
526
|
+
# Fire an event on a specific DOM element identified by one of its attributes and that attribute's value.
|
527
|
+
#
|
528
|
+
# @example
|
529
|
+
# # html for a link element:
|
530
|
+
# # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
|
531
|
+
#
|
532
|
+
# fire_event(browser, :link, :text, 'Pickaxe', 'onMouseOver')
|
533
|
+
#
|
534
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
535
|
+
# @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
|
536
|
+
# Some common values are :link, :button, :image, :div, :span.
|
537
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
538
|
+
# Valid values depend on the kind of element.
|
539
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
540
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
541
|
+
# @param [String] event A string identifying the event to be fired.
|
542
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
543
|
+
# @return (see #click)
|
544
|
+
#
|
545
|
+
def fire_event(browser, element, how, what, event, desc = '')
|
546
|
+
msg = build_message("#{element.to_s.titlecase}: #{how}=>'#{what}' event:'#{event}'", desc)
|
547
|
+
begin
|
548
|
+
case element
|
549
|
+
when :link
|
550
|
+
browser.link(how, what).fire_event(event)
|
551
|
+
when :button
|
552
|
+
browser.button(how, what).fire_event(event)
|
553
|
+
when :image
|
554
|
+
browser.image(how, what).fire_event(event)
|
555
|
+
when :span
|
556
|
+
browser.span(how, what).fire_event(event)
|
557
|
+
when :div
|
558
|
+
browser.div(how, what).fire_event(event)
|
559
|
+
else
|
560
|
+
browser.element(how, what).fire_event(event)
|
561
|
+
end
|
562
|
+
rescue => e
|
563
|
+
unless rescue_me(e, __method__, rescue_me_command(element, how, what, __method__.to_s, event), "#{browser.class}")
|
564
|
+
raise e
|
565
|
+
end
|
566
|
+
end
|
567
|
+
passed_to_log("Fire event: #{msg}. #{desc}")
|
568
|
+
true
|
569
|
+
rescue
|
570
|
+
failed_to_log("Unable to fire event: #{msg}. '#{$!}' #{desc}")
|
571
|
+
end
|
572
|
+
|
573
|
+
end
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|