Aller au contenu principal

nouvelleFenêtre

Ouvrir une nouvelle fenêtre ou un nouvel onglet dans le navigateur (par défaut, une nouvelle fenêtre si non spécifié). Cette commande est l'équivalent fonctionnel de window.open(). Cette commande ne fonctionne pas dans les environnements mobiles.

Remarque: Lorsque vous appelez cette commande, vous basculez automatiquement vers la nouvelle fenêtre ou le nouvel onglet.

Utilisation
browser.newWindow(url, { type, windowName, windowFeatures })
Paramètres
NomTypeDétails
urlstringURL du site web à ouvrir
options
optionnel
NewWindowOptionsoptions de la commande newWindow
options.type
optionnel
stringtype de nouvelle fenêtre: 'tab' ou 'window'
options.windowName
optionnel
Stringnom de la nouvelle fenêtre
options.windowFeatures
optionnel
Stringcaractéristiques de la fenêtre ouverte (par ex. taille, position, barres de défilement, etc.)
Exemples
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"
});
Retourne
  • <Object> return: Un objet contenant le handle de la fenêtre et le type de nouvelle fenêtre {handle: string, type: string} handle - L'ID du handle de la fenêtre du nouvel onglet ou de la nouvelle fenêtre, type - Le type de la nouvelle fenêtre, soit 'tab' ou 'window'
Lève
  • Error: Si url est invalide, si la commande est utilisée sur mobile, ou si type n'est pas 'tab' ou 'window'.

Welcome! How can I help?

WebdriverIO AI Copilot