t.closeWindow Method

Closes a browser window. Chainable.

t.closeWindow([windowDescriptor]) → this | Promise<any>
Parameter Type Description
windowDescriptor (optional) Object Object that describes the target window. If this parameter is omitted, the active window is selected.

You cannot close the last remaining window or windows with open children.

Examples:

The following two examples produce identical test scenarios:

The window parameter is absent. Each call of the t.closeWindow method closes the active window:

fixture`TestController.closeWindow`
    .page`https://devexpress.github.io/testcafe/example/`;

test('Closing windows', async t => {
    await t.openWindow('https://devexpress.github.io/testcafe')
        .openWindow('https://devexpress.com')
        .closeWindow()
        .closeWindow();
});

The window parameter is present. Each call of the t.closeWindow method closes the specified target window:

fixture`TestCafe`
    .page('https://www.example.com/');

test('Closing specific windows', async t => {
    const testcafe = await t.openWindow('https://devexpress.github.io/testcafe');

    await t.openWindow('https://devexpress.com');
    const devexpress = await t.getCurrentWindow();

    await t.closeWindow(devexpress)
        .closeWindow(testcafe);
});