awetestlib 0.1.3-x86-mingw32 → 0.1.5-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/awetestlib.windows.gemspec +1 -1
- data/bin/awetestlib +11 -4
- data/bin/awetestlib-helpers.rb +28 -1
- data/bin/awetestlib-netbeans-setup.rb +39 -0
- data/bin/awetestlib-rubymine-setup.rb +33 -0
- data/images/logo.png +0 -0
- data/lib/awetestlib/html_report.rb +171 -0
- data/lib/{regression → awetestlib}/logging.rb +10 -43
- data/lib/awetestlib/regression/browser.rb +1233 -0
- data/lib/awetestlib/regression/drag_and_drop.rb +379 -0
- data/lib/awetestlib/regression/find.rb +431 -0
- data/lib/awetestlib/regression/legacy.rb +45 -0
- data/lib/awetestlib/regression/page_data.rb +190 -0
- data/lib/awetestlib/regression/runner.rb +306 -0
- data/lib/awetestlib/regression/tables.rb +491 -0
- data/lib/awetestlib/regression/user_input.rb +1256 -0
- data/lib/awetestlib/regression/utilities.rb +895 -0
- data/lib/awetestlib/regression/validations.rb +1184 -0
- data/lib/awetestlib/regression/waits.rb +391 -0
- data/lib/awetestlib/runner.rb +16 -0
- data/lib/awetestlib.rb +4 -4
- data/lib/version.rb +2 -2
- data/setup_samples/sample_netbeans/demo.rb +86 -0
- data/setup_samples/sample_netbeans/nbproject/configs/Demo.properties +2 -0
- data/setup_samples/sample_netbeans/nbproject/private/config.properties +1 -0
- data/setup_samples/sample_netbeans/nbproject/private/configs/Demo.properties +1 -0
- data/setup_samples/sample_netbeans/nbproject/private/private.properties +2 -0
- data/setup_samples/sample_netbeans/nbproject/project.properties +5 -0
- data/setup_samples/sample_netbeans/nbproject/project.xml +13 -0
- data/setup_samples/sample_rubymine/.idea/.name +1 -0
- data/setup_samples/sample_rubymine/.idea/encodings.xml +5 -0
- data/setup_samples/sample_rubymine/.idea/misc.xml +5 -0
- data/setup_samples/sample_rubymine/.idea/modules.xml +9 -0
- data/setup_samples/sample_rubymine/.idea/sample_rubymine.iml +9 -0
- data/setup_samples/sample_rubymine/.idea/scopes/scope_settings.xml +5 -0
- data/setup_samples/sample_rubymine/.idea/vcs.xml +7 -0
- data/setup_samples/sample_rubymine/.idea/workspace.xml +213 -0
- data/setup_samples/sample_rubymine/demo.rb +86 -0
- metadata +44 -19
- data/lib/regression/browser.rb +0 -1259
- data/lib/regression/drag_and_drop.rb +0 -374
- data/lib/regression/find.rb +0 -426
- data/lib/regression/legacy.rb +0 -40
- data/lib/regression/page_data.rb +0 -185
- data/lib/regression/runner.rb +0 -278
- data/lib/regression/tables.rb +0 -486
- data/lib/regression/user_input.rb +0 -1255
- data/lib/regression/utilities.rb +0 -891
- data/lib/regression/validations.rb +0 -1179
- data/lib/regression/waits.rb +0 -387
data/lib/regression/browser.rb
DELETED
@@ -1,1259 +0,0 @@
|
|
1
|
-
module Browser
|
2
|
-
|
3
|
-
def run
|
4
|
-
setup
|
5
|
-
set_script_variables
|
6
|
-
run_test
|
7
|
-
rescue
|
8
|
-
fatal_to_log("(#{__LINE__}) #{$!}")
|
9
|
-
browser.close
|
10
|
-
raise
|
11
|
-
end
|
12
|
-
|
13
|
-
=begin rdoc
|
14
|
-
:category: A_rdoc_test
|
15
|
-
Opens a browser and returns a reference to it. If *url* is specified the browser is
|
16
|
-
opened to that url, otherwise it is opened to a bland page
|
17
|
-
|
18
|
-
_Parameters_::
|
19
|
-
|
20
|
-
*url* - a string containing the full url. Optional.
|
21
|
-
|
22
|
-
_Example_
|
23
|
-
|
24
|
-
browser = open_browser('www.google.com')
|
25
|
-
|
26
|
-
=end
|
27
|
-
|
28
|
-
def open_browser(url = nil)
|
29
|
-
debug_to_log("Opening browser: #{@targetBrowser.name}")
|
30
|
-
debug_to_log("#{__method__}: [#{get_caller_line}] #{get_callers}")
|
31
|
-
case @targetBrowser.abbrev
|
32
|
-
when 'IE'
|
33
|
-
@myBrowser = open_ie
|
34
|
-
@myHwnd = @myBrowser.hwnd
|
35
|
-
#@waiter = Watir::Waiter.new(WAIT)
|
36
|
-
when 'FF'
|
37
|
-
#version = "11"
|
38
|
-
#@myBrowser = open_ff_for_version(version)
|
39
|
-
@myBrowser = open_ff_for_version
|
40
|
-
when 'S'
|
41
|
-
debug_to_log("Opening browser: #{@targetBrowser.name} legacy.rb:#{__LINE__}")
|
42
|
-
aBrowser = Watir::Safari.new
|
43
|
-
debug_to_log("Browser instantiated")
|
44
|
-
@myBrowser = aBrowser
|
45
|
-
#require 'shamisen/awetest_legacy/safari_waiter'
|
46
|
-
#@waiter = Watir::Waiter
|
47
|
-
when 'C', 'GC'
|
48
|
-
@myBrowser = open_chrome
|
49
|
-
##require 'shamisen/awetest_legacy/webdriver_waiter'
|
50
|
-
#require 'shamisen/support/webdriver_ext/browser'
|
51
|
-
#@waiter = Watir::Waiter
|
52
|
-
|
53
|
-
else
|
54
|
-
raise "Unsupported browser: #{@targetBrowser.name}"
|
55
|
-
end
|
56
|
-
get_browser_version(@myBrowser)
|
57
|
-
if url
|
58
|
-
go_to_url(@myBrowser, url)
|
59
|
-
end
|
60
|
-
@myBrowser
|
61
|
-
end
|
62
|
-
|
63
|
-
def open_ie(process = true)
|
64
|
-
check_for_and_clear_other_browsers
|
65
|
-
Watir::Browser.default = 'ie'
|
66
|
-
#if process && !IS_WIN_2008
|
67
|
-
# browser = Watir::IE.new_process
|
68
|
-
#else
|
69
|
-
browser = Watir::IE.new
|
70
|
-
#end
|
71
|
-
browser
|
72
|
-
end
|
73
|
-
|
74
|
-
def open_ff_for_version(version = @targetVersion)
|
75
|
-
if version.to_f < 4.0
|
76
|
-
browser = open_ff
|
77
|
-
#waiter = Watir::Waiter.new(WAIT)
|
78
|
-
else
|
79
|
-
browser = Watir::Browser.new(:firefox)
|
80
|
-
#require 'shamisen/awetest_legacy/webdriver_waiter'
|
81
|
-
#waiter = Watir::Waiter
|
82
|
-
end
|
83
|
-
browser
|
84
|
-
end
|
85
|
-
|
86
|
-
def open_ff
|
87
|
-
Watir::Browser.default = 'firefox'
|
88
|
-
browser = Watir::Browser.new
|
89
|
-
end
|
90
|
-
|
91
|
-
def open_chrome
|
92
|
-
browser = Watir::Browser.new(:chrome)
|
93
|
-
end
|
94
|
-
|
95
|
-
def go_to_url(browser, url = nil, redirect = nil)
|
96
|
-
if url
|
97
|
-
@myURL = url
|
98
|
-
end
|
99
|
-
message_tolog("URL: #{@myURL}")
|
100
|
-
browser.goto(@myURL)
|
101
|
-
if validate(browser, @myName, __LINE__)
|
102
|
-
# TODO .url method returns blank in Firewatir
|
103
|
-
if redirect
|
104
|
-
passed_to_log("Redirected to url '#{browser.url}'.")
|
105
|
-
true
|
106
|
-
elsif browser.url =~ /#{@myURL}/i # or @browserAbbrev == 'FF'
|
107
|
-
passed_to_log("Navigated to url '#{@myURL}'.")
|
108
|
-
true
|
109
|
-
else
|
110
|
-
failed_to_log("Navigated to url '#{browser.url}' but expected '#{@myURL}'.")
|
111
|
-
end
|
112
|
-
end
|
113
|
-
rescue
|
114
|
-
fatal_to_log("Unable to navigate to '#{@myURL}': '#{$!}'")
|
115
|
-
end
|
116
|
-
|
117
|
-
def token_auth(browser, role, token, id = 'token_pass')
|
118
|
-
set_textfield_by_id(browser, id, token)
|
119
|
-
click_button_by_value(browser, 'Continue')
|
120
|
-
if validate_text(browser, 'The requested page requires authentication\.\s*Please enter your Passcode below', nil, true)
|
121
|
-
bail_out(browser, __LINE__, "Token authorization failed on '#{token}'")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def bail_out(browser, lnbr, msg)
|
126
|
-
ts = Time.new
|
127
|
-
msg = "Bailing out at util line #{lnbr} #{ts} " + msg
|
128
|
-
puts "#{msg}"
|
129
|
-
fatal_to_log(msg, nil, 1, lnbr)
|
130
|
-
debug_to_log(dump_caller(lnbr))
|
131
|
-
if is_browser?(browser)
|
132
|
-
if @browserAbbrev == 'IE'
|
133
|
-
hwnd = browser.hwnd
|
134
|
-
kill_browser(hwnd, lnbr, browser)
|
135
|
-
raise(RuntimeError, msg, caller)
|
136
|
-
elsif @browserAbbrev == 'FF'
|
137
|
-
debug_to_log("#{browser.inspect}")
|
138
|
-
debug_to_log("#{browser.to_s}")
|
139
|
-
raise(RuntimeError, msg, caller)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
@status = 'bailout'
|
143
|
-
raise(RuntimeError, msg, caller)
|
144
|
-
end
|
145
|
-
|
146
|
-
def do_taskkill(severity, pid)
|
147
|
-
if pid and pid > 0 and pid < 538976288
|
148
|
-
info_to_log("Executing taskkill for pid #{pid}")
|
149
|
-
log_message(severity, %x[taskkill /t /f /pid #{pid}])
|
150
|
-
end
|
151
|
-
rescue
|
152
|
-
error_to_log("#{$!} (#{__LINE__})")
|
153
|
-
end
|
154
|
-
|
155
|
-
def check_for_other_browsers
|
156
|
-
cnt1 = find_other_browsers
|
157
|
-
cnt2 = Watir::Process.count 'iexplore.exe'
|
158
|
-
debug_to_log("check_for_other_browsers: cnt1: #{cnt1} cnt2: #{cnt2}")
|
159
|
-
rescue
|
160
|
-
error_to_log("#{$!} (#{__LINE__})\n#{Kernel.caller.to_yaml}")
|
161
|
-
end
|
162
|
-
|
163
|
-
def check_for_and_clear_other_browsers
|
164
|
-
if @targetBrowser.abbrev == 'IE'
|
165
|
-
debug_to_log("#{__method__}:")
|
166
|
-
cnt1 = find_other_browsers
|
167
|
-
cnt2 = Watir::IE.process_count
|
168
|
-
debug_to_log("#{__method__}: cnt1: #{cnt1} cnt2: #{cnt2}")
|
169
|
-
begin
|
170
|
-
Watir::IE.each do |ie|
|
171
|
-
pid = Watir::IE::Process.process_id_from_hwnd(ie.hwnd)
|
172
|
-
debug_to_log("#{__method__}: Killing browser process: hwnd #{ie.hwnd} pid #{pid} title '#{ie.title}' (#{__LINE__})")
|
173
|
-
do_taskkill(INFO, pid)
|
174
|
-
sleep_for(10)
|
175
|
-
end
|
176
|
-
#Watir::IE.close_all()
|
177
|
-
rescue
|
178
|
-
debug_to_log("#{__method__}: #{$!} (#{__LINE__})")
|
179
|
-
end
|
180
|
-
sleep(3)
|
181
|
-
cnt1 = find_other_browsers
|
182
|
-
cnt2 = Watir::IE.process_count
|
183
|
-
if cnt1 > 0 or cnt2 > 0
|
184
|
-
debug_to_log("#{__method__}:cnt1: #{cnt1} cnt2: #{cnt2}")
|
185
|
-
begin
|
186
|
-
Watir::IE.each do |ie|
|
187
|
-
pid = Watir::IE::Process.process_id_from_hwnd(ie.hwnd)
|
188
|
-
debug_to_log("#{__method__}: Killing browser process: hwnd #{ie.hwnd} pid #{pid} title '#{ie.title}' (#{__LINE__})")
|
189
|
-
do_taskkill(INFO, pid)
|
190
|
-
sleep_for(10)
|
191
|
-
end
|
192
|
-
#Watir::IE.close_all()
|
193
|
-
rescue
|
194
|
-
debug_to_log("#{__method__}:#{$!} (#{__LINE__})")
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
rescue
|
199
|
-
error_to_log("#{__method__}: #{$!} (#{__LINE__})\n#{Kernel.caller.to_yaml}")
|
200
|
-
end
|
201
|
-
|
202
|
-
def kill_browser(hwnd, lnbr, browser = nil, doflag = false)
|
203
|
-
# TODO Firefox
|
204
|
-
logit = false
|
205
|
-
if @browserAbbrev == 'FF'
|
206
|
-
if is_browser?(browser) # and browser.url.length > 1
|
207
|
-
logit = true
|
208
|
-
here = __LINE__
|
209
|
-
url = browser.url
|
210
|
-
capture_screen(browser, Time.new.to_f) if @screenCaptureOn
|
211
|
-
browser.close if url.length > 0
|
212
|
-
@status = 'killbrowser'
|
213
|
-
fatal_to_log("Kill browser called from line #{lnbr}")
|
214
|
-
end
|
215
|
-
elsif hwnd
|
216
|
-
pid = Watir::IE::Process.process_id_from_hwnd(hwnd)
|
217
|
-
if pid and pid > 0 and pid < 538976288
|
218
|
-
if browser.exists?
|
219
|
-
here = __LINE__
|
220
|
-
logit = true
|
221
|
-
url = browser.url
|
222
|
-
capture_screen(browser, Time.new.to_f) if @screenCaptureOn
|
223
|
-
browser.close
|
224
|
-
sleep(2)
|
225
|
-
if browser.exists?
|
226
|
-
do_taskkill(FATAL, pid)
|
227
|
-
end
|
228
|
-
@status = 'killbrowser'
|
229
|
-
end
|
230
|
-
end
|
231
|
-
if logit
|
232
|
-
debug_to_log("#{@browserName} window hwnd #{hwnd} pid #{pid} #{url} (#{here})")
|
233
|
-
fatal_to_log("Kill browser called from line #{lnbr}")
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
=begin rdoc
|
239
|
-
:category: A_rdoc_test
|
240
|
-
|
241
|
-
Returns a reference to a browser window. Used to attach a browser window to a variable
|
242
|
-
which can then be passed to methods that require a *browser* parameter.
|
243
|
-
|
244
|
-
_Parameters_::
|
245
|
-
|
246
|
-
*browser* - a reference to the browser window to be tested
|
247
|
-
|
248
|
-
*how* - the browser attribute used to identify the window: either :url or :title
|
249
|
-
|
250
|
-
*what* - a string or a regular expression in the url or title
|
251
|
-
|
252
|
-
*desc* - a string containing a message or description intended to appear in the log and/or report output
|
253
|
-
|
254
|
-
|
255
|
-
*_Example_*
|
256
|
-
|
257
|
-
mainwindow = open_browser('www.myapp.com') # open a browser to www.google.com
|
258
|
-
click(mainwindow, :button, :id, 'an id string') # click a button that opens another browser window
|
259
|
-
popup = attach_browser(mainwindow, :url, '[url of new window]') #*or*
|
260
|
-
popup = attach_browser(mainwindow, :title, '[title of new window]')
|
261
|
-
|
262
|
-
=end
|
263
|
-
|
264
|
-
def attach_browser(browser, how, what, desc = '')
|
265
|
-
debug_to_log("Attaching browser window :#{how}=>'#{what}' #{desc}")
|
266
|
-
uri_decoded_pattern = URI.encode(what.to_s.gsub('(?-mix:', '').gsub(')', ''))
|
267
|
-
case @browserAbbrev
|
268
|
-
when 'IE'
|
269
|
-
tmpbrowser = Watir::IE.attach(how, what)
|
270
|
-
browser.visible = true
|
271
|
-
if tmpbrowser
|
272
|
-
tmpbrowser.visible = true
|
273
|
-
tmpbrowser.speed = :fast
|
274
|
-
else
|
275
|
-
raise "Browser window :#{how}=>'#{what}' has at least one doc not in completed ready state."
|
276
|
-
end
|
277
|
-
when 'FF'
|
278
|
-
#TODO: This may be dependent on Firefox version if webdriver doesn't support 3.6.17 and below
|
279
|
-
browser.driver.switch_to.window(browser.driver.window_handles[0])
|
280
|
-
browser.window(how, /#{uri_decoded_pattern}/).use
|
281
|
-
tmpbrowser = browser
|
282
|
-
when 'S'
|
283
|
-
Watir::Safari.attach(how, what)
|
284
|
-
tmpbrowser = browser
|
285
|
-
when 'C'
|
286
|
-
browser.window(how, /#{uri_decoded_pattern}/).use
|
287
|
-
tmpbrowser = browser
|
288
|
-
end
|
289
|
-
debug_to_log("#{__method__}: tmpbrowser:#{tmpbrowser.inspect}")
|
290
|
-
tmpbrowser
|
291
|
-
end
|
292
|
-
|
293
|
-
=begin rdoc
|
294
|
-
:category: A_rdoc_test
|
295
|
-
Returns a reference to a browser window using the window's url. Calls attach_browser().
|
296
|
-
|
297
|
-
_Parameters_::
|
298
|
-
|
299
|
-
*browser* - a reference to the browser window to be tested
|
300
|
-
|
301
|
-
*pattern* - a string with the complete url or a regular expression containing part of the url
|
302
|
-
that uniquely identifies it in the context of the test.
|
303
|
-
|
304
|
-
*desc* - a string containing a message or description intended to appear in the log and/or report output
|
305
|
-
|
306
|
-
|
307
|
-
_Example_
|
308
|
-
|
309
|
-
mainwindow = open_browser('www.myapp.com') # open a browser to www.google.com
|
310
|
-
click(mainwindow, :button, :id, 'an id string') # click a button that opens another browser window
|
311
|
-
popup = attach_browser_by_url(mainwindow, '[url of new window]')
|
312
|
-
|
313
|
-
=end
|
314
|
-
|
315
|
-
def attach_browser_by_url(browser, pattern, desc = '')
|
316
|
-
attach_browser(browser, :url, pattern, desc)
|
317
|
-
end
|
318
|
-
|
319
|
-
alias attach_browser_with_url attach_browser_by_url
|
320
|
-
|
321
|
-
=begin rdoc
|
322
|
-
:category: A_rdoc_test
|
323
|
-
Returns a reference to a new browser window. Used to attach a new browser window to a variable
|
324
|
-
which can then be passed to methods that require a *browser* parameter. Calls attach_browser().
|
325
|
-
|
326
|
-
_Parameters_::
|
327
|
-
|
328
|
-
*browser* - a reference to the browser window to be tested
|
329
|
-
|
330
|
-
*how* - the browser attribute used to identify the window: either :url or :title
|
331
|
-
|
332
|
-
*what* - a string or a regular expression in the url or title
|
333
|
-
|
334
|
-
*desc* - a string containing a message or description intended to appear in the log and/or report output
|
335
|
-
|
336
|
-
|
337
|
-
_Example_
|
338
|
-
|
339
|
-
mainwindow = open_browser('www.myapp.com') # open a browser to www.google.com
|
340
|
-
click(mainwindow, :button, :id, 'an id string') # click a button that opens another browser window
|
341
|
-
popup = attach_popup(mainwindow, :url, '[url of new window]') *or*
|
342
|
-
popup = attach_popup(mainwindow, :title, '[title of new window]')
|
343
|
-
|
344
|
-
=end
|
345
|
-
def attach_popup(browser, how, what, desc = '')
|
346
|
-
msg = "Attach popup :#{how}=>'#{what}'. #{desc}"
|
347
|
-
popup = attach_browser(browser, how, what, desc)
|
348
|
-
sleep_for(1)
|
349
|
-
debug_to_log("#{popup.inspect}")
|
350
|
-
if is_browser?(popup)
|
351
|
-
title = popup.title
|
352
|
-
passed_to_log("#{msg} title='#{title}'")
|
353
|
-
return popup
|
354
|
-
else
|
355
|
-
failed_to_log(msg)
|
356
|
-
end
|
357
|
-
rescue
|
358
|
-
failed_to_log("Unable to attach popup :#{how}=>'#{what}'. #{desc} '#{$!}' (#{__LINE__})")
|
359
|
-
end
|
360
|
-
|
361
|
-
def attach_popup_by_title(browser, strg, desc = '')
|
362
|
-
attach_popup(browser, :title, strg, desc)
|
363
|
-
end
|
364
|
-
|
365
|
-
def attach_popup_by_url(browser, pattern, desc = '')
|
366
|
-
attach_popup(browser, :url, pattern, desc)
|
367
|
-
end
|
368
|
-
|
369
|
-
alias get_popup_with_url attach_popup_by_url
|
370
|
-
alias attach_popup_with_url attach_popup_by_url
|
371
|
-
alias attach_iepopup attach_popup_by_url
|
372
|
-
|
373
|
-
def find_other_browsers
|
374
|
-
cnt = 0
|
375
|
-
if @targetBrowser.abbrev == 'IE'
|
376
|
-
Watir::IE.each do |ie|
|
377
|
-
debug_to_log("#{ie.inspect}")
|
378
|
-
ie.close()
|
379
|
-
cnt = cnt + 1
|
380
|
-
end
|
381
|
-
end
|
382
|
-
debug_to_log("Found #{cnt} IE browser(s).")
|
383
|
-
return cnt
|
384
|
-
rescue
|
385
|
-
error_to_log("#{$!} (#{__LINE__})\n#{Kernel.caller.to_yaml}", __LINE__)
|
386
|
-
return 0
|
387
|
-
end
|
388
|
-
|
389
|
-
def close_window_by_title(browser, title, desc = '', text = '')
|
390
|
-
msg = "Window '#{title}':"
|
391
|
-
if @ai.WinWait(title, text, WAIT) > 0
|
392
|
-
passed_to_log("#{msg} appeared. #{desc}")
|
393
|
-
myHandle = @ai.WinGetHandle(title, text)
|
394
|
-
full_text = @ai.WinGetText(title)
|
395
|
-
debug_to_log("#{msg} hwnd: #{myHandle.inspect}")
|
396
|
-
debug_to_log("#{msg} title: '#{title}' text: '#{full_text}'")
|
397
|
-
if @ai.WinClose(title, text) > 0
|
398
|
-
passed_to_log("#{msg} closed successfully. #{desc}")
|
399
|
-
else
|
400
|
-
failed_to_log("#{msg} close failed. (#{__LINE__}) #{desc}")
|
401
|
-
end
|
402
|
-
else
|
403
|
-
failed_to_log("#{msg} did not appear after #{WAIT} seconds. (#{__LINE__}) #{desc}")
|
404
|
-
end
|
405
|
-
rescue
|
406
|
-
failed_to_log("#{msg}: Unable to close: '#{$!}'. (#{__LINE__}) #{desc}")
|
407
|
-
end
|
408
|
-
|
409
|
-
=begin rdoc
|
410
|
-
:category: Basic
|
411
|
-
:tags:logon, login, user, password, url
|
412
|
-
TODO: Needs to be more flexible about finding login id and password textfields
|
413
|
-
TODO: Parameterize url and remove references to environment
|
414
|
-
=end
|
415
|
-
def login(browser, user, password)
|
416
|
-
myURL = @myAppEnv.url
|
417
|
-
runenv = @myAppEnv.nodename
|
418
|
-
message_tolog("URL: #{myURL}")
|
419
|
-
message_tolog("Beginning login: User: #{user} Environment: #{runenv}")
|
420
|
-
if validate(browser, @myName, __LINE__)
|
421
|
-
browser.goto(myURL)
|
422
|
-
if validate(browser, @myName)
|
423
|
-
set_textfield_by_name(browser, 'loginId', user)
|
424
|
-
set_textfield_by_name(browser, 'password', password)
|
425
|
-
click_button_by_value(browser, 'Login')
|
426
|
-
if validate(browser, @myName)
|
427
|
-
passed_to_log("Login successful.")
|
428
|
-
end
|
429
|
-
else
|
430
|
-
failed_to_log("Unable to login to application: '#{$!}'")
|
431
|
-
# screen_capture( "#{@myRoot}/screens/#{myName}_#{@runid}_#{__LINE__.to_s}_#{Time.new.to_f.to_s}.jpg")
|
432
|
-
end
|
433
|
-
end
|
434
|
-
rescue
|
435
|
-
failed_to_log("Unable to login to application: '#{$!}'")
|
436
|
-
end
|
437
|
-
|
438
|
-
=begin rdoc
|
439
|
-
category: Logon
|
440
|
-
:tags:logon, login, user, password, url, basic authorization
|
441
|
-
=end
|
442
|
-
def basic_auth(browser, user, pswd, url, bypass_validate = false)
|
443
|
-
mark_testlevel("Basic Authorization Login", 0)
|
444
|
-
|
445
|
-
message_to_report ("Login: #{user}")
|
446
|
-
message_to_report ("URL: #{url}")
|
447
|
-
message_to_report ("Password: #{pswd}")
|
448
|
-
|
449
|
-
@login_title = "Connect to"
|
450
|
-
|
451
|
-
a = Thread.new {
|
452
|
-
browser.goto(url)
|
453
|
-
}
|
454
|
-
|
455
|
-
sleep_for(2)
|
456
|
-
message_to_log("#{@login_title}...")
|
457
|
-
|
458
|
-
if (@ai.WinWait(@login_title, "", 90) > 0)
|
459
|
-
win_title = @ai.WinGetTitle(@login_title)
|
460
|
-
debug_to_log("Basic Auth Login window appeared: '#{win_title}'")
|
461
|
-
@ai.WinActivate(@login_title)
|
462
|
-
@ai.ControlSend(@login_title, '', "[CLASS:Edit; INSTANCE:2]", '!u')
|
463
|
-
@ai.ControlSend(@login_title, '', "[CLASS:Edit; INSTANCE:2]", user, 1)
|
464
|
-
@ai.ControlSend(@login_title, '', "[CLASS:Edit; INSTANCE:3]", pswd.gsub(/!/, '{!}'), 1)
|
465
|
-
@ai.ControlClick(@login_title, "", '[CLASS:Button; INSTANCE:1]')
|
466
|
-
else
|
467
|
-
debug_to_log("Basic Auth Login window did not appear.")
|
468
|
-
end
|
469
|
-
a.join
|
470
|
-
|
471
|
-
validate(browser, @myName) unless bypass_validate
|
472
|
-
|
473
|
-
message_to_report("URL: [#{browser.url}] User: [#{user}]")
|
474
|
-
|
475
|
-
end
|
476
|
-
|
477
|
-
def logout(browser, where = @myName, lnbr = __LINE__)
|
478
|
-
#TODO Firewatir 1.6.5 does not implement .exists for FireWatir::Firefox class
|
479
|
-
debug_to_log("Logging out in #{where} at line #{lnbr}.", lnbr, true)
|
480
|
-
debug_to_log("#{__method__}: browser: #{browser.inspect} (#{__LINE__})")
|
481
|
-
|
482
|
-
if ['FF', 'S'].include?(@browserAbbrev) || browser.exists?
|
483
|
-
case @browserAbbrev
|
484
|
-
when 'FF'
|
485
|
-
if is_browser?(browser)
|
486
|
-
url = browser.url
|
487
|
-
title = browser.title
|
488
|
-
debug_to_log("#{__method__}: Firefox browser url: [#{url}]")
|
489
|
-
debug_to_log("#{__method__}: Firefox browser title: [#{title}]")
|
490
|
-
debug_to_log("#{__method__}: Closing browser: #{where} (#{lnbr})")
|
491
|
-
if url and url.length > 1
|
492
|
-
browser.close
|
493
|
-
else
|
494
|
-
browser = FireWatir::Firefox.attach(:title, title)
|
495
|
-
browser.close
|
496
|
-
end
|
497
|
-
|
498
|
-
end
|
499
|
-
when 'IE'
|
500
|
-
hwnd = browser.hwnd
|
501
|
-
pid = Watir::IE::Process.process_id_from_hwnd(hwnd)
|
502
|
-
debug_to_log("#{__method__}: Closing browser: hwnd #{hwnd} pid #{pid} #{where} (#{lnbr}) (#{__LINE__})")
|
503
|
-
browser.close
|
504
|
-
if browser.exists? and pid > 0 and pid < 538976288 # value of uninitialized memory location
|
505
|
-
debug_to_log("Retry close browser: hwnd #{hwnd} pid #{pid} #{where} #{lnbr} (#{__LINE__})")
|
506
|
-
browser.close
|
507
|
-
end
|
508
|
-
if browser.exists? and pid > 0 and pid < 538976288 # value of uninitialized memory location
|
509
|
-
kill_browser(browser.hwnd, __LINE__, browser, true)
|
510
|
-
end
|
511
|
-
when 'S'
|
512
|
-
if is_browser?(browser)
|
513
|
-
url = browser.url
|
514
|
-
title = browser.title
|
515
|
-
debug_to_log("Safari browser url: [#{url}]")
|
516
|
-
debug_to_log("Safari browser title: [#{title}]")
|
517
|
-
debug_to_log("Closing browser: #{where} (#{lnbr})")
|
518
|
-
close_modal_s # to close any leftover modal dialogs
|
519
|
-
browser.close
|
520
|
-
end
|
521
|
-
when 'C'
|
522
|
-
if is_browser?(browser)
|
523
|
-
url = browser.url
|
524
|
-
title = browser.title
|
525
|
-
debug_to_log("Chrome browser url: [#{url}]")
|
526
|
-
debug_to_log("Chrome browser title: [#{title}]")
|
527
|
-
debug_to_log("Closing browser: #{where} (#{lnbr})")
|
528
|
-
if url and url.length > 1
|
529
|
-
browser.close
|
530
|
-
#else
|
531
|
-
#browser = FireWatir::Firefox.attach(:title, title)
|
532
|
-
#browser.close
|
533
|
-
end
|
534
|
-
|
535
|
-
end
|
536
|
-
else
|
537
|
-
raise "Unsupported browser: '#{@browserAbbrev}'"
|
538
|
-
end
|
539
|
-
end
|
540
|
-
# rescue => e
|
541
|
-
# if not e.is_a?(Vapir::WindowGoneException)
|
542
|
-
# raise e
|
543
|
-
# end
|
544
|
-
end
|
545
|
-
|
546
|
-
#close popup in new window
|
547
|
-
def close_new_window_popup(popup)
|
548
|
-
if is_browser?(popup)
|
549
|
-
url = popup.url
|
550
|
-
debug_to_log("Closing popup '#{url}' ")
|
551
|
-
popup.close
|
552
|
-
|
553
|
-
end
|
554
|
-
end
|
555
|
-
|
556
|
-
def close_panel_by_text(browser, panel, strg = 'Close')
|
557
|
-
if validate(browser, @myName, __LINE__)
|
558
|
-
if @browserAbbrev == 'IE'
|
559
|
-
panel.link(:text, strg).click!
|
560
|
-
elsif $USE_FIREWATIR
|
561
|
-
begin
|
562
|
-
panel.link(:text, strg).click
|
563
|
-
rescue => e
|
564
|
-
if not rescue_me(e, __method__, "link(:text,'#{strg}').click", "#{panel.class}")
|
565
|
-
raise e
|
566
|
-
end
|
567
|
-
end
|
568
|
-
else
|
569
|
-
panel.link(:text, strg).click(:wait => false)
|
570
|
-
end
|
571
|
-
sleep_for(1)
|
572
|
-
if validate(browser, @myName, __LINE__)
|
573
|
-
passed_to_log("Panel '#{strg}' (by :text) closed.")
|
574
|
-
true
|
575
|
-
end
|
576
|
-
else
|
577
|
-
failed_to_log("Panel '#{strg}' (by :text) still open.")
|
578
|
-
end
|
579
|
-
rescue
|
580
|
-
failed_to_log("Click on '#{strg}'(by :text) failed: '#{$!}' (#{__LINE__})")
|
581
|
-
end
|
582
|
-
|
583
|
-
# def close_modal_ie(title="", button="OK", text='', side = 'primary', wait = WAIT)
|
584
|
-
def close_popup(title, button = "OK", text = '', side = 'primary', wait = WAIT, desc = '', quiet = false)
|
585
|
-
#TODO needs simplifying and debug code cleaned up
|
586
|
-
title = translate_popup_title(title)
|
587
|
-
msg = "'#{title}'"
|
588
|
-
msg << " with text '#{text}'" if text.length > 0
|
589
|
-
msg << " (#{desc})" if desc.length > 0
|
590
|
-
@ai.Opt("WinSearchChildren", 1) # Match any substring in the title
|
591
|
-
if @ai.WinWait(title, text, wait) > 0
|
592
|
-
myHandle = @ai.WinGetHandle(title, text)
|
593
|
-
full_text = @ai.WinGetText(title)
|
594
|
-
#debug_to_report("Found popup handle:'#{myHandle}', title:'#{title}', text:'#{full_text}'")
|
595
|
-
if myHandle.length > 0
|
596
|
-
debug_to_log("hwnd: #{myHandle.inspect}")
|
597
|
-
passed_to_log("#{msg} appeared.") unless quiet
|
598
|
-
sleep_for(0.5)
|
599
|
-
@ai.WinActivate(title, text)
|
600
|
-
if @ai.WinActive(title, text) # > 0 #Hack to prevent fail when windows session locked
|
601
|
-
debug_to_log("#{msg} activated.")
|
602
|
-
if @ai.ControlFocus(title, text, button) # > 0
|
603
|
-
controlHandle = @ai.ControlGetHandle(title, '', "[CLASS:Button; TEXT:#{button}]")
|
604
|
-
if not controlHandle
|
605
|
-
button = "&#{button}"
|
606
|
-
controlHandle = @ai.ControlGetHandle(title, '', "[CLASS:Button; TEXT:#{button}]")
|
607
|
-
end
|
608
|
-
debug_to_log("Handle for button '#{button}': [#{controlHandle}]")
|
609
|
-
debug_to_log("#{msg} focus gained.")
|
610
|
-
# sleep_for(2)
|
611
|
-
if @ai.ControlClick(title, text, button, side) # > 0
|
612
|
-
# if @ai.ControlClick(title, text, "[Handle:#{controlHandle}]", side) > 0
|
613
|
-
# debug_to_log("#{msg} #{side} click on 'Handle:#{controlHandle}'." )
|
614
|
-
debug_to_log("#{msg} #{side} click on '#{button}' successful.")
|
615
|
-
sleep_for(1)
|
616
|
-
if @ai.WinExists(title, text) > 0
|
617
|
-
debug_to_log("#{msg} close popup failed on click '#{button}'. Trying WinClose. (#{__LINE__})")
|
618
|
-
@ai.WinClose(title, text)
|
619
|
-
if @ai.WinExists(title, text) > 0
|
620
|
-
debug_to_log("#{msg} close popup failed with WinClose('#{title}','#{text}'). (#{__LINE__})")
|
621
|
-
@ai.WinKill(title, text)
|
622
|
-
if @ai.WinExists(title, text) > 0
|
623
|
-
debug_to_log("#{msg} close popup failed with WinKill('#{title}','#{text}'). (#{__LINE__})")
|
624
|
-
else
|
625
|
-
debug_to_log("#{msg} closed successfully with WinKill('#{title}','#{text}').")
|
626
|
-
end
|
627
|
-
else
|
628
|
-
debug_to_log("#{msg} closed successfully with WinClose('#{title}','#{text}').")
|
629
|
-
end
|
630
|
-
else
|
631
|
-
passed_to_log("#{msg} closed successfully.") unless quiet
|
632
|
-
end
|
633
|
-
else
|
634
|
-
failed_to_log("#{msg} #{side} click on '#{button}' failed. (#{__LINE__})")
|
635
|
-
end
|
636
|
-
else
|
637
|
-
failed_to_log("#{msg} Unable to gain focus on button (#{__LINE__})")
|
638
|
-
end
|
639
|
-
else
|
640
|
-
failed_to_log("#{msg} Unable to activate (#{__LINE__})")
|
641
|
-
end
|
642
|
-
else
|
643
|
-
failed_to_log("#{msg} did not appear after #{wait} seconds. (#{__LINE__})")
|
644
|
-
end
|
645
|
-
else
|
646
|
-
failed_to_log("#{msg} did not appear after #{wait} seconds. (#{__LINE__})")
|
647
|
-
end
|
648
|
-
rescue
|
649
|
-
failed_to_log("Close popup title=#{title} failed: '#{$!}' (#{__LINE__})")
|
650
|
-
end
|
651
|
-
|
652
|
-
alias close_popup_validate_text close_popup
|
653
|
-
|
654
|
-
def close_popup_by_text(popup, strg = 'Close', desc = '')
|
655
|
-
count = 0
|
656
|
-
url = popup.url
|
657
|
-
if validate(popup, @myName, __LINE__)
|
658
|
-
count = string_count_in_string(popup.text, strg)
|
659
|
-
if count > 0
|
660
|
-
# @waiter.wait_until( browser.link(:text, strg).exists? ) if @waiter
|
661
|
-
begin
|
662
|
-
popup.link(:text, strg).click
|
663
|
-
rescue => e
|
664
|
-
if not rescue_me(e, __method__, "link(:text,'#{strg}')", "#{popup.class}")
|
665
|
-
raise e
|
666
|
-
end
|
667
|
-
end
|
668
|
-
passed_to_log("Popup #{url} closed by clicking link with text '#{strg}'. #{desc}")
|
669
|
-
true
|
670
|
-
else
|
671
|
-
failed_to_log("Link :text=>'#{strg}' for popup #{url} not found. #{desc}")
|
672
|
-
end
|
673
|
-
end
|
674
|
-
rescue
|
675
|
-
failed_to_log("Close popup #{url} with click link :text+>'#{strg}' failed: '#{$!}' (#{__LINE__})")
|
676
|
-
debug_to_log("#{strg} appears #{count} times in popup.text.")
|
677
|
-
raise
|
678
|
-
end
|
679
|
-
|
680
|
-
# #close a modal dialog
|
681
|
-
def close_modal(browser, title="", button="OK", text='', side = 'primary', wait = WAIT)
|
682
|
-
case @targetBrowser.abbrev
|
683
|
-
when 'IE'
|
684
|
-
close_modal_ie(browser, title, button, text, side, wait)
|
685
|
-
when 'FF'
|
686
|
-
close_modal_ff(browser, title, button, text, side)
|
687
|
-
when 'S'
|
688
|
-
close_modal_s
|
689
|
-
when 'C', 'GC'
|
690
|
-
close_modal_c(browser, title)
|
691
|
-
end
|
692
|
-
end
|
693
|
-
|
694
|
-
# TODO: Logging
|
695
|
-
def close_modal_c(browser, title)
|
696
|
-
browser.window(:url, title).close
|
697
|
-
end
|
698
|
-
|
699
|
-
# TODO: Logging
|
700
|
-
def close_modal_s
|
701
|
-
# simply closes the frontmost Safari dialog
|
702
|
-
Appscript.app("Safari").activate; Appscript.app("System Events").processes["Safari"].key_code(52)
|
703
|
-
end
|
704
|
-
|
705
|
-
def close_modal_ie(browser, title="", button="OK", text='', side = 'primary', wait = WAIT, desc = '', quiet = false)
|
706
|
-
#TODO needs simplifying, incorporating text verification, and debug code cleaned up
|
707
|
-
title = translate_popup_title(title)
|
708
|
-
msg = "Modal window (popup) '#{title}'"
|
709
|
-
if @ai.WinWait(title, text, wait)
|
710
|
-
myHandle = @ai.WinGetHandle(title, text)
|
711
|
-
if myHandle.length > 0
|
712
|
-
debug_to_log("hwnd: #{myHandle.inspect}")
|
713
|
-
passed_to_log("#{msg} appeared.") unless quiet
|
714
|
-
window_handle = "[HANDLE:#{myHandle}]"
|
715
|
-
sleep_for(0.5)
|
716
|
-
@ai.WinActivate(window_handle)
|
717
|
-
if @ai.WinActive(window_handle)
|
718
|
-
debug_to_log("#{msg} activated.")
|
719
|
-
controlHandle = @ai.ControlGetHandle(title, '', "[CLASS:Button; TEXT:#{button}]")
|
720
|
-
if not controlHandle.length > 0
|
721
|
-
button = "&#{button}"
|
722
|
-
controlHandle = @ai.ControlGetHandle(title, '', "[CLASS:Button; TEXT:#{button}]")
|
723
|
-
end
|
724
|
-
debug_to_log("Handle for button '#{button}': [#{controlHandle}]")
|
725
|
-
debug_to_log("#{msg} focus gained.")
|
726
|
-
if @ai.ControlClick(title, '', "[CLASS:Button; TEXT:#{button}]")
|
727
|
-
passed_to_log("#{msg} #{side} click on '[CLASS:Button; TEXT:#{button}]' successful.")
|
728
|
-
sleep_for(0.5)
|
729
|
-
if @ai.WinExists(window_handle)
|
730
|
-
debug_to_log("#{msg} close popup failed on click '#{button}'. Trying WinClose. (#{__LINE__})")
|
731
|
-
@ai.WinClose(title, text)
|
732
|
-
if @ai.WinExists(window_handle)
|
733
|
-
debug_to_log("#{msg} close popup failed with WinClose(#{window_handle}). (#{__LINE__})")
|
734
|
-
@ai.WinKill(window_handle)
|
735
|
-
if @ai.WinExists(window_handle)
|
736
|
-
debug_to_log("#{msg} close popup failed with WinKill(#{window_handle}). (#{__LINE__})")
|
737
|
-
else
|
738
|
-
debug_to_log("#{msg} closed successfully with WinKill(#{window_handle}).")
|
739
|
-
end
|
740
|
-
else
|
741
|
-
debug_to_log("#{msg} closed successfully with WinClose(#{window_handle}).")
|
742
|
-
end
|
743
|
-
else
|
744
|
-
passed_to_log("#{msg} closed successfully.")
|
745
|
-
end
|
746
|
-
else
|
747
|
-
failed_to_log("#{msg} #{side} click on '[CLASS:Button; TEXT:#{button}]' failed. (#{window_handle}) (#{__LINE__})")
|
748
|
-
end
|
749
|
-
else
|
750
|
-
failed_to_log("#{msg} Unable to activate (#{window_handle}) (#{__LINE__})")
|
751
|
-
end
|
752
|
-
else
|
753
|
-
failed_to_log("#{msg} did not appear after #{wait} seconds. (#{window_handle}) (#{__LINE__})")
|
754
|
-
end
|
755
|
-
else
|
756
|
-
failed_to_log("#{msg} did not appear after #{wait} seconds.(#{window_handle}) (#{__LINE__})")
|
757
|
-
end
|
758
|
-
rescue
|
759
|
-
failed_to_log("Close popup title=#{title} failed: '#{$!}' (#{__LINE__})")
|
760
|
-
end
|
761
|
-
|
762
|
-
# private :close_modal_ie
|
763
|
-
|
764
|
-
def close_modal_ff(browser, title="", button=nil, text="", side='')
|
765
|
-
title = translate_popup_title(title)
|
766
|
-
msg = "Modal dialog (popup): title=#{title} button='#{button}' text='#{text}' side='#{side}':"
|
767
|
-
modal = browser.modal_dialog(:timeout => WAIT)
|
768
|
-
if modal.exists?
|
769
|
-
modal_text = modal.text
|
770
|
-
if text.length > 0
|
771
|
-
if modal_text =~ /#{text}/
|
772
|
-
passed_to_log("#{msg} appeared with match on '#{text}'.")
|
773
|
-
else
|
774
|
-
failed_to_log("#{msg} appeared but did not match '#{text}' ('#{modal_text}).")
|
775
|
-
end
|
776
|
-
else
|
777
|
-
passed_to_log("#{msg} appeared.")
|
778
|
-
end
|
779
|
-
if button
|
780
|
-
modal.click_button(button)
|
781
|
-
else
|
782
|
-
modal.close
|
783
|
-
end
|
784
|
-
if modal.exists?
|
785
|
-
failed_to_log("#{msg} close failed. (#{__LINE__})")
|
786
|
-
else
|
787
|
-
passed_to_log("#{msg} closed successfully.")
|
788
|
-
end
|
789
|
-
else
|
790
|
-
failed_to_log("#{msg} did not appear after #{WAIT} seconds. (#{__LINE__})")
|
791
|
-
end
|
792
|
-
rescue
|
793
|
-
failed_to_log("#{msg} Unable to validate modal popup: '#{$!}'. (#{__LINE__})")
|
794
|
-
end
|
795
|
-
|
796
|
-
def handle_popup(title, text = '', button= 'OK', side = 'primary', wait = WAIT, desc = '')
|
797
|
-
title = translate_popup_title(title)
|
798
|
-
msg = "'#{title}'"
|
799
|
-
if text.length > 0
|
800
|
-
msg << " with text '#{text}'"
|
801
|
-
end
|
802
|
-
@ai.Opt("WinSearchChildren", 1) # match title from start, forcing default
|
803
|
-
|
804
|
-
if button and button.length > 0
|
805
|
-
if button =~ /ok|yes/i
|
806
|
-
id = '1'
|
807
|
-
else
|
808
|
-
id = '2'
|
809
|
-
end
|
810
|
-
else
|
811
|
-
id = ''
|
812
|
-
end
|
813
|
-
|
814
|
-
if @ai.WinWait(title, '', wait) > 0
|
815
|
-
myHandle = @ai.WinGetHandle(title, '')
|
816
|
-
window_handle = "[HANDLE:#{myHandle}]"
|
817
|
-
full_text = @ai.WinGetText(window_handle)
|
818
|
-
debug_to_log("Found popup handle:'#{myHandle}', title:'#{title}', text:'#{full_text}'")
|
819
|
-
|
820
|
-
controlHandle = @ai.ControlGetHandle(window_handle, '', "[CLASS:Button; TEXT:#{button}]")
|
821
|
-
if not controlHandle
|
822
|
-
# button = "&#{button}"
|
823
|
-
controlHandle = @ai.ControlGetHandle(window_handle, '', "[CLASS:Button; TEXT:&#{button}]")
|
824
|
-
end
|
825
|
-
|
826
|
-
if text.length > 0
|
827
|
-
if full_text =~ /#{text}/
|
828
|
-
passed_to_log("Found popup handle:'#{myHandle}', title:'#{title}', text includes '#{text}'. #{desc}")
|
829
|
-
else
|
830
|
-
failed_to_log("Found popup handle:'#{myHandle}', title:'#{title}', text does not include '#{text}'. Closing it. #{desc}")
|
831
|
-
end
|
832
|
-
end
|
833
|
-
|
834
|
-
@ai.WinActivate(window_handle, '')
|
835
|
-
@ai.ControlClick(window_handle, '', id, side)
|
836
|
-
if @ai.WinExists(title, '') > 0
|
837
|
-
debug_to_log("#{msg} @ai.ControlClick on '#{button}' (ID:#{id}) with handle '#{window_handle}' failed to close window. Trying title.")
|
838
|
-
@ai.ControlClick(title, '', id, side)
|
839
|
-
if @ai.WinExists(title, '') > 0
|
840
|
-
debug_to_report("#{msg} @ai.ControlClick on '#{button}' (ID:#{id}) with title '#{title}' failed to close window. Forcing closed.")
|
841
|
-
@ai.WinClose(title, '')
|
842
|
-
if @ai.WinExists(title, '') > 0
|
843
|
-
debug_to_report("#{msg} @ai.WinClose on title '#{title}' failed to close window. Killing window.")
|
844
|
-
@ai.WinKill(title, '')
|
845
|
-
if @ai.WinExists(title, '') > 0
|
846
|
-
failed_to_log("#{msg} @ai.WinKill on title '#{title}' failed to close window")
|
847
|
-
else
|
848
|
-
passed_to_log("Killed: popup handle:'#{myHandle}', title:'#{title}'. #{desc}")
|
849
|
-
true
|
850
|
-
end
|
851
|
-
else
|
852
|
-
passed_to_log("Forced closed: popup handle:'#{myHandle}', title:'#{title}'. #{desc}")
|
853
|
-
true
|
854
|
-
end
|
855
|
-
else
|
856
|
-
passed_to_log("Closed on '#{button}': popup handle:'#{myHandle}', title:'#{title}'. #{desc}")
|
857
|
-
true
|
858
|
-
end
|
859
|
-
else
|
860
|
-
passed_to_log("Closed on '#{button}': popup handle:'#{myHandle}', title:'#{title}'. #{desc}")
|
861
|
-
true
|
862
|
-
end
|
863
|
-
|
864
|
-
else
|
865
|
-
failed_to_log("#{msg} did not appear after #{wait} seconds. #{desc} (#{__LINE__})")
|
866
|
-
end
|
867
|
-
rescue
|
868
|
-
failed_to_log("Unable to handle popup #{msg}: '#{$!}' #{desc} (#{__LINE__})")
|
869
|
-
|
870
|
-
end
|
871
|
-
|
872
|
-
def find_popup(browser, how, what, desc = '')
|
873
|
-
msg = "Find popup :#{how}=>'#{what}'. #{desc}"
|
874
|
-
popup = Watir::IE.find(how, what) # TODO: too browser specific
|
875
|
-
sleep_for(1)
|
876
|
-
debug_to_log("#{popup.inspect}")
|
877
|
-
if is_browser?(popup)
|
878
|
-
# title = popup.title
|
879
|
-
passed_to_log(msg)
|
880
|
-
return popup
|
881
|
-
else
|
882
|
-
failed_to_log(msg)
|
883
|
-
end
|
884
|
-
rescue
|
885
|
-
failed_to_log("Unable to find popup :#{how}=>'#{what}'. #{desc} '#{$!}' (#{__LINE__})")
|
886
|
-
end
|
887
|
-
|
888
|
-
def is_browser?(browser)
|
889
|
-
myClass = browser.class.to_s
|
890
|
-
case @targetBrowser.abbrev
|
891
|
-
when 'IE'
|
892
|
-
myClass =~ /Watir::/i # TODO: should this be /Watir::IE/i ?
|
893
|
-
when 'FF'
|
894
|
-
if @version.to_f < 4.0
|
895
|
-
myClass =~ /FireWatir::/i
|
896
|
-
else
|
897
|
-
myClass =~ /Watir::Browser/i
|
898
|
-
end
|
899
|
-
when 'S'
|
900
|
-
myClass =~ /Watir::Safari/i
|
901
|
-
when 'C'
|
902
|
-
myClass =~ /Watir::Browser/i
|
903
|
-
end
|
904
|
-
end
|
905
|
-
|
906
|
-
alias is_browser is_browser?
|
907
|
-
|
908
|
-
def translate_popup_title(title)
|
909
|
-
new_title = title
|
910
|
-
case @browserAbbrev
|
911
|
-
when 'IE'
|
912
|
-
if @browserVersion
|
913
|
-
case @browserVersion
|
914
|
-
when '8.0'
|
915
|
-
case title
|
916
|
-
when "Microsoft Internet Explorer"
|
917
|
-
new_title = "Message from webpage"
|
918
|
-
when "The page at"
|
919
|
-
new_title = "Message from webpage"
|
920
|
-
end
|
921
|
-
when '7.0'
|
922
|
-
case title
|
923
|
-
when "Message from webpage"
|
924
|
-
new_title = "Microsoft Internet Explorer"
|
925
|
-
when "The page at"
|
926
|
-
new_title = "Windows Internet Explorer"
|
927
|
-
end
|
928
|
-
when '6.0'
|
929
|
-
case title
|
930
|
-
when "Message from webpage"
|
931
|
-
new_title = "Microsoft Internet Explorer"
|
932
|
-
when "The page at"
|
933
|
-
new_title = "Microsoft Internet Explorer"
|
934
|
-
end
|
935
|
-
else
|
936
|
-
case title
|
937
|
-
when "Microsoft Internet Explorer"
|
938
|
-
new_title = "Message from webpage"
|
939
|
-
when "The page at"
|
940
|
-
new_title = "Message from webpage"
|
941
|
-
end
|
942
|
-
end
|
943
|
-
else
|
944
|
-
case title
|
945
|
-
when "Microsoft Internet Explorer"
|
946
|
-
new_title = "Message from webpage"
|
947
|
-
when "The page at"
|
948
|
-
new_title = "Message from webpage"
|
949
|
-
end
|
950
|
-
end
|
951
|
-
when 'FF'
|
952
|
-
case title
|
953
|
-
when 'File Download'
|
954
|
-
new_title = 'Opening'
|
955
|
-
when "Microsoft Internet Explorer"
|
956
|
-
new_title = 'The page at'
|
957
|
-
when "Message from webpage"
|
958
|
-
new_title = 'The page at'
|
959
|
-
end
|
960
|
-
when 'C'
|
961
|
-
case title
|
962
|
-
when 'File Download'
|
963
|
-
new_title = 'Save As'
|
964
|
-
when "Microsoft Internet Explorer"
|
965
|
-
new_title = 'The page at'
|
966
|
-
when "Message from webpage"
|
967
|
-
new_title = 'The page at'
|
968
|
-
end
|
969
|
-
end
|
970
|
-
new_title
|
971
|
-
end
|
972
|
-
|
973
|
-
def get_browser_version(browser)
|
974
|
-
debug_to_log("starting get_browser_version")
|
975
|
-
case @targetBrowser.abbrev
|
976
|
-
when 'IE'
|
977
|
-
@browserAbbrev = 'IE'
|
978
|
-
@browserName = 'Internet Explorer'
|
979
|
-
@browserAppInfo = browser.document.invoke('parentWindow').navigator.appVersion
|
980
|
-
@browserAppInfo =~ /MSIE\s(.*?);/
|
981
|
-
@browserVersion = $1
|
982
|
-
when 'FF'
|
983
|
-
#@browserAbbrev = 'FF'
|
984
|
-
#@browserName = 'Firefox'
|
985
|
-
#js_stuff = <<-end_js_stuff
|
986
|
-
#var info = Components.classes["@mozilla.org/xre/app-info;1"]
|
987
|
-
#.getService(Components.interfaces.nsIXULAppInfo);
|
988
|
-
#[info, info.name, info.version];
|
989
|
-
#end_js_stuff
|
990
|
-
#js_stuff.gsub!("\n", " ")
|
991
|
-
#info = browser.execute_script(js_stuff)
|
992
|
-
#info, aName, @browserVersion = info.split(',')
|
993
|
-
#debug_to_log("FF info: [#{info}]")
|
994
|
-
#debug_to_log("FF name: [#{aName}]")
|
995
|
-
#debug_to_log("FF vrsn: [#{@browserVersion}]")
|
996
|
-
@browserAbbrev = 'FF'
|
997
|
-
@browserName = 'Firefox'
|
998
|
-
@browserVersion = '6.01' #TODO: get actual version from browser
|
999
|
-
debug_to_log("Firefox, in get_browser_version (#{@browserVersion})")
|
1000
|
-
when 'S'
|
1001
|
-
@browserAbbrev = 'S'
|
1002
|
-
@browserName = 'Safari'
|
1003
|
-
@browserVersion = '5.0.4' #TODO: get actual version from browser itself
|
1004
|
-
debug_to_log("Safari, in get_browser_version (#{@browserVersion})")
|
1005
|
-
when 'C'
|
1006
|
-
@browserAbbrev = 'C'
|
1007
|
-
@browserName = 'Chrome'
|
1008
|
-
@browserVersion = '11.0' #TODO: get actual version from browser
|
1009
|
-
debug_to_log("Chrome, in get_browser_version (#{@browserVersion})")
|
1010
|
-
end
|
1011
|
-
# if [notify_queue, notify_class, notify_id].all?
|
1012
|
-
# Resque::Job.create(notify_queue, notify_class, :id => notify_id, :browser_used => "#{@browserName} #{@browserVersion}")
|
1013
|
-
#end
|
1014
|
-
rescue
|
1015
|
-
debug_to_log("Unable to determine #{@browserAbbrev} browser version: '#{$!}' (#{__LINE__})")
|
1016
|
-
|
1017
|
-
# TODO: can we get rid of this?
|
1018
|
-
# js for getting firefox version information
|
1019
|
-
# function getAppID() {
|
1020
|
-
# var id;
|
1021
|
-
# if("@mozilla.org/xre/app-info;1" in Components.classes) {
|
1022
|
-
# // running under Mozilla 1.8 or later
|
1023
|
-
# id = Components.classes["@mozilla.org/xre/app-info;1"]
|
1024
|
-
# .getService(Components.interfaces.nsIXULAppInfo).ID;
|
1025
|
-
# } else {
|
1026
|
-
# try {
|
1027
|
-
# id = Components.classes["@mozilla.org/preferences-service;1"]
|
1028
|
-
# .getService(Components.interfaces.nsIPrefBranch)
|
1029
|
-
# .getCharPref("app.id");
|
1030
|
-
# } catch(e) {
|
1031
|
-
# // very old version
|
1032
|
-
# dump(e);
|
1033
|
-
# }
|
1034
|
-
# }
|
1035
|
-
# return id;
|
1036
|
-
# }
|
1037
|
-
# alert(getAppID());
|
1038
|
-
# another snippet that shows getting attributes from object
|
1039
|
-
# var info = Components.classes["@mozilla.org/xre/app-info;1"]
|
1040
|
-
# .getService(Components.interfaces.nsIXULAppInfo);
|
1041
|
-
# // Get the name of the application running us
|
1042
|
-
# info.name; // Returns "Firefox" for Firefox
|
1043
|
-
# info.version; // Returns "2.0.0.1" for Firefox version 2.0.0.1
|
1044
|
-
ensure
|
1045
|
-
message_to_log("Browser: [#{@browserAbbrev} #{@browserVersion}]")
|
1046
|
-
end
|
1047
|
-
|
1048
|
-
protected :get_browser_version
|
1049
|
-
|
1050
|
-
def close_popup_by_button_title(popup, strg, desc = '')
|
1051
|
-
click(popup, :link, :title, strg, desc)
|
1052
|
-
end
|
1053
|
-
|
1054
|
-
def filter_bailout_from_rescue(err, msg)
|
1055
|
-
if msg =~ /bailing out/i
|
1056
|
-
raise err
|
1057
|
-
else
|
1058
|
-
error_to_log(msg)
|
1059
|
-
end
|
1060
|
-
end
|
1061
|
-
|
1062
|
-
def open_popup_through_link_title(browser, title, pattern, name)
|
1063
|
-
click_title(browser, title)
|
1064
|
-
#TODO need some kind of wait for process here
|
1065
|
-
sleep_for 2
|
1066
|
-
attach_iepopup(browser, pattern, name)
|
1067
|
-
rescue
|
1068
|
-
failed_to_log("Unable to open popup '#{name}': '#{$!}' (#{__LINE__})")
|
1069
|
-
end
|
1070
|
-
|
1071
|
-
=begin rdoc
|
1072
|
-
Verifies health of the browser. Looks for common http and system errors that are unrecoverable and
|
1073
|
-
attempts to gracefully bail out of the script. Calls rescue_me() when trying to capture the text to filter out
|
1074
|
-
known false errors and handle container elements that don't respond to the .text method.
|
1075
|
-
category: bullet-proofing
|
1076
|
-
tags: system, http, fatal, error
|
1077
|
-
example: See click()
|
1078
|
-
related methods: rescue_me()
|
1079
|
-
=end
|
1080
|
-
def validate(browser, fileName = '', lnbr = __LINE__, dbg = false)
|
1081
|
-
debug_to_log("#{__method__} begin") if dbg
|
1082
|
-
msg = ''
|
1083
|
-
myOK = true
|
1084
|
-
if not browser
|
1085
|
-
msg = "#{fileName}----browser is nil object. (#{lnbr})"
|
1086
|
-
myOK = false
|
1087
|
-
elsif not is_browser?(browser)
|
1088
|
-
msg = "#{fileName}----not a browser. (#{lnbr})"
|
1089
|
-
debug_to_log(browser.inspect)
|
1090
|
-
myOK = false
|
1091
|
-
|
1092
|
-
else
|
1093
|
-
if browser.respond_to?(:url)
|
1094
|
-
if not browser.url == @currentURL
|
1095
|
-
@currentURL = browser.url
|
1096
|
-
debug_to_log("Current URL: [#{@currentURL}]")
|
1097
|
-
# mark_testlevel( "Current URL: [#{@currentURL}]", 1 )
|
1098
|
-
end
|
1099
|
-
end
|
1100
|
-
|
1101
|
-
if @capture_js_errors
|
1102
|
-
if browser.respond_to?(:status)
|
1103
|
-
if browser.status.downcase =~ /errors? on page/ and
|
1104
|
-
not browser.status.downcase.include?('Waiting for')
|
1105
|
-
capture_js_error(browser)
|
1106
|
-
end
|
1107
|
-
end
|
1108
|
-
end
|
1109
|
-
|
1110
|
-
begin
|
1111
|
-
browser_text = browser.text.downcase
|
1112
|
-
rescue => e
|
1113
|
-
if not rescue_me(e, __method__, "browser.text.downcase", "#{browser.class}", browser)
|
1114
|
-
debug_to_log("browser.text.downcase in #{__method__} #{browser.class}")
|
1115
|
-
debug_to_log("#{get_callers}")
|
1116
|
-
raise e
|
1117
|
-
else
|
1118
|
-
return true
|
1119
|
-
end
|
1120
|
-
end
|
1121
|
-
|
1122
|
-
if browser_text
|
1123
|
-
if browser_text.match(/unrecognized error condition has occurred/i)
|
1124
|
-
msg = "#{fileName}----Unrecognized Exception occurred. (#{lnbr})"
|
1125
|
-
myOK = false
|
1126
|
-
|
1127
|
-
elsif browser_text.match(/cannot find server or dns error/i)
|
1128
|
-
msg = "#{fileName}----Cannot find server error or DNS error. (#{lnbr})"
|
1129
|
-
myOK = false
|
1130
|
-
|
1131
|
-
elsif browser_text.match(/the rpc server is unavailable/i)
|
1132
|
-
msg = "#{fileName}----RPC server unavailable. (#{lnbr})"
|
1133
|
-
myOK = false
|
1134
|
-
|
1135
|
-
elsif browser_text.match(/404 not found/i) or
|
1136
|
-
browser_text.match(/the page you were looking for does\s*n[o']t exist/i)
|
1137
|
-
msg = "#{fileName}----RFC 2068 HTTP/1.1: 404 URI Not Found. (#{lnbr})"
|
1138
|
-
myOK = false
|
1139
|
-
|
1140
|
-
elsif browser_text.match(/we're sorry, but something went wrong/i) or
|
1141
|
-
browser_text.match(/http status 500/i)
|
1142
|
-
msg = "#{fileName}----RFC 2068 HTTP/1.1: 500 Internal Server Error. (#{lnbr})"
|
1143
|
-
myOK = false
|
1144
|
-
|
1145
|
-
elsif browser_text.match(/internet explorer cannot display the webpage/i)
|
1146
|
-
msg = "#{fileName}----Probably RFC 2068 HTTP/1.1: 500 Internal Server Error. (#{lnbr})"
|
1147
|
-
myOK = false
|
1148
|
-
|
1149
|
-
elsif browser_text.match(/503.*service unavailable/i)
|
1150
|
-
msg = "#{fileName}----RFC 2068 HTTP/1.1: 503 Service Unavailable. (#{lnbr})"
|
1151
|
-
myOK = false
|
1152
|
-
|
1153
|
-
elsif browser_text.match(/java.lang.NullPointerException/i)
|
1154
|
-
msg = "#{fileName}----java.lang.NullPointerException. (#{lnbr})"
|
1155
|
-
myOK = false
|
1156
|
-
|
1157
|
-
elsif browser_text.match(/due to unscheduled maintenance/i)
|
1158
|
-
msg = "#{fileName}----Due to unscheduled maintenance. (#{lnbr})"
|
1159
|
-
myOK = false
|
1160
|
-
|
1161
|
-
elsif browser_text.match(/network\s+error\s*(.+)$/i)
|
1162
|
-
$1.chomp!
|
1163
|
-
msg = "#{fileName}----Network Error #{$1}. (#{lnbr})"
|
1164
|
-
myOK = false
|
1165
|
-
|
1166
|
-
elsif browser_text.match(/warning: page has expired/i)
|
1167
|
-
msg = "#{fileName}----Page using information from form has expired. Not automatically resubmitted. (#{lnbr})"
|
1168
|
-
myOK = false
|
1169
|
-
|
1170
|
-
elsif browser_text.match(/no backend server available/i)
|
1171
|
-
msg = "#{fileName}----Cannot Reach Server (#{lnbr})"
|
1172
|
-
myOK = false
|
1173
|
-
|
1174
|
-
elsif browser_text.match(/sign on\s+.+\s+unsuccessful/i)
|
1175
|
-
msg = "#{fileName}----Invalid Id or Password (#{lnbr})"
|
1176
|
-
myOK = false
|
1177
|
-
|
1178
|
-
elsif browser_text.match(/you are not authorized/i)
|
1179
|
-
msg = "#{fileName}----Not authorized to view this page. (#{lnbr})"
|
1180
|
-
myOK = false
|
1181
|
-
|
1182
|
-
elsif browser_text.match(/too many incorrect login attempts have been made/i)
|
1183
|
-
msg = "#{fileName}----Invalid Id or Password. Too many tries. (#{lnbr})"
|
1184
|
-
myOK = false
|
1185
|
-
|
1186
|
-
elsif browser_text.match(/system error\.\s+an error has occurred/i)
|
1187
|
-
msg = "#{fileName}----System Error. An error has occurred. Please try again or call the Help Line for assistance. (#{lnbr})"
|
1188
|
-
myOK = false
|
1189
|
-
|
1190
|
-
elsif browser_text.match(/Internal Server failure,\s+NSAPI plugin/i)
|
1191
|
-
msg = "#{fileName}----Internal Server failure, NSAPI plugin. (#{lnbr})"
|
1192
|
-
myOK = false
|
1193
|
-
|
1194
|
-
elsif browser_text.match(/Error Page/i)
|
1195
|
-
msg = "#{fileName}----Error Page. (#{lnbr})"
|
1196
|
-
myOK = false
|
1197
|
-
|
1198
|
-
elsif browser_text.match(/The website cannot display the page/i)
|
1199
|
-
msg = "#{fileName}----HTTP 500. (#{lnbr})"
|
1200
|
-
myOK = false
|
1201
|
-
|
1202
|
-
# elsif browser_text.match(/Insufficient Data/i)
|
1203
|
-
# msg = "#{fileName}----Insufficient Data. (#{lnbr})"
|
1204
|
-
# myOK = false
|
1205
|
-
|
1206
|
-
elsif browser_text.match(/The timeout period elapsed/i)
|
1207
|
-
msg = "#{fileName}----Time out period elapsed or server not responding. (#{lnbr})"
|
1208
|
-
myOK = false
|
1209
|
-
|
1210
|
-
elsif browser_text.match(/Unexpected\s+errors*\s+occur+ed\.\s+(?:-+)\s+(.+)/i)
|
1211
|
-
msg = "#{fileName}----Unexpected errors occurred. #{$2.slice(0, 120)} (#{lnbr})"
|
1212
|
-
if not browser_text.match(/close the window and try again/i)
|
1213
|
-
myOK = false
|
1214
|
-
else
|
1215
|
-
debug_to_log("#{msg}")
|
1216
|
-
end
|
1217
|
-
|
1218
|
-
elsif browser_text.match(/Server Error in (.+) Application\.\s+(?:-+)\s+(.+)/i)
|
1219
|
-
msg = "#{fileName}----Server Error in #{1} Application. #{$2.slice(0, 100)} (#{lnbr})"
|
1220
|
-
myOK = false
|
1221
|
-
|
1222
|
-
elsif browser_text.match(/Server Error in (.+) Application\./i)
|
1223
|
-
msg = "#{fileName}----Server Error in #{1} Application. '#{browser_text.slice(0, 250)}...' (#{lnbr})"
|
1224
|
-
myOK = false
|
1225
|
-
|
1226
|
-
elsif browser_text.match(/An error has occur+ed\. Please contact support/i)
|
1227
|
-
msg = "#{fileName}----An error has occurred. Please contact support (#{lnbr})"
|
1228
|
-
myOK = false
|
1229
|
-
|
1230
|
-
end
|
1231
|
-
else
|
1232
|
-
debug_to_log("browser.text returned nil")
|
1233
|
-
end
|
1234
|
-
end
|
1235
|
-
|
1236
|
-
if not myOK
|
1237
|
-
msg << " (#{browser.url})"
|
1238
|
-
puts msg
|
1239
|
-
debug_to_log(browser.inspect)
|
1240
|
-
debug_to_log(browser.text)
|
1241
|
-
fatal_to_log(msg, lnbr)
|
1242
|
-
raise(RuntimeError, msg, caller)
|
1243
|
-
else
|
1244
|
-
debug_to_log("#{__method__} returning OK") if dbg
|
1245
|
-
return myOK
|
1246
|
-
end
|
1247
|
-
|
1248
|
-
rescue
|
1249
|
-
errmsg = $!
|
1250
|
-
if errmsg.match(msg)
|
1251
|
-
errmsg = ''
|
1252
|
-
end
|
1253
|
-
bail_out(browser, lnbr, "#{msg} #{errmsg}")
|
1254
|
-
end
|
1255
|
-
|
1256
|
-
alias validate_browser validate
|
1257
|
-
|
1258
|
-
|
1259
|
-
end
|