Skip to main content

closeWindow

Close the tab or window of this browsing context. Other tabs and windows stay open, and the session keeps running as long as one of them is left.

Commands on the closed context, and on frames of it, reject afterwards. Mocks made on the context end with it.

Only a top-level browsing context can be closed, a frame rejects.

Usage​

const context = await browser.url('https://webdriver.io')
await context.closeWindow()

Example​

closeWindow.js
it('closes a tab it opened', async () => {
const page = await browser.url('https://webdriver.io')
const tab = await browser.newWindow('https://webdriver.io/docs/api', { type: 'tab' })

await tab.closeWindow()
console.log((await browser.browsingContexts()).length) // outputs: 1
console.log(await page.getTitle()) // the first tab is unchanged
})

Welcome! How can I help?

WebdriverIO AI Copilot