TestCafe v2015.1   |   Documentation
The documentation on this webpage describes TestCafe v2015.1. This product is no longer available and has been replaced by TestCafe Studio. TestCafe Studio is our new cross-platform IDE for end-to-end web testing.
To learn more about TestCafe Studio, please visit www.devexpress.com/testcafestudio

NATIVE DIALOG HANDLING

If a browser displays a native message box during the test, use the functions from this section to close the dialog as required, and avoid test failure.

handleAlert

Closes an alert dialog.

handleAlert();

This function closes the dialogs invoked via the standard JavaScript window.alert() method. Note that the handleAlert call should precede the action that invokes the dialog.

'@test'['handleAlert'] = {
    'Click submit button "Try it"': function () {
        var submitButton = $(':containsExcludeChildren(Try it)', $("#iframeResult").contents());
        handleAlert();
        act.click(submitButton);
    }
};

handleBeforeUnload

Closes a dialog that is shown when a window is about to be unloaded.

handleBeforeUnload();

This function closes a dialog invoked via the standard JavaScript window.onbeforeunload() function. Note that the handleBeforeUnload call should precede the action that invokes the dialog.

'@test'['handleBeforeUnload'] = {
    'Click link "Link"': function () {
        var link = $(':containsExcludeChildren(LINK)');
        handleBeforeUnload();
        act.click(link);
    }
};

handleConfirm

Closes a confirmation dialog.

handleConfirm( result );

result: String (required). Specifies one of the following dialog result values.

  • 'OK' or true: Closes the dialog and confirms the action, thus emulating the OK button.
  • 'Cancel' or false: Closes the dialog and prohibits the action, thus emulating the Cancel button.

This function handles dialogs invoked via the standard JavaScript window.confirm() method. Note that the handleConfirm call should precede the action that invokes the dialog.

'@test'['Handle Confirm'] = {
    'Click div "Populate Form"': function () {
        var populateFormButton = $(':containsExcludeChildren(Populate Form)');
        handleConfirm('OK');
        act.click(populateFormButton);
    }
};

handlePrompt

Closes a dialog that prompts user input.

handlePrompt( input );

input: String (required). Specify the string to be entered before closing the dialog by clicking OK. Pass null to close the dialog by clicking Cancel.

This function handles dialogs invoked via the standard JavaScript window.prompt() method. Note that the handlePrompt call should precede the action that invokes a dialog.

'@test'['handlePrompt'] = {
    'Click submit button "Try it"': function () {
        var submitButton = $(':containsExcludeChildren(Try it)', $("#iframeResult").contents());
        handlePrompt("Peter");
        act.click(submitButton);
    }
};