t.getNativeDialogHistory Method

Provides a history of the invoked native dialogs.

t.getNativeDialogHistory() → Promise<[{type, text, url}]>

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>.
fixture `My fixture`
    .page `http://www.example.com/`;

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

    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.