Extending IeUnit User guide The Framework API

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.

   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.

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.

Extending IeUnit User guide The Framework API