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.


The following two examples produce identical test scenarios:

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


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

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


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)