跳到主要内容

覆盖命令

浏览器方法 overwriteCommand 帮助您覆盖浏览器和元素的原生命令,如 pauseclick

信息

您可以在自定义命令部分查看更多相关信息。

用法
browser.overwriteCommand(name, callback, elementScope)
参数
名称类型详情
namestring原始命令的名称
callbackFunction传递原始函数
elementScope
可选
Boolean扩展元素对象而不是浏览器对象
示例
execute.js
// print milliseconds before pause and return its value.
await browser.overwriteCommand('pause', function (origPauseFunction, ms) {
console.log(`Sleeping for ${ms}`)
origPauseFunction(ms)
return ms
})

// usage
it('should use my overwrite command', async () => {
await browser.url('https://webdriver.io')
await browser.pause(1000) // outputs "Sleeping for 1000"
})

Welcome! How can I help?

WebdriverIO AI Copilot