Pular para o conteúdo principal

novaJanela

Abrir nova janela ou aba no navegador (o padrão é uma nova janela se não for especificado). Este comando é a função equivalente ao window.open(). Este comando não funciona em ambientes móveis.

Nota: Ao chamar este comando, você automaticamente muda para a nova janela ou aba.

Uso
browser.newWindow(url, { type, windowName, windowFeatures })
Parâmetros
NomeTipoDetalhes
urlstringURL do site a ser aberto
options
opcional
NewWindowOptionsopções do comando newWindow
options.type
opcional
stringtipo de nova janela: 'tab' ou 'window'
options.windowName
opcional
Stringnome da nova janela
options.windowFeatures
opcional
Stringcaracterísticas da janela aberta (por exemplo, tamanho, posição, barras de rolagem, etc.)
Exemplos
newWindowSync.js
it('should open a new window', async () => {
await browser.url('https://google.com')
console.log(await browser.getTitle()) // outputs: "Google"

const result = await browser.newWindow('https://webdriver.io', {
windowName: 'WebdriverIO window',
windowFeature: 'width=420,height=230,resizable,scrollbars=yes,status=1',
})
console.log(await browser.getTitle()) // outputs: "WebdriverIO · Next-gen browser and mobile automation test framework for Node.js"
console.log(result.type) // outputs: "window"
const handles = await browser.getWindowHandles()
await browser.switchToWindow(handles[1])
await browser.closeWindow()
await browser.switchToWindow(handles[0])
console.log(await browser.getTitle()) // outputs: "Google"
});

newTabSync.js
  it('should open a new tab', async () => {
await browser.url('https://google.com')
console.log(await browser.getTitle()) // outputs: "Google"

await browser.newWindow('https://webdriver.io', {
type:'tab',
windowName: 'WebdriverIO window',
windowFeature: 'width=420,height=230,resizable,scrollbars=yes,status=1',
})
console.log(await browser.getTitle()) // outputs: "WebdriverIO · Next-gen browser and mobile automation test framework for Node.js"
console.log(result.type) // outputs: "tab"
const handles = await browser.getWindowHandles()
await browser.switchToWindow(handles[1])
await browser.closeWindow()
await browser.switchToWindow(handles[0])
console.log(await browser.getTitle()) // outputs: "Google"
});
Retorna
  • <Object> return: Um objeto contendo o identificador da janela e o tipo de nova janela {handle: string, type: string} handle - O ID do identificador da janela da nova aba ou janela, type - O tipo da nova janela, 'tab' ou 'window'
Lança
  • Error: Se url for inválido, se o comando for usado em dispositivos móveis, ou se type não for 'tab' ou 'window'.

Welcome! How can I help?

WebdriverIO AI Copilot