Using selenium to test the ShowModalDialog modal dialog box

Source: Internet
Author: User

Selenium does not currently provide processing for the IE modal dialog box (that is, a pop-up dialog box opened through the ShowModalDialog method). The reason for this is that the modal dialog box will suspend the parent page's JS until the dialog is finished and the parent page JS will continue to execute. Because the underlying implementation of the selenium is based on JS, the modal dialog box will suspend selenium, selenium cannot select the modal dialog box until timeout.

But many systems tend to have a large number of modal dialog boxes applied. These applications are divided into two categories: the selection of people, the choice of business types, such as operations, the purpose of which is to fill the corresponding fields of the parent page, does not trigger other operations, and the other kind of more special, such as workflow distribution, This type of operation continues to perform a series of operations after the selected person returns a value in the modal dialog box (that is, the call to the ShowModalDialog method is sandwiched between a bunch of JS operations).

For the first case, the corresponding data constants can be established in the test code to avoid invoking the ShowModalDialog method by direct assignment, but only hack in the second case.

In the current test case, use the following hack method:

A typical modal dialog box opens (for example, a button) after a page element is clicked, and the ShowModalDialog method is overwritten the first time the page element is clicked. Open the modal dialog box to open the page for window.open and select the pop-up page selenium:

Java code

public void clickAndSelectModalDialog(String locator){
   clickForModalDialog(locator);
    selenium.selectWindow(“name=modal”);
}

private void clickForModalDialog(String locator){
   String overrideShowModalDialogJs=="if(selenium.browserbot.getCurrentWindow().showModalDialog){";

overrideShowModalDialogJs += "selenium.browserbot.getCurrentWindow().showModalDialog = function( sURL, vArguments, sFeatures)";

overrideShowModalDialogJs +="selenium.browserbot.getCurrentWindow().open(sURL, 'modal', sFeatures);";

overrideShowModalDialogJs += "};}";
//showModalDialog方法进行覆盖
selenium.getEval(overrideShowModalDialogJs);
selenium.click(locator);
selenium.openWindow(“”,”modal”);
selenium.waitForPopUp(“modal”,”15000”);

}

You can then work on the pop-up page to get the values you want to return to the parent page, which is typically an array. Close the pop-up page and return to the parent page after getting the value. Click on the elements of the modal dialog box again on the parent page to overwrite the ShowModalDialog method for the second time and return the value obtained above directly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.