IeUnit
Frequently Asked Questions
Q1: How do I debug an IeUnit script?
The best way to debug a test script is using the Microsoft Windows Script Debugger. After installed
the debugger you can start a test script under the debugger with the following
command:
cscript /X %IEUNIT_HOME%/IeTextRunner.wsf -run
yourTestScript.jst
You can also launch the debugger by opening an IeUnit workspace
prompt (through the Windows menu Start>Programs>IeUnit>Create
Tests) then issue the command DebugTest yourTestScript.jst.
The simplest way to launch the debugger is through the Windows Explorer
by right-mous clicking on the script file then select the Debug Script
menu item.
After launched the script debugger will stop at the first statement
of IeTextRunner.wsf. You can then step through your code and investigate
values of objects and properties. If you want to quickly jump into your
test script you can set a break-point by adding a "debugger" statement
in to your script, for example, as follows:
this.testHelloWorld = function() {
debugger;
this.assertPageHasText("Hello");
}
Notice that the above method doesn't help you to locate syntax
error in scripts. To locate syntax errors you can use techniques like
comment-in and comment-out parts of your test scripts.
In cases that your code has many deeply nested function calls you
can put a try-and-catch block around your code to catch and print out
stack information like in the following example:
this.testTestCode = function() {
try {
<test
code...>
} catch (ex) {
printStackTrace();
}
}
Q2: How do I handle various popup windows?
When using a web application the browser often uses popup windows to display
warning messages or prompt for extra user inputs. Those popup windows
are in most cases native OS windows, so that we cannot drive those windows
with DHTML APIs. IeUnit provides various support to handle those popup
windows. The following is a list of cases and methods to handle those cases.
- Alert and confirmation popup window: When you click on buttons
on some web pages the browser sometimes displays a message to ask for confirmation.
Such popup window uses the confirm() or alert()
method to display the message. Without special code those popup windows
will block normal execution of an IeUnit test. In order to pass through
these popup windows you can just suppress the popup message as described
in following test case:
this.testClickButtonWithOK = function() {
this.doc.parentWindow.confirm
= function() { return true; }
this.clickButton("submit");
// Validate the response
for "OK" confirmation.
this.assertEquals("OK", this.doc.all("response".innerText);
};
The first statement in above example overrides the confirm() method,
so that the popup window doesn't come up at all. The test case SupressPopupWindow.jst
of the test suite of IeUnit demonstrates this technique.
- HTTP authentication: When we navigate to a site that requires
HTTP authentication the browser will open a window to prompt for user name
and password. To login into those site programmatically we can use the
COM object Win32Dom that provides access to normal windows on
the desktop. The Win32Dom object is automatically loaded during
the start of an IeUnit test. In the test script we just need to call the
method this.openWindowAsUser() to login automatically. The
supplied test case WebLoginTest.jst shows an example for this method.
- Security alert messages: When, for instance, a site is
using secured HTTP protocol but the site's certificate has not been accepted
by the browser, the browser will popup a message to warn the user the situation.
Again to pass this kind of popup window we can use the Win32Dom object
to access the non-HTML window. The test case SkipSecurityAlert.jst
shows an example to deal with this kind of task.
- Printing: Win32Dom can also be used to
drive the OS printer panel. The smart bookmark script contrib/PrintPage.sbk
demonstrates how to automate such a task. Notice that this
script is not included in the installation package, you have to download
it from IeUnit CVS page.
- File Uploading: The test case contrib/UploadFile.jst
demonstrates how to use Win32Dom to automate uploading
a local file to a web server.
- Modal dialog windows: Some web sites use modal dialogs
to allow complex client side data editing. The modal dialog is implemented
in HTML. The test case ModalDialogTest.jst demonstrates a
simple case with modal dialogs. Basically, this test case launches sbk script
before opening the modal dialog. The sbk script waits for the modal dialog
window, then attach to it and enters test data into the modal dialog window,
then click on the submit submit button.
Q3: How do I do a google search with a single click?
You can use the smart bookmark feature of IeUnit to automate this kind
of work. Put the following code into a sbk script file, say googleIeUnit.sbk:
this.openWindow("http://www.google.com");
this.setField(0, "web testing tool IeUnit");
this.clickButton("Google Search");
Then create a desktop shortcut to this file, then click on the shortcut
icon.
Q4: How do I run all test cases within a directory?
Open the IeUnit prompt window through the Windows start menu Start>Programs>IeUnit>Create
Tests. Then change directory to your test case directory and issue
the command "StartTest.bat" without any option.
Alternately you can create a batch file, say RunAllTests.bat,
in your test case directory with the following content:
@cscript/nologo "%IEUNIT_HOME%lib\IeTextRunner.wsf"
-run
@pause
Then open the windows explorer and click the batch file.