QA/Mozmill Test Automation/Shared Modules Refactor/Documentation/Window Handling

From MozillaWiki
Jump to: navigation, search

If a Mozmill test has to handle an additional set of windows, we now have an easier way to get a reference and operate on those windows. In general two different kind of windows exist: non-modal windows and modal dialogs. Both have to be handled differently.

Non-modal Windows

A non-modal window is a window, like an additional browser window, which does not block any other open window. The handling of those windows is fairly trivial. The following steps are necessary:

Trigger an event which opens a new window

You can use any kind of trigger. Just check the feature you write tests for and check if there are entry points in the menu, via a shortcut, or any other kind of ui element. Finally issue the corresponding action, so the window gets opened.

Handle the opened window

Initially your test has access to the global 'browser' variable which represents the currently open browser window. This variable is an instance of a ChromeWindowWrapper with additional mixed-in helper methods and ui elements. It offers access to a method 'handleWindow'. That function requires at least 2 parameters to identify the correct window. The callback function for the handler can be used to let handleWindow call this function and handle the closing of the window afterward. If no callback has been specified you have to take care of closing the window.

To find the right window, you can let handleWindow() seach for the window type or the window title. Therefor the first parameter has to be 'driver.filterWindowByType' or 'driver.filterWindowByTitle'. Dependent on the callback you have to specify the exact value to compare the target with, i.e. the browser window has a type of 'navigator:browser'. That means if you want to handle a new browser window, you have to do the following:

function callback(aWindow) {
 [...]
 aWindow.close();
}

browser.handleWindow(driver.filterWindowByTitle, "navigator:browser", callback);

Modal Dialogs

Modal dialogs are different to the non-modal windows, because once opened they are blocking the other open windows until they have been closed themselve. That's why the window handler has to be installed before the action which opens the modal dialog gets triggered. That can be done by simply calling initModalDialog() with the callback function as parameter. Right after the action can be initiated, and we have to wait for the modal dialog. That can be done by calling waitForModalDialog() with the timeout as parameter (default are 5 seconds).

browser.initModalDialog(callback);
browser.ui.navBar.keypress("VK_DELETE", {shiftKey: true, accelKey: true});
browser.waitForModalDialog(500);