awetestlib 0.1.30-x86-mingw32 → 1.2.4-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +101 -41
  3. data/awetestlib.gemspec +36 -47
  4. data/awetestlib_osx.gemspec +24 -18
  5. data/awetestlib_windows.gemspec +46 -0
  6. data/bin/awetestlib +130 -111
  7. data/bin/awetestlib-driver-setup.rb +0 -2
  8. data/bin/awetestlib-helpers.rb +43 -30
  9. data/lib/awetestlib.rb +196 -20
  10. data/lib/awetestlib/command_line.rb +44 -0
  11. data/lib/awetestlib/html_report.rb +57 -50
  12. data/lib/awetestlib/logging.rb +242 -171
  13. data/lib/awetestlib/regression/awetest_dsl.rb +4240 -0
  14. data/lib/awetestlib/regression/browser.rb +514 -397
  15. data/lib/awetestlib/regression/date_and_time.rb +280 -0
  16. data/lib/awetestlib/regression/drag_and_drop.rb +24 -0
  17. data/lib/awetestlib/regression/find.rb +70 -43
  18. data/lib/awetestlib/regression/legacy.rb +1 -1
  19. data/lib/awetestlib/regression/mobile.rb +293 -0
  20. data/lib/awetestlib/regression/reporting.rb +298 -0
  21. data/lib/awetestlib/regression/runner.rb +156 -200
  22. data/lib/awetestlib/regression/tables.rb +117 -7
  23. data/lib/awetestlib/regression/test_data.rb +354 -0
  24. data/lib/awetestlib/regression/user_input.rb +179 -93
  25. data/lib/awetestlib/regression/utilities.rb +755 -286
  26. data/lib/awetestlib/regression/validations.rb +325 -115
  27. data/lib/awetestlib/regression/waits.rb +60 -133
  28. data/lib/awetestlib/runner.rb +5 -2
  29. data/lib/version.rb +11 -2
  30. data/setup_samples/sample_cucumber/features/step_definitions/predefined_steps.rb +109 -49
  31. data/setup_samples/sample_mobile_app/features/support/env.rb +1 -1
  32. data/test/google_search2.rb +7 -6
  33. data/test/popup_child_0.rb +13 -0
  34. data/test/popup_child_1.rb +33 -0
  35. data/test/watir_no_require.rb +13 -0
  36. data/test/watir_with_require.rb +16 -0
  37. data/test/zoho_exercise.rb +8 -8
  38. metadata +216 -303
  39. data/AwetestLib Instructions.rtf +0 -0
  40. data/awetestlib.windows.gemspec +0 -42
  41. data/lib/patches/README +0 -2
  42. data/lib/patches/firewatir.rb +0 -106
  43. data/lib/patches/watir.rb +0 -175
@@ -4,36 +4,24 @@ module Awetestlib
4
4
  # Methods to manage browser windows: open, close, attach, verify health, and clean up.
5
5
  module Browser
6
6
 
7
- #def run #DO WE NEED? Use this method to tell user they need to create a run method?
8
- ## Not here in any case.
9
- # setup
10
- # set_script_variables
11
- # run_test
12
- #rescue
13
- # fatal_to_log("(#{__LINE__}) #{$!}")
14
- # browser.close
15
- # raise
16
- #end
17
-
18
7
  # @!group Browser
19
8
 
20
- # @note webdriver specific - still work in progress
21
9
  def go_to_wd_url(browser, url)
22
10
 
23
11
  Watir::Browser.class_eval do
24
12
  def goto(uri)
25
13
  uri = "http://#{uri}" unless uri =~ URI.regexp
26
- @driver.navigate.to uri
14
+ begin
15
+ @driver.navigate.to uri
16
+ rescue => e
17
+ debug_to_log("#{e.inspect} '#{$!}'")
18
+ end
27
19
  run_checkers
28
20
  end
29
21
  end
30
22
  browser.goto(url)
31
-
32
- #in basic_auth1 edit:
33
- #a = Thread.new {
34
- # goto_wd_url(browser, @myURL)
35
- # }
36
-
23
+ rescue
24
+ failed_to_log(unable_to)
37
25
  end
38
26
 
39
27
  alias goto_wd_url go_to_wd_url
@@ -46,30 +34,61 @@ module Awetestlib
46
34
  # @param [String, Regexp] url When provided, the browser will go to this url.
47
35
  # @return [Watir::Browser]
48
36
  def open_browser(url = nil)
49
- message_to_report("Opening browser: #{@targetBrowser.name}")
50
- case @targetBrowser.abbrev
51
- when 'IE'
52
- @myBrowser = open_ie
53
- if @myBrowser.class.to_s == "Watir::IE"
54
- @myHwnd = @myBrowser.hwnd
55
- end
56
- when 'FF'
57
- @myBrowser = open_ff
58
- when 'S'
59
- if USING_OSX
60
- @myBrowser = open_safari
37
+ message_to_report("Opening browser: #{@targetBrowser.abbrev}")
38
+
39
+ browser = nil
40
+
41
+ if $mobile
42
+ end_android_processes if $platform == :android
43
+ clean_up_android_temp unless $device
44
+ sleep_for(3)
45
+ browser = open_mobile_browser
46
+ else
47
+ case @targetBrowser.abbrev
48
+ when 'IE'
49
+ browser = open_ie
50
+ if browser.class.to_s == "Watir::IE"
51
+ @myHwnd = browser.hwnd
52
+ end
53
+ when 'FF'
54
+ browser = open_ff
55
+ when 'S'
56
+ if USING_OSX
57
+ browser = open_safari
58
+ else
59
+ fail "Safari is not supported under this operating system #{RUBY_PLATFORM}"
60
+ end
61
+ when 'C', 'GC'
62
+ browser = open_chrome
61
63
  else
62
- raise "Safari is not supported under this operating system #{RUBY_PLATFORM}"
63
- end
64
- when 'C', 'GC'
65
- @myBrowser = open_chrome
66
- else
67
- raise "Unsupported browser: #{@targetBrowser.name}"
64
+ fail "Unsupported browser: #{@targetBrowser.name} (#{@targetBrowser.abbrev})"
65
+ end
68
66
  end
69
- if url
70
- go_to_url(@myBrowser, url)
67
+
68
+ if browser and url
69
+ go_to_url(browser, url)
70
+ end
71
+
72
+ get_browser_version(browser)
73
+ message_to_report("Opened browser: #{@browserName} #{@browserVersion}")
74
+ #message_to_log(@browserName)
75
+ #message_to_log(@browserVersion)
76
+
77
+ @myBrowser = browser
78
+
79
+ rescue
80
+ failed_to_log(unable_to)
81
+ end
82
+
83
+ def browser_driver(browser)
84
+ if @myBrowser.class.to_s =~ /IE/
85
+ @actualBrowser.driver = 'Watir Classic'
86
+ $using_webdriver = false
87
+ else
88
+ #@actualBrowser.driver = "Watir-webdriver #{@myBrowser.driver.capabilities.browser_name.titleize}"
89
+ $using_webdriver = true
71
90
  end
72
- @myBrowser
91
+ #message_to_report("Running with #{@actualBrowser.driver}")
73
92
  end
74
93
 
75
94
  # Open IE (Internet Explorer) browser instance.
@@ -78,31 +97,41 @@ module Awetestlib
78
97
  # otherwise Watir Webdriver will be used.
79
98
  # @return [Watir::Browser]
80
99
  def open_ie
81
- if $watir_script
82
- browser = Watir::IE.new
83
- else
84
- browser = Watir::Browser.new :ie
85
- end
86
- browser
100
+ #browser = Watir::Browser.new :ie
101
+ caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer(
102
+ #:nativeEvents => false,
103
+ #'nativeEvents' => false,
104
+ :initialBrowserUrl => 'about:blank',
105
+ :enablePersistentHover => false,
106
+ :ignoreProtectedModeSettings => true,
107
+ :introduceInstabilityByIgnoringProtectedModeSettings => true,
108
+ :unexpectedAlertBehaviour => 'ignore'
109
+ )
110
+ Watir::Browser.new(:ie, :desired_capabilities => caps)
111
+ rescue
112
+ failed_to_log(unable_to)
87
113
  end
88
114
 
89
115
  # Open Safari browser instance.
90
116
  # @note Safari currently supported only on Mac OS X
91
117
  # @return [Watir::Browser]
92
118
  def open_safari
93
- browser = Watir::Browser.new(:remote, :desired_capabilities=>:'safari')
119
+ Watir::Browser.new(:remote, :desired_capabilities => :'safari')
94
120
  end
95
121
 
96
122
  # Open FF (Firefox) browser instance under FireWatir.
97
123
  # @return [Watir::Browser]
98
124
  def open_ff
99
- browser = Watir::Browser.new :firefox
125
+ Watir::Browser.new :firefox
100
126
  end
101
127
 
102
128
  # Open GC (Google Chrome) browser instance.
103
129
  # @return [Watir::Browser] Browser is Google Chrome.
104
130
  def open_chrome
105
- browser = Watir::Browser.new(:chrome)
131
+ client = Selenium::WebDriver::Remote::Http::Default.new
132
+ client.timeout = 180 # seconds � default is 60
133
+
134
+ Watir::Browser.new(:chrome, :http_client => client)
106
135
  end
107
136
 
108
137
  # Instruct browser to navigate to a specific URL
@@ -114,7 +143,7 @@ module Awetestlib
114
143
  if url
115
144
  @myURL = url
116
145
  end
117
- message_to_report("URL: #{@myURL}")
146
+ message_to_report(with_caller("URL: #{@myURL}"))
118
147
  browser.goto(@myURL)
119
148
  true
120
149
  rescue
@@ -122,94 +151,53 @@ module Awetestlib
122
151
  end
123
152
 
124
153
  # Return a reference to a browser window. Used to attach a browser window to a variable
125
- # which can then be passed to methods that require a *browser* parameter.
154
+ # which can then be passed to methods that require a *browser* parameter containing a Browser object.
126
155
  # @example
127
156
  # mainwindow = open_browser('www.google.com')
128
157
  # click(mainwindow, :button, :id, 'an id string') # click a button that opens another browser window
129
158
  # popup = attach_browser(mainwindow, :url, '[url of new window]') #*or*
130
159
  # popup = attach_browser(mainwindow, :title, '[title of new window]')
131
- # @todo Update to work with webdriver for IE.
132
160
  # @param [Watir::Browser] browser A reference to the current browser window.
133
161
  # @param [Symbol] how The element attribute used to identify the window: *:title* or :url.
134
162
  # @param [String|Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
135
163
  # @param [String] desc Contains a message or description intended to appear in the log and/or report output
136
- # @return [Watir::Browser] Internet Explorer
137
- def attach_browser(browser, how, what, desc = '')
138
- debug_to_log("Attaching browser window :#{how}=>'#{what}' #{desc}")
164
+ # @param [String] refs List of reference identifiers to include in log/report message
165
+ # @return [Watir::Browser]
166
+ def attach(browser, how, what, desc = '', refs = '')
167
+ msg = "Attaching browser window :#{how}='#{what}' #{desc} #{refs}"
168
+ debug_to_report(with_caller(msg))
139
169
  uri_decoded_pattern = ::URI.encode(what.to_s.gsub('(?-mix:', '').gsub(')', ''))
140
-
141
- if $watir_script
142
- tmpbrowser = Watir::IE.attach(how, what)
143
- browser.visible = true
144
- if tmpbrowser
145
- tmpbrowser.visible = true
146
- tmpbrowser.speed = :fast
147
- else
148
- raise "Browser window :#{how}=>'#{what}' has at least one doc not in completed ready state."
149
- end
150
- else
151
- browser.driver.switch_to.window(browser.driver.window_handles[0])
152
- browser.window(how, /#{uri_decoded_pattern}/).use
153
- tmpbrowser = browser
154
- end
155
-
156
- # case @browserAbbrev
157
- # when 'IE'
158
- # tmpbrowser = Watir::IE.attach(how, what)
159
- # browser.visible = true
160
- # if tmpbrowser
161
- # tmpbrowser.visible = true
162
- # tmpbrowser.speed = :fast
163
- # else
164
- # raise "Browser window :#{how}=>'#{what}' has at least one doc not in completed ready state."
165
- # end
166
- # when 'FF'
167
- # #TODO: This may be dependent on Firefox version if webdriver doesn't support 3.6.17 and below
168
- # browser.driver.switch_to.window(browser.driver.window_handles[0])
169
- # browser.window(how, /#{uri_decoded_pattern}/).use
170
- # tmpbrowser = browser
171
- # when 'S'
172
- # Watir::Safari.attach(how, what)
173
- # tmpbrowser = browser
174
- # when 'C', 'GC'
175
- # browser.window(how, /#{uri_decoded_pattern}/).use
176
- # tmpbrowser = browser
177
- # end
178
-
179
-
180
- debug_to_log("#{__method__}: tmpbrowser:#{tmpbrowser.inspect}")
181
- tmpbrowser
170
+ debug_to_log(with_caller(uri_decoded_pattern))
171
+ browser.driver.switch_to.window(browser.driver.window_handles[0])
172
+ browser.window(how, what).use
173
+ browser
174
+ rescue
175
+ failed_to_log(unable_to(msg))
182
176
  end
183
177
 
184
-
185
- # Returns a reference to a new browser window. Used to attach a new browser window to a variable
186
- # which can then be passed to methods that require a *browser* parameter. Calls attach_browser().
187
- # @example
188
- # mainwindow = open_browser('www.google.com')
189
- # click(mainwindow, :button, :id, 'an id string') # click a button that opens another browser window
190
- # popup = attach_popup(mainwindow, :url, '[url of new window]') *or*
191
- # popup = attach_popup(mainwindow, :title, '[title of new window]')
192
- # @param [Watir::Browser] browser A reference to the current browser window.
193
- # @param [Symbol] how The element attribute used to identify the window: *:title* or :url.
194
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
195
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
196
- # @return [Watir::Browser] The new browser window.
197
- def attach_popup(browser, how, what, desc = '')
198
- msg = "Attach popup :#{how}=>'#{what}'. #{desc}"
199
- popup = attach_browser(browser, how, what, desc)
200
- sleep_for(1)
201
- debug_to_log("#{popup.inspect}")
202
- if is_browser?(popup)
203
- title = popup.title
204
- passed_to_log("#{msg} title='#{title}'")
205
- return popup
178
+ alias find_popup attach
179
+ alias find_window attach
180
+ alias attach_popup attach
181
+ alias attach_window attach
182
+ alias attach_browser attach
183
+ alias use_window attach
184
+
185
+ def re_attach(browser, window = 0)
186
+ if $using_webdriver
187
+ @myBrowser.driver.switch_to.window(browser.driver.window_handles[window])
188
+ #@myBrowser.window.use
206
189
  else
207
- failed_to_log(msg)
190
+ case window
191
+ when 0
192
+ @myBrowser
193
+ else
194
+ @myBrowser
195
+ end
208
196
  end
209
- rescue
210
- failed_to_log("Unable to attach popup :#{how}=>'#{what}'. #{desc} '#{$!}' (#{__LINE__})")
211
197
  end
212
198
 
199
+ alias re_attach_window re_attach
200
+
213
201
  # Locate and close instances of IE browsers
214
202
  def find_other_browsers
215
203
  cnt = 0
@@ -270,38 +258,100 @@ module Awetestlib
270
258
  # @param [Boolean] bypass_validate When set to true, the call to validate(),
271
259
  # which checks the health of the browser, is skipped..
272
260
  def basic_auth(browser, user, password, url, bypass_validate = false)
273
- mark_testlevel("Basic Authorization Login", 0)
274
-
275
- message_to_report ("Login: #{user}")
276
- message_to_report ("URL: #{url}")
277
- message_to_report ("Password: #{password}")
261
+ mark_test_level("Login")
278
262
 
279
- @login_title = "Connect to"
263
+ get_browser_version(browser)
264
+ message_to_log(@browserName)
265
+ message_to_log(@browserVersion)
266
+ message_to_log("Login: #{user}")
267
+ message_to_log("URL: #{url}")
268
+ message_to_log("Password: #{password}")
269
+ debug_to_report("@user: #{user}, @pass: #{password} (#{__LINE__})")
280
270
 
281
- a = Thread.new {
282
- browser.goto(url)
283
- }
284
-
285
- sleep_for(2)
286
- message_to_log("#{@login_title}...")
271
+ case @browserAbbrev
272
+ when 'IE', 'FF'
273
+
274
+ user_name, pass_word, login_button, login_title = get_basic_auth_control_indexes
275
+
276
+ a = Thread.new {
277
+ begin
278
+ #go_to_wd_url(browser, url)
279
+ browser.goto(url)
280
+ Watir::Wait.until(5) { browser.alert.exists? }
281
+ rescue => e
282
+ debug_to_log("#{__LINE__}: #{e.inspect}")
283
+ rescue => e
284
+ debug_to_log("#{__LINE__}: #{e.inspect}")
285
+ end
286
+ }
287
+
288
+ sleep(1)
289
+ message_to_log("#{login_title}...")
290
+ if @ai.WinWait(login_title, "", 90) > 0
291
+ win_title = @ai.WinGetTitle(login_title)
292
+ debug_to_log("Basic Auth Login window appeared: '#{win_title}'")
293
+ @ai.WinActivate(login_title)
294
+
295
+ case @browserAbbrev
296
+ when 'FF'
297
+ @ai.Send(user)
298
+ @ai.Send('{TAB}')
299
+ @ai.Send(password)
300
+ sleep(1)
301
+ @ai.Send('{ENTER}')
302
+ when 'IE'
303
+ begin
304
+ @ai.ControlSend(login_title, '', "[CLASS:Edit; INSTANCE:#{user_name}]", '!u')
305
+ @ai.ControlSetText(login_title, '', "[CLASS:Edit; INSTANCE:#{user_name}]", user)
306
+ @ai.ControlSetText(login_title, '', "[CLASS:Edit; INSTANCE:#{pass_word}]", password.gsub(/!/, '{!}'))
307
+ sleep(1)
308
+ @ai.ControlClick(login_title, "", "[CLASS:Button; INSTANCE:#{login_button}]")
309
+ rescue => e
310
+ debug_to_log("#{__LINE__}: #{e.inspect}")
311
+ rescue => e
312
+ debug_to_log("#{__LINE__}: #{e.inspect}")
313
+ end
314
+ end
315
+ else
316
+ debug_to_log("Basic Auth Login window '#{login_title}' did not appear.")
317
+ end
318
+ begin
319
+ a.join
320
+ rescue => e
321
+ debug_to_log("#{__LINE__}: #{e.inspect}")
322
+ rescue => e
323
+ debug_to_log("#{__LINE__}: #{e.inspect}")
324
+ end
325
+ begin
326
+ validate(browser, @myName) unless bypass_validate
327
+ rescue => e
328
+ debug_to_log("#{__LINE__}: #{e.inspect}")
329
+ rescue => e
330
+ debug_to_log("#{__LINE__}: #{e.inspect}")
331
+ end
287
332
 
288
- if (@ai.WinWait(@login_title, "", 90) > 0)
289
- win_title = @ai.WinGetTitle(@login_title)
290
- debug_to_log("Basic Auth Login window appeared: '#{win_title}'")
291
- @ai.WinActivate(@login_title)
292
- @ai.ControlSend(@login_title, '', "[CLASS:Edit; INSTANCE:2]", '!u')
293
- @ai.ControlSend(@login_title, '', "[CLASS:Edit; INSTANCE:2]", user, 1)
294
- @ai.ControlSend(@login_title, '', "[CLASS:Edit; INSTANCE:3]", password.gsub(/!/, '{!}'), 1)
295
- @ai.ControlClick(@login_title, "", '[CLASS:Button; INSTANCE:1]')
296
- else
297
- debug_to_log("Basic Auth Login window did not appear.")
333
+ when 'GC', 'C'
334
+ browser.goto(url)
335
+ sleep(2)
336
+ browser.alert.use do
337
+ browser.send_keys(user)
338
+ browser.send_keys("{TAB}")
339
+ browser.send_keys(password)
340
+ browser.send_keys("~") # Enter
341
+ end
342
+ browser.windows[0].use
343
+ #when 'FF'
344
+ # aug_url = insert_id_pswd_in_url(user, password, url)
345
+ # debug_to_log("urL: #{url}\naug: #{aug_url}")
346
+ # go_to_wd_url(browser, aug_url)
298
347
  end
299
- a.join
300
-
301
- validate(browser, @myName) unless bypass_validate
302
348
 
303
- message_to_report("URL: [#{browser.url}] User: [#{user}]")
349
+ message_to_log("URL: [#{browser.url}]")
304
350
 
351
+ rescue => e
352
+ debug_to_log("#{__LINE__}: #{e.inspect}")
353
+ rescue => e
354
+ debug_to_log("#{__LINE__}: #{e.inspect}")
305
355
  end
306
356
 
307
357
  # Provide an authorization token or passcode in a specified text field element identified by its *:id* attribute.
@@ -327,28 +377,23 @@ module Awetestlib
327
377
  # @param [Fixnum] lnbr Line number in calling script.
328
378
  # @param [String] desc Contains a message or description intended to appear in the log and/or report output
329
379
  #
330
- def bail_out(browser, lnbr, desc)
380
+ def bail_out(browser, lnbr = __LINE__, desc = '')
331
381
  ts = Time.new
332
- msg = "Bailing out at util line #{lnbr} #{ts} " + desc
333
- puts "#{msg}"
334
- fatal_to_log(msg, lnbr)
335
- debug_to_log(dump_caller(lnbr))
382
+ msg = "Bailing out at #{ts}. " + desc
383
+ debug_to_log(msg)
336
384
  if is_browser?(browser)
337
385
  if @browserAbbrev == 'IE'
338
386
  hwnd = browser.hwnd
339
387
  kill_browser(hwnd, lnbr, browser)
340
- raise(RuntimeError, msg, caller)
341
388
  elsif @browserAbbrev == 'FF'
342
389
  debug_to_log("#{browser.inspect}")
343
390
  debug_to_log("#{browser.to_s}")
344
- raise(RuntimeError, msg, caller)
345
391
  end
346
392
  end
347
393
  @status = 'bailout'
348
394
  raise(RuntimeError, msg, caller)
349
395
  end
350
396
 
351
-
352
397
  # Check for the presence of IE browser instances.
353
398
  # @return [Fixnum] The number of IE browser instances encountered.
354
399
  def check_for_other_browsers
@@ -434,11 +479,11 @@ module Awetestlib
434
479
  end
435
480
  end
436
481
  if logit
437
- debug_to_log("#{@browserName} window hwnd #{hwnd} pid #{pid} #{url} (#{here})")
438
- fatal_to_log("Kill browser called from line #{lnbr}")
439
- end
440
- end
441
- end
482
+ debug_to_log("#{@browserName} window hwnd #{hwnd} pid #{pid} #{url} (#{here})")
483
+ fatal_to_log("Kill browser called from line #{lnbr}")
484
+ end
485
+ end
486
+ end
442
487
 
443
488
  # @!endgroup Error Handling
444
489
 
@@ -503,120 +548,134 @@ module Awetestlib
503
548
  failed_to_log("#{msg}: Unable to close: '#{$!}'. (#{__LINE__}) #{desc}")
504
549
  end
505
550
 
506
- # Closes main browser session. Misnamed. Usually used at end of script to shut down browser.
551
+ # Closes main browser session. Usually used at end of script to shut down browser.
507
552
  def close_browser(browser, where = @myName, lnbr = __LINE__)
508
- #TODO Firewatir 1.6.5 does not implement .exists for FireWatir::Firefox class
509
- debug_to_log("Logging out in #{where} at line #{lnbr}.", lnbr, true)
510
- debug_to_log("#{__method__}: browser: #{browser.inspect} (#{__LINE__})")
553
+ browser_name = BROWSER_MAP[@browserAbbrev]
554
+ mark_test_level("#{browser_name} in #{where}")
555
+ debug_to_log(with_caller("#{browser.inspect}"))
511
556
 
512
557
  url = browser.url
513
558
  title = browser.title
559
+ message_to_report(with_caller("#{browser_name} url: #{browser.url}"))
560
+ message_to_report(with_caller("#{browser_name} title: #{browser.title}"))
514
561
 
515
- if ['FF', 'S'].include?(@browserAbbrev) || browser.exists?
516
- case @browserAbbrev
517
- when 'FF'
518
- if is_browser?(browser)
519
- debug_to_log("#{__method__}: Firefox browser url: [#{url}]")
520
- debug_to_log("#{__method__}: Firefox browser title: [#{title}]")
521
- debug_to_log("#{__method__}: Closing browser: #{where} (#{lnbr})")
522
- if url and url.length > 1
523
- browser.close
524
- else
525
- browser = FireWatir::Firefox.attach(:title, title)
526
- browser.close
527
- end
562
+ report_browser_message(browser)
528
563
 
529
- end
530
- when 'IE'
531
- debug_to_log("#{__method__}: Internet Explorer browser url: [#{url}]")
532
- debug_to_log("#{__method__}: Internet Explorer browser title: [#{title}]")
533
- debug_to_log("#{__method__}: Closing browser: #{where} (#{lnbr})")
534
- if $watir_script
535
- hwnd = browser.hwnd
536
- pid = Watir::IE::Process.process_id_from_hwnd(hwnd)
537
- debug_to_log("#{__method__}: Closing browser: hwnd #{hwnd} pid #{pid} #{where} (#{lnbr}) (#{__LINE__})")
538
- browser.close
539
- if browser.exists? and pid > 0 and pid < 538976288 # value of uninitialized memory location
540
- debug_to_log("Retry close browser: hwnd #{hwnd} pid #{pid} #{where} #{lnbr} (#{__LINE__})")
541
- browser.close
542
- end
543
- if browser.exists? and pid > 0 and pid < 538976288 # value of uninitialized memory location
544
- kill_browser(browser.hwnd, __LINE__, browser)
545
- end
546
- else
547
- browser.close
548
- end
549
- when 'S'
550
- if is_browser?(browser)
551
- url = browser.url
552
- title = browser.title
553
- debug_to_log("Safari browser url: [#{url}]")
554
- debug_to_log("Safari browser title: [#{title}]")
555
- debug_to_log("Closing browser: #{where} (#{lnbr})")
556
- close_modal_s # to close any leftover modal dialogs
557
- browser.close
558
- end
559
- when 'C', 'GC'
560
- if is_browser?(browser)
561
- url = browser.url
562
- title = browser.title
563
- debug_to_log("Chrome browser url: [#{url}]")
564
- debug_to_log("Chrome browser title: [#{title}]")
565
- debug_to_log("Closing browser: #{where} (#{lnbr})")
566
- if url and url.length > 1
567
- browser.close
568
- end
564
+ if $mobile
565
+ browser.close
566
+ sleep(1)
567
+ end_android_processes if $platform == :android
568
+ clean_up_android_temp unless $device
569
569
 
570
- end
571
- else
572
- raise "Unsupported browser: '#{@browserAbbrev}'"
573
- end
570
+ else
571
+ browser.close
572
+ # case @browserAbbrev
573
+ # when 'FF'
574
+ # if is_browser?(browser)
575
+ # debug_to_log("#{__method__}: Firefox browser url: [#{url}]")
576
+ # debug_to_log("#{__method__}: Firefox browser title: [#{title}]")
577
+ # debug_to_log("#{__method__}: Closing browser: #{where} (#{lnbr})")
578
+ # if url and url.length > 1
579
+ # browser.close
580
+ # else
581
+ # browser = FireWatir::Firefox.attach(:title, title)
582
+ # browser.close
583
+ # end
584
+ #
585
+ # end
586
+ # when 'IE'
587
+ # if is_browser?(browser)
588
+ # debug_to_log("#{__method__}: Internet Explorer browser url: [#{url}]")
589
+ # debug_to_log("#{__method__}: Internet Explorer browser title: [#{title}]")
590
+ # debug_to_log("#{__method__}: Closing browser: #{where} (#{lnbr})")
591
+ # browser.close
592
+ # end
593
+ # when 'S'
594
+ # if is_browser?(browser)
595
+ # url = browser.url
596
+ # title = browser.title
597
+ # debug_to_log("Safari browser url: [#{url}]")
598
+ # debug_to_log("Safari browser title: [#{title}]")
599
+ # debug_to_log("Closing browser: #{where} (#{lnbr})")
600
+ # # close_modal_s # to close any leftover modal dialogs
601
+ # browser.close
602
+ # end
603
+ # when 'C', 'GC'
604
+ # if is_browser?(browser)
605
+ # url = browser.url
606
+ # title = browser.title
607
+ # debug_to_log("Chrome browser url: [#{url}]")
608
+ # debug_to_log("Chrome browser title: [#{title}]")
609
+ # debug_to_log("Closing browser: #{where} (#{lnbr})")
610
+ # if url and url.length > 1
611
+ # browser.close
612
+ # end
613
+ #
614
+ # end
615
+ # else
616
+ # raise "Unsupported browser: '#{@browserAbbrev}'"
617
+ # end
574
618
  end
575
619
  rescue
576
620
  failed_to_log(unable_to)
577
621
  end
578
622
 
579
- alias logout close_browser
623
+ def report_browser_message(browser)
624
+ if browser.title =~ /^\d+\s/
625
+ failed_to_log(browser.title)
626
+ message_to_report(browser.text)
627
+ end
628
+ end
580
629
 
581
- # Close a browser popup window. Does not apply to modal popups.
582
- # @param [Watir::Browser] popup Reference to the popup to be closed
583
- def close_new_window_popup(popup)
584
- if is_browser?(popup)
585
- url = popup.url
630
+ # Close a browser window, usually a child window. Does not apply to modal popups/alerts.
631
+ # @param [Watir::Browser] window Reference to the browser window to be closed
632
+ def close_window(window)
633
+ if is_browser?(window)
634
+ url = window.url
586
635
  debug_to_log("Closing popup '#{url}' ")
587
- popup.close
588
-
636
+ if $using_webdriver
637
+ window.driver.switch_to.window(window.driver.window_handles[0])
638
+ window.window(:url, url).close
639
+ else
640
+ window.close
641
+ end
589
642
  end
590
643
  end
591
644
 
645
+ alias close_new_window_popup close_window
646
+ alias close_child_window close_window
647
+
592
648
  # Close an HTML panel or division by clicking a link within it identified by the *:text* value of the link.
593
649
  # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
594
650
  # @param [Watir::Browser] panel Reference to the panel (usually a div element) to be closed
595
- def close_panel_by_text(browser, panel, what = 'Close')
651
+ # @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
652
+ # Some common values are :link, :button, :image, :div, :span.
653
+ # @param [Symbol] how The element attribute used to identify the specific element.
654
+ # Valid values depend on the kind of element.
655
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
656
+ # @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
657
+ def close_panel(browser, panel, element, how, what, desc = '')
658
+ msg = "Close panel with #{element} '#{how}'=>'#{what}' #{desc}"
596
659
  if validate(browser, @myName, __LINE__)
597
- if @browserAbbrev == 'IE'
598
- panel.link(:text, what).click!
599
- elsif $USE_FIREWATIR
660
+ if $using_webdriver
600
661
  begin
601
- panel.link(:text, what).click
662
+ panel.element(how, what).click
602
663
  rescue => e
603
- unless rescue_me(e, __method__, rescue_me_command(:link, :id, what, :click), "#{panel.class}")
664
+ unless rescue_me(e, __method__, rescue_me_command(:link, how, what, :click), "#{panel.class}")
604
665
  raise e
605
666
  end
606
667
  end
607
668
  else
608
- panel.link(:text, what).click(:wait => false)
669
+ panel.element(how, what).click!
609
670
  end
610
671
  sleep_for(1)
611
- if validate(browser, @myName, __LINE__)
612
- passed_to_log("Panel '#{what}' (by :text) closed.")
613
- true
614
- end
672
+ passed_to_log(msg)
673
+ true
615
674
  else
616
- failed_to_log("Panel '#{strg}' (by :text) still open.")
675
+ failed_to_log(unable_to(msg))
617
676
  end
618
677
  rescue
619
- failed_to_log("Click on '#{strg}'(by :text) failed: '#{$!}' (#{__LINE__})")
678
+ failed_to_log(unable_to(msg))
620
679
  end
621
680
 
622
681
  #def close_modal_ie(title, button = "OK", text = '', side = 'primary', wait = WAIT, desc = '', quiet = false)
@@ -726,31 +785,21 @@ module Awetestlib
726
785
  # @param [String] side A string identifying which mouse button to click.
727
786
  # @param [Fixnum] wait Number of seconds to wait for the popup to be seen.
728
787
  def close_modal(browser, title="", button="OK", text='', side = 'primary', wait = WAIT)
729
- case @targetBrowser.abbrev
730
- when 'IE'
731
- close_modal_ie(browser, title, button, text, side, wait)
732
- when 'FF'
733
- close_modal_ff(browser, title, button, text, side)
734
- when 'S'
735
- close_modal_s
736
- when 'C', 'GC'
737
- close_modal_c(browser, title)
788
+ if $using_webdriver
789
+ case button
790
+ when /^OK$/i, /^Yes$/i
791
+ browser.alert.ok
792
+ else
793
+ browser.alert.dismiss
794
+ end
795
+ else
796
+ close_modal_ie(browser, title, button, text, side, wait)
738
797
  end
798
+ rescue
799
+ failed_to_log(unable_to)
739
800
  end
740
801
 
741
- # TODO: Logging
742
- # Close a Chrome modal popup by :url.
743
- def close_modal_c(browser, url)
744
- browser.window(:url, url).close
745
- end
746
-
747
- # TODO: Logging
748
- # Close a Safari modal popup by closing the frontmost Safari dialog. Mac OSX only.
749
- def close_modal_s
750
- # simply closes the frontmost Safari dialog
751
- Appscript.app("Safari").activate
752
- Appscript.app("System Events").processes["Safari"].key_code(52)
753
- end
802
+ alias close_alert close_modal
754
803
 
755
804
  # Close an IE modal popup by its title using AutoItX3. Windows only.
756
805
  # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
@@ -915,7 +964,7 @@ module Awetestlib
915
964
 
916
965
  controlHandle = @ai.ControlGetHandle(window_handle, '', "[CLASS:Button; TEXT:#{button}]")
917
966
  if not controlHandle
918
- # button = "&#{button}"
967
+ # button = "&#{button}"
919
968
  controlHandle = @ai.ControlGetHandle(window_handle, '', "[CLASS:Button; TEXT:&#{button}]")
920
969
  end
921
970
 
@@ -965,46 +1014,12 @@ module Awetestlib
965
1014
 
966
1015
  end
967
1016
 
968
- # Return a reference to an IE browser window based on one of its attributes.
969
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
970
- # @param [Symbol] how The element attribute used to identify the window: :url, :title, or :hwnd.
971
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
972
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
973
- # @return [Watir::IE] A reference to the popup.
974
- def find_popup(browser, how, what, desc = '')
975
- msg = "Find popup :#{how}=>'#{what}'. #{desc}"
976
- popup = Watir::IE.find(how, what) # TODO: too browser specific
977
- sleep_for(1)
978
- debug_to_log("#{popup.inspect}")
979
- if is_browser?(popup)
980
- # title = popup.title
981
- passed_to_log(msg)
982
- return popup
983
- else
984
- failed_to_log(msg)
985
- end
986
- rescue
987
- failed_to_log("Unable to find popup :#{how}=>'#{what}'. #{desc} '#{$!}' (#{__LINE__})")
988
- end
989
-
990
1017
  # Confirm that the object passed in *browser* is actually a Browser object.
991
1018
  # @param [Watir::Browser] browser A reference to the window or container element to be tested.
992
1019
  def is_browser?(browser)
993
- myClass = browser.class.to_s
994
- case @targetBrowser.abbrev
995
- when 'IE'
996
- myClass =~ /Watir::IE|Watir::Browser/i
997
- when 'FF'
998
- myClass =~ /Watir::Browser/i
999
- when 'S'
1000
- myClass =~ /Watir::Browser/i
1001
- when 'C'
1002
- myClass =~ /Watir::Browser/i
1003
- end
1020
+ browser.class.to_s =~ /Watir::Browser/i
1004
1021
  end
1005
1022
 
1006
- alias is_browser is_browser?
1007
-
1008
1023
  # Translate window title supplied in *title* to a title appropriate for the targeted browser and version
1009
1024
  # actually being run.
1010
1025
  # Used primarily for handling of modal popups and dialogs.
@@ -1014,8 +1029,8 @@ module Awetestlib
1014
1029
  new_title = title
1015
1030
  case @browserAbbrev
1016
1031
  when 'IE'
1017
- if @browserVersion
1018
- case @browserVersion
1032
+ if @actualBrowser.version
1033
+ case @actualBrowser.version
1019
1034
  when '8.0'
1020
1035
  case title
1021
1036
  when "Microsoft Internet Explorer"
@@ -1078,12 +1093,11 @@ module Awetestlib
1078
1093
  # Identify the exact version of the Browser currently being executed.
1079
1094
  # @todo Bring up to date with newer browser versions
1080
1095
  # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
1081
- def get_browser_version(browser)
1082
- debug_to_log("starting get_browser_version")
1096
+ def browser_version(browser)
1083
1097
  case @targetBrowser.abbrev
1084
1098
  when 'IE'
1085
- @browserAbbrev = 'IE'
1086
- @browserName = 'Internet Explorer'
1099
+ @browserAbbrev = 'IE'
1100
+ @browserName = 'Internet Explorer'
1087
1101
  if $watir_script
1088
1102
  @browserAppInfo = browser.document.invoke('parentWindow').navigator.appVersion
1089
1103
  else
@@ -1094,37 +1108,55 @@ module Awetestlib
1094
1108
  when 'FF'
1095
1109
  @browserAbbrev = 'FF'
1096
1110
  @browserName = 'Firefox'
1097
- @browserVersion = '6.01' #TODO: get actual version from browser
1098
1111
  @browserAppInfo = browser.execute_script("return navigator.userAgent;")
1099
- debug_to_log("#{@browserName}, @browserAppInfo: (#{@browserAppInfo})")
1112
+ @browserAppInfo =~ /Firefox\/([\d\.]+)/
1113
+ @browserVersion = $1
1100
1114
  when 'S'
1101
1115
  @browserAbbrev = 'S'
1102
1116
  @browserName = 'Safari'
1103
- @browserVersion = '5.0.4' #TODO: get actual version from browser itself
1104
1117
  @browserAppInfo = browser.execute_script("return navigator.userAgent;")
1105
- debug_to_log("#{@browserName}, @browserAppInfo: (#{@browserAppInfo})")
1106
- when 'C'
1107
- @browserAbbrev = 'C'
1118
+ @browserVersion = '6.0' #TODO: get actual version from browser itself
1119
+ when 'C', 'GC'
1120
+ @browserAbbrev = 'GC'
1108
1121
  @browserName = 'Chrome'
1109
- @browserVersion = '11.0' #TODO: get actual version from browser
1110
1122
  @browserAppInfo = browser.execute_script("return navigator.userAgent;")
1111
- debug_to_log("#{@browserName}, @browserAppInfo: (#{@browserAppInfo})")
1123
+ @browserAppInfo =~ /Chrome\/([\d\.]+)/
1124
+ @browserVersion = $1
1125
+ else
1126
+ @browserAbbrev = @targetBrowser.abbrev
1127
+ @browserAppInfo = browser.execute_script("return navigator.userAgent;")
1128
+
1112
1129
  end
1130
+ debug_to_report("#{@browserName}, @browserAppInfo: (#{@browserAppInfo})")
1131
+ debug_to_log("#{browser.driver.capabilities.to_yaml}")
1132
+
1133
+ @browserVersion # = browser.driver.capabilities.version
1113
1134
  rescue
1114
- debug_to_log("Unable to determine #{@browserAbbrev} browser version: '#{$!}' (#{__LINE__})")
1135
+ failed_to_log(unable_to)
1115
1136
  ensure
1116
- message_to_log("Browser: [#{@browserAbbrev} #{@browserVersion}]")
1137
+ message_to_report("Browser: [#{@browserName} (#{@browserAbbrev}) #{@browserVersion}]")
1117
1138
  end
1118
1139
 
1140
+ alias get_browser_version browser_version
1141
+
1142
+
1119
1143
  protected :get_browser_version
1120
1144
 
1121
- #def filter_bailout_from_rescue(err, msg)
1122
- # if msg =~ /bailing out/i
1123
- # raise err
1124
- # else
1125
- # error_to_log(msg)
1126
- # end
1127
- #end
1145
+ def get_viewport_to_win_diff(browser)
1146
+ window_width = browser.window.size.width.to_f
1147
+ body_width = browser.body.style("width")
1148
+ body_width = body_width.to_f
1149
+ (window_width - body_width).to_i
1150
+ end
1151
+
1152
+ def calc_window_size(browser, bpsize)
1153
+ diff = get_viewport_to_win_diff(browser)
1154
+ if @targetBrowser.abbrev == 'C'
1155
+ new_size = bpsize + diff -1
1156
+ elsif @targetBrowser.abbrev == 'FF'
1157
+ new_size = bpsize + diff -16
1158
+ end
1159
+ end
1128
1160
 
1129
1161
  # @!group Browser
1130
1162
 
@@ -1151,24 +1183,24 @@ module Awetestlib
1151
1183
  # @param [Boolean] dbg If set to true additional debug messages are written to the log.
1152
1184
  #
1153
1185
  # @return [Boolean] True if no error conditions have been encountered.
1154
- def validate(browser, file_name = @myName, lnbr = "#{__LINE__}", dbg = false)
1186
+ def validate(browser, file_name = @myName, lnbr = '', dbg = false)
1155
1187
  debug_to_log("#{__method__} begin") if dbg
1156
- msg = ''
1157
- myOK = true
1188
+ msg = ''
1189
+ ok = true
1158
1190
  if not browser
1159
- msg = "#{file_name}----browser is nil object. (#{lnbr})"
1160
- myOK = false
1191
+ msg = "browser is nil object."
1192
+ ok = false
1193
+
1161
1194
  elsif not browser.class.to_s =~ /Watir/
1162
- msg = "#{file_name}----not a Watir object. (#{lnbr})"
1195
+ msg = "not a Watir object."
1163
1196
  debug_to_log(browser.inspect)
1164
- myOK = false
1197
+ ok = false
1165
1198
 
1166
1199
  else
1167
1200
  if browser.respond_to?(:url)
1168
1201
  if not browser.url == @currentURL
1169
1202
  @currentURL = browser.url
1170
- debug_to_log("Current URL: [#{@currentURL}]")
1171
- # mark_testlevel( "Current URL: [#{@currentURL}]", 1 )
1203
+ debug_to_log(with_caller("Current URL: [#{@currentURL}]"))
1172
1204
  end
1173
1205
  end
1174
1206
 
@@ -1182,7 +1214,8 @@ module Awetestlib
1182
1214
  end
1183
1215
 
1184
1216
  begin
1185
- browser_text = browser.text.downcase
1217
+ browser_text = browser.text.downcase
1218
+ browser_title = browser.title
1186
1219
  rescue => e
1187
1220
  unless rescue_me(e, __method__, "browser.text.downcase", "#{browser.class}", browser)
1188
1221
  debug_to_log("browser.text.downcase in #{__method__} #{browser.class}")
@@ -1195,111 +1228,111 @@ module Awetestlib
1195
1228
 
1196
1229
  if browser_text
1197
1230
  if browser_text.match(/unrecognized error condition has occurred/i)
1198
- msg = "#{file_name}----Unrecognized Exception occurred. (#{lnbr})"
1199
- myOK = false
1231
+ error = "Unrecognized Exception occurred."
1232
+ ok = false
1200
1233
 
1201
1234
  elsif browser_text.match(/cannot find server or dns error/i)
1202
- msg = "#{file_name}----Cannot find server error or DNS error. (#{lnbr})"
1203
- myOK = false
1235
+ error = "Cannot find server error or DNS error."
1236
+ ok = false
1204
1237
 
1205
1238
  elsif browser_text.match(/the rpc server is unavailable/i)
1206
- msg = "#{file_name}----RPC server unavailable. (#{lnbr})"
1207
- myOK = false
1239
+ error = "RPC server unavailable."
1240
+ ok = false
1208
1241
 
1209
1242
  elsif browser_text.match(/404 not found/i) or
1210
1243
  browser_text.match(/the page you were looking for does\s*n[o']t exist/i)
1211
- msg = "#{file_name}----RFC 2068 HTTP/1.1: 404 URI Not Found. (#{lnbr})"
1212
- myOK = false
1244
+ error = "RFC 2068 HTTP/1.1: 404 URI Not Found."
1245
+ ok = false
1213
1246
 
1214
1247
  elsif browser_text.match(/we're sorry, but something went wrong/i) or
1215
1248
  browser_text.match(/http status 500/i)
1216
- msg = "#{file_name}----RFC 2068 HTTP/1.1: 500 Internal Server Error. (#{lnbr})"
1217
- myOK = false
1249
+ error = "RFC 2068 HTTP/1.1: 500 Internal Server Error."
1250
+ ok = false
1218
1251
 
1219
1252
  elsif browser_text.match(/internet explorer cannot display the webpage/i)
1220
- msg = "#{file_name}----Probably RFC 2068 HTTP/1.1: 500 Internal Server Error. (#{lnbr})"
1221
- myOK = false
1253
+ error = "Probably RFC 2068 HTTP/1.1: 500 Internal Server Error."
1254
+ ok = false
1222
1255
 
1223
1256
  elsif browser_text.match(/503.*service unavailable/i)
1224
- msg = "#{file_name}----RFC 2068 HTTP/1.1: 503 Service Unavailable. (#{lnbr})"
1225
- myOK = false
1257
+ error = "RFC 2068 HTTP/1.1: 503 Service Unavailable."
1258
+ ok = false
1226
1259
 
1227
1260
  elsif browser_text.match(/java.lang.NullPointerException/i)
1228
- msg = "#{file_name}----java.lang.NullPointerException. (#{lnbr})"
1229
- myOK = false
1261
+ error = "java.lang.NullPointerException."
1262
+ ok = false
1230
1263
 
1231
1264
  elsif browser_text.match(/due to unscheduled maintenance/i)
1232
- msg = "#{file_name}----Due to unscheduled maintenance. (#{lnbr})"
1233
- myOK = false
1265
+ error = "Due to unscheduled maintenance."
1266
+ ok = false
1234
1267
 
1235
1268
  elsif browser_text.match(/network\s+error\s*(.+)$/i)
1236
1269
  $1.chomp!
1237
- msg = "#{file_name}----Network Error #{$1}. (#{lnbr})"
1238
- myOK = false
1270
+ error = "Network Error #{$1}."
1271
+ ok = false
1239
1272
 
1240
1273
  elsif browser_text.match(/warning: page has expired/i)
1241
- msg = "#{file_name}----Page using information from form has expired. Not automatically resubmitted. (#{lnbr})"
1242
- myOK = false
1274
+ error = "Page using information from form has expired. Not automatically resubmitted."
1275
+ ok = false
1243
1276
 
1244
1277
  elsif browser_text.match(/no backend server available/i)
1245
- msg = "#{file_name}----Cannot Reach Server (#{lnbr})"
1246
- myOK = false
1278
+ error = "Cannot Reach Server"
1279
+ ok = false
1247
1280
 
1248
1281
  elsif browser_text.match(/sign on\s+.+\s+unsuccessful/i)
1249
- msg = "#{file_name}----Invalid Id or Password (#{lnbr})"
1250
- myOK = false
1282
+ error = "Invalid Id or Password"
1283
+ ok = false
1251
1284
 
1252
1285
  elsif browser_text.match(/you are not authorized/i)
1253
- msg = "#{file_name}----Not authorized to view this page. (#{lnbr})"
1254
- myOK = false
1286
+ error = "Not authorized to view this page."
1287
+ ok = false
1255
1288
 
1256
1289
  elsif browser_text.match(/too many incorrect login attempts have been made/i)
1257
- msg = "#{file_name}----Invalid Id or Password. Too many tries. (#{lnbr})"
1258
- myOK = false
1290
+ error = "Invalid Id or Password. Too many tries."
1291
+ ok = false
1259
1292
 
1260
1293
  elsif browser_text.match(/system error\.\s+an error has occurred/i)
1261
- msg = "#{file_name}----System Error. An error has occurred. Please try again or call the Help Line for assistance. (#{lnbr})"
1262
- myOK = false
1294
+ error = "System Error. An error has occurred. Please try again or call the Help Line for assistance."
1295
+ ok = false
1263
1296
 
1264
1297
  elsif browser_text.match(/Internal Server failure,\s+NSAPI plugin/i)
1265
- msg = "#{file_name}----Internal Server failure, NSAPI plugin. (#{lnbr})"
1266
- myOK = false
1298
+ error = "Internal Server failure, NSAPI plugin."
1299
+ ok = false
1267
1300
 
1268
1301
  elsif browser_text.match(/Error Page/i)
1269
- msg = "#{file_name}----Error Page. (#{lnbr})"
1270
- myOK = false
1302
+ error = "Error Page."
1303
+ ok = false
1271
1304
 
1272
1305
  elsif browser_text.match(/The website cannot display the page/i)
1273
- msg = "#{file_name}----HTTP 500. (#{lnbr})"
1274
- myOK = false
1306
+ error = "HTTP 500."
1307
+ ok = false
1275
1308
 
1276
1309
  # elsif browser_text.match(/Insufficient Data/i)
1277
- # msg = "#{file_name}----Insufficient Data. (#{lnbr})"
1278
- # myOK = false
1310
+ # error = "Insufficient Data."
1311
+ # ok = false
1279
1312
 
1280
1313
  elsif browser_text.match(/The timeout period elapsed/i)
1281
- msg = "#{file_name}----Time out period elapsed or server not responding. (#{lnbr})"
1282
- myOK = false
1314
+ error = "Time out period elapsed or server not responding."
1315
+ ok = false
1283
1316
 
1284
1317
  elsif browser_text.match(/Unexpected\s+errors*\s+occur+ed\.\s+(?:-+)\s+(.+)/i)
1285
- msg = "#{file_name}----Unexpected errors occurred. #{$2.slice(0, 120)} (#{lnbr})"
1318
+ error = "Unexpected errors occurred. #{$2.slice(0, 120)}"
1286
1319
  if not browser_text.match(/close the window and try again/i)
1287
- myOK = false
1320
+ ok = false
1288
1321
  else
1289
- debug_to_log("#{msg}")
1322
+ debug_to_log(with_caller(filename, '----', error, "(#{browser.url})"))
1290
1323
  end
1291
1324
 
1292
1325
  elsif browser_text.match(/Server Error in (.+) Application\.\s+(?:-+)\s+(.+)/i)
1293
- msg = "#{file_name}----Server Error in #{1} Application. #{$2.slice(0, 100)} (#{lnbr})"
1294
- myOK = false
1326
+ error = "Server Error in #{1} Application. #{$2.slice(0, 100)}"
1327
+ ok = false
1295
1328
 
1296
1329
  elsif browser_text.match(/Server Error in (.+) Application\./i)
1297
- msg = "#{file_name}----Server Error in #{1} Application. '#{browser_text.slice(0, 250)}...' (#{lnbr})"
1298
- myOK = false
1330
+ error = "Server Error in #{1} Application. '#{browser_text.slice(0, 250)}...'"
1331
+ ok = false
1299
1332
 
1300
1333
  elsif browser_text.match(/An error has occur+ed\. Please contact support/i)
1301
- msg = "#{file_name}----An error has occurred. Please contact support (#{lnbr})"
1302
- myOK = false
1334
+ error = "An error has occurred. Please contact support."
1335
+ ok = false
1303
1336
 
1304
1337
  end
1305
1338
  else
@@ -1307,28 +1340,104 @@ module Awetestlib
1307
1340
  end
1308
1341
  end
1309
1342
 
1310
- if not myOK
1311
- msg << " (#{browser.url})"
1343
+ if browser_title
1344
+ if browser_title.match(/page not found/i)
1345
+ error = "#{browser_title} RFC 2068 HTTP/1.1: 404 URI Not Found."
1346
+ ok = false
1347
+ end
1348
+ end
1349
+
1350
+ if not ok
1351
+ msg = with_caller(file_name, '----', error, "(#{browser.url})")
1312
1352
  puts msg
1313
1353
  debug_to_log(browser.inspect)
1314
1354
  debug_to_log(browser.text)
1315
- fatal_to_log(msg, lnbr)
1355
+ # fatal_to_log(msg)
1316
1356
  raise(RuntimeError, msg, caller)
1317
1357
  else
1318
1358
  debug_to_log("#{__method__} returning OK") if dbg
1319
- return myOK
1359
+ return ok
1320
1360
  end
1321
1361
 
1322
1362
  rescue
1323
1363
  errmsg = $!
1324
- if errmsg and errmsg.match(msg)
1364
+ if errmsg and errmsg.message.match(msg)
1325
1365
  errmsg = ''
1326
1366
  end
1327
- bail_out(browser, lnbr, "#{msg} #{errmsg}")
1367
+ bail_out(browser, __LINE__, build_message(msg, errmsg))
1328
1368
  end
1329
1369
 
1330
1370
  alias validate_browser validate
1331
1371
 
1372
+ def verify_browser_options
1373
+ browser_name = Awetestlib::BROWSER_MAP[self.browser]
1374
+ browser_acro = self.browser
1375
+ ok = true
1376
+
1377
+ if $mobile
1378
+
1379
+ # REDTAG: correction for Shamisen sending wrong browser acronym.
1380
+ if self.browser =~ /browser/i
1381
+ self.browser = 'AB'
1382
+ browser_name = Awetestlib::BROWSER_MAP[self.browser]
1383
+ browser_acro = self.browser
1384
+ end
1385
+
1386
+ debug_to_log(with_caller(":#{__LINE__}\n#{self.options.to_yaml}"))
1387
+
1388
+ parse_environment_node_for_mobile
1389
+
1390
+ debug_to_log(with_caller(":#{__LINE__}\n#{self.options.to_yaml}"))
1391
+
1392
+ case browser_acro
1393
+ when 'FF', 'IE', 'S', 'GC', 'C', 'ED', 'O'
1394
+ failed_to_log("#{browser_acro} (#{browser_name}) is not a valid mobile browser.")
1395
+ ok = false
1396
+ when 'IS', 'MS', 'IC', 'MC'
1397
+ if self.sdk
1398
+ self.device_type = 'iOS Simulator'
1399
+ self.options[:device_type] = 'iOS Simulator'
1400
+ elsif self.device_id
1401
+ self.device_type = 'iOS Device'
1402
+ self.options[:device_type] = 'iOS Device'
1403
+ else
1404
+ failed_to_log(with_caller("Must supply either sdk or device id for iOS."))
1405
+ ok = false
1406
+ end
1407
+ when 'AC', 'AB'
1408
+ if self.emulator
1409
+ self.device_type = 'Android Emulator'
1410
+ self.options[:device_type] = 'Android Emulator'
1411
+ elsif self.device_id
1412
+ self.device_type = 'Android Device'
1413
+ self.options[:device_type] = 'Android Device'
1414
+ if self.sdk
1415
+ self.options[:sdk] = self.sdk
1416
+ else
1417
+ failed_to_log(with_caller("Must supply sdk for Android device."))
1418
+ ok = false
1419
+ end
1420
+ else
1421
+ failed_to_log(with_caller("Must supply either emulator or device id for Android."))
1422
+ ok = false
1423
+ end
1424
+ when 'ME', 'MI'
1425
+ failed_to_log(with_caller("#{browser_acro} (#{browser_name}) is not yet supported."))
1426
+ ok = false
1427
+ else
1428
+ failed_to_log(with_caller("'#{browser_acro}' is not a valid browser code."))
1429
+ ok = false
1430
+ end
1431
+ else
1432
+ ok = true
1433
+ end
1434
+ debug_to_log(with_caller(":#{__LINE__}\n#{self.options.to_yaml}"))
1435
+
1436
+ ok
1437
+ rescue
1438
+ failed_to_log(unable_to)
1439
+ end
1440
+
1332
1441
  # @!endgroup Error Handling
1333
1442
 
1334
1443
  # @!group Backward compatible usages
@@ -1343,7 +1452,7 @@ module Awetestlib
1343
1452
  # @param [String] desc Contains a message or description intended to appear in the log and/or report output
1344
1453
  # @return [Watir::Browser]
1345
1454
  def attach_browser_by_url(browser, what, desc = '')
1346
- attach_browser(browser, :url, what, desc)
1455
+ attach(browser, :url, what, desc)
1347
1456
  end
1348
1457
 
1349
1458
  alias attach_browser_with_url attach_browser_by_url
@@ -1352,14 +1461,14 @@ module Awetestlib
1352
1461
  # which can then be passed to methods that require a *browser* parameter. Calls attach_browser().
1353
1462
  # @param (see #attach_browser_by_url)
1354
1463
  def attach_popup_by_title(browser, what, desc = '')
1355
- attach_popup(browser, :title, what, desc)
1464
+ attach(browser, :title, what, desc)
1356
1465
  end
1357
1466
 
1358
1467
  # Returns a reference to a new browser window identified by its *:url* attribute. Used to attach a new browser window to a variable
1359
1468
  # which can then be passed to methods that require a *browser* parameter. Calls attach_browser().
1360
1469
  # @param (see #attach_browser_by_url)
1361
1470
  def attach_popup_by_url(browser, what, desc = '')
1362
- attach_popup(browser, :url, what, desc)
1471
+ attach(browser, :url, what, desc)
1363
1472
  end
1364
1473
 
1365
1474
  alias get_popup_with_url attach_popup_by_url
@@ -1368,12 +1477,20 @@ module Awetestlib
1368
1477
 
1369
1478
  # Close a popup browser window (non-modal) by clicking on a link with :title *what*.
1370
1479
  # This method does not check to make sure the popup is actually closed.
1371
- # @param [Watir::Browser] popup A reference to the current popup browser window.
1480
+ # @param [Watir::Browser] browser A reference to the current popup browser window.
1372
1481
  # @param [String, Regexp] what The value in the targeted attribute that uniquely identifies the new window
1373
1482
  # @param [String] desc Contains a message or description intended to appear in the log and/or report output
1374
1483
  # @return [Boolean] True if the click is successful.
1375
- def close_popup_by_button_title(popup, what, desc = '')
1376
- click(popup, :link, :title, what, desc)
1484
+ def close_popup_by_button_title(browser, what, desc = '')
1485
+ click(browser, :link, :title, what, desc)
1486
+ end
1487
+
1488
+ # Close an HTML panel or division by clicking a link within it identified by the *:text* value of the link.
1489
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
1490
+ # @param [Watir::Browser] panel Reference to the panel (usually a div element) to be closed
1491
+ # @param [String, Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
1492
+ def close_panel_by_text(browser, panel, what = 'Close', desc = '')
1493
+ close_panel(browser, panel, :link, :text, what, desc)
1377
1494
  end
1378
1495
 
1379
1496
  # @!endgroup Backward