Recipes
Popup handler (Pro edition)
Watir (the underlying test framework used in TestWise v1) is known not pop-up friendly. We tried most of attempted approaches, didn't work as we hoped. In real life, there will be all sorts of popups, JavaScript popup (like you just described), IE Security Alerts, Upload/Download dialog, Basic Authentication and so on. A single un-handled popups will block the test execution!
Our solution: running a background process to handle popups, a simple and reliable approach. Here is how it works:
nid = notify_execution_monitor_before_basic_auth("bob", "builder") # prepare to handle basic authentication pop with username/password
open_browser # it will ask for user to login (basic authentication popup)
notify_execution_monitor_cancel(nid) #operation complete, test can continue, notify the handler
Prequiste
C:\Program Files\TestWise\scripts\execution_monitor> startup.bat
You will see the text below, indicating the background popup clicking process up running
[05-11 09:39:14PM] Starting RWebSpec Monitoring v(0.2.5) on 4208
Let's illustrate with an exmaple. In TestWise, open samples\demo\demo.tpr project, select file popup_handler_test.rb, run it.
the test script:
require 'rwebspec'
load File.expand_path(File.join(File.dirname(__FILE__), "execution_monitor_helper.rb"))
specification "Popup handler" do
include RWebSpec::RSpecHelper
include ExecutionMonitorHelper
before(:all) do
open_browser("http://testwisely.com/demo")
end
after(:all) do
close_browser unless debugging?
end
story "Click OK in JavaScript popup window to continue" do
nid = notify_execution_monitor_before_popup
click_link("Popup windows")
click_button(" Buy Now ")
assert_link_present_with_text("Popup windows")
notify_execution_monitor_cancel(nid)
end
story "Basic Authentication" do
nid = notify_execution_monitor_before_basic_auth("tony", "password")
goto_url("http://www.agileway.net/svn-demo/")
click_link("tony/")
notify_execution_monitor_cancel(nid)
end
end
You shall see two popups were handled: JavaScript Popup and Baisc Authentication dialog. Here is a screencast to see in action.
For basic authentication, if somehow previous tests alreay created the session, the dialog won't be shown. The above test still works!
- notify_execution_monitor_before_basic_auth
- notify_execution_monitor_before_file_upload
- notify_execution_monitor_before_security_alerts
- notify_execution_monitor_before_popup
As different versions of IE might have popups with different titles, the execution monitor's target environment is IE8 on WinXP.
on Window 7
Prior to RubyShel v1.6.1, the AutoIt3, the library used to click buttons in popups, does not working well on Window 7 64-bit OS. An alternative approach is to use RAutomation's WinFFi adapter. You don't need to worry about this, just install RubyShell 1.6.1 or later version.
The steps is exactly the same, on starting the execution monitor, you get this:
Error no load AutoITX3 (not working on Win7), will use RAutomation instead [05-15 08:24:12AM] Starting RWebSpec Monitoring v(0.2.6) on 4208
Here is a screencast of Popup handler on Window 7
Please note: this approach is an early release, JavaScript and Basic Authentication popup known working. RAutomation is patched to make it work with Basic Authentication dialog.