Saltar al contenido principal

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
NombreTipoDetalles
namestringnombre del comando personalizado
callbackFunctionfunción a ejecutar
elementScope
opcional
Booleanextender 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')
})

Welcome! How can I help?

WebdriverIO AI Copilot