addCommand
Il metodo del browser addCommand
ti aiuta a scrivere il tuo set di comandi personalizzati.
informazione
Puoi trovare maggiori informazioni sull'aggiunta di comandi personalizzati nella guida sui comandi personalizzati.
Utilizzo
browser.addCommand(name, callback, elementScope)
Parametri
Nome | Tipo | Dettagli |
---|---|---|
name | string | nome del comando personalizzato |
callback | Function | funzione da chiamare |
elementScope opzionale | Boolean | estende 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')
})