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