Vai al contenuto principale

addCommand

Il metodo del browser addCommand ti aiuta a scrivere il tuo set di comandi personalizzati.

info

Puoi trovare maggiori informazioni sull'aggiunta di comandi personalizzati nella guida sui comandi personalizzati.

Utilizzo​
browser.addCommand(name, callback, elementScope)
Parametri​
NomeTipoDettagli
namestringnome del comando personalizzato
callbackFunctionfunzione da chiamare
elementScope
opzionale
Booleanestende l'oggetto Element invece dell'oggetto Browser
Esempio​
execute.js
await browser.addCommand('getUrlAndTitle', async function (customParam) {
// `this` refers to the `browser` scope
return {
url: await this.getUrl(),
title: await this.getTitle(),
customParam: customParam
}
})
//usage
it('should use my add command', async () => {
await browser.url('https://webdriver.io')
const result = await browser.getUrlAndTitle('foobar')

assert.strictEqual(result.url, 'https://webdriver.io')
assert.strictEqual(result.title, 'WebdriverIO · Next-gen browser and mobile automation test framework for Node.js | WebdriverIO')
assert.strictEqual(result.customParam, 'foobar')
})

Welcome! How can I help?

WebdriverIO AI Copilot