t.getNativeDialogHistory Method

TestCafe collects data from native dialogs that appear after you set a native dialog handler. Call the t.getNativeDialogHistory to view this data.

t.getNativeDialogHistory() → Promise<Array>

Important

You cannot chain the t.getNativeDialogHistory method with other methods of the TestController object.

The t.getNativeDialogHistory method returns an array of native dialog entries, sorted in reverse chronological order.

Each entry includes the following information:

Property Type Description
type String Native dialog type ('alert', 'confirm', 'beforeunload', 'prompt', 'print', 'geolocation').
text String Native dialog content.
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 */
fixture`TestController.getNativeDialogHistory`
    .page`./index.html`;

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;
        })
        .click('#show-alert')
        .click('#show-confirm')
        .click('#show-prompt');

    const history = await t.getNativeDialogHistory();

    await t
        .expect(history[0].type).eql('prompt')
        .expect(history[0].text).eql('Say hello')
        .expect(history[1].type).eql('confirm')
        .expect(history[2].type).eql('alert');
});