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