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>


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 */

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')