t.getNativeDialogHistory Method

Returns a history of the invoked native dialogs. Cannot be chained with other methods of the test controller.

Browsers do not display native dialogs when TestCafe handles them. Use the t.getNativeDialogHistory method to read their contents.

t.getNativeDialogHistory() → Promise<Array>

t.getNativeDialogHistory returns a stack of history entries (that is, an array in which the latest dialog has an index of 0). Each entry corresponds to a native dialog that appears in the main window or in an <iframe>.

A history entry contains the following properties.

Property Type Description
type String The type of the native dialog. 'alert' | 'confirm' | 'beforeunload' | 'prompt'.
text String Text of the dialog message.
url String The URL of the page that invoked the dialog. Use it to determine if the dialog originated from the main window or an <iframe>.
/* eslint-disable no-unused-vars */

test('Check native dialogs', async t => {
    await t
        .setNativeDialogHandler((type, text, url) => {
            if (type === 'confirm')
                return true;
            else if (type === 'prompt')
                return 'Hello!';
            return null;

    const history = await t.getNativeDialogHistory();

    await t
        .expect(history[0].text).eql('Say hello')

You can set the native dialog handler with the t.setNativeDialogHandler method.