addCommand
El método del navegador addCommand
te ayuda a escribir tu propio conjunto de comandos.
información
Puedes encontrar más información sobre cómo agregar comandos personalizados en la guía de comandos personalizados.
Uso
browser.addCommand(name, callback, elementScope)
Parámetros
Nombre | Tipo | Detalles |
---|---|---|
name | string | nombre del comando personalizado |
callback | Function | función a ejecutar |
elementScope opcional | Boolean | extender el objeto Element en lugar del objeto Browser |
Ejemplo
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')
})