跳至主要內容

overwriteCommand

瀏覽器方法 overwriteCommand 可協助您覆寫瀏覽器和元素的原生指令,例如 pauseclick

資訊

您可以在自訂指令章節中查看更多相關資訊。

用法
browser.overwriteCommand(name, callback, elementScope)
參數
名稱類型詳細資訊
namestring原始指令的名稱
callbackFunction傳遞原始函式
elementScope
選填
Boolean擴充 Element 物件而非 Browser 物件
範例
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://webdriverio.dev.org.tw')
await browser.pause(1000) // outputs "Sleeping for 1000"
})

歡迎!我能如何協助您?

WebdriverIO AI Copilot