overwriteCommand
The browser method overwriteCommand
helps you to overwrite the browser's and element's native commands like pause
and click
.
info
You can view more information on this in the custom command section.
Usage
browser.overwriteCommand(name, callback, elementScope)
Parameters
Name | Type | Details |
---|---|---|
name | String | name of the original command |
callback | Function | pass original function |
elementScope optional | Boolean | extend the Element object instead of the Browser object |
Example
- Asynchronous Mode
- Synchronous Mode
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"
})
execute.js
// print milliseconds before pause and return its value.
browser.overwriteCommand('pause', function (origPauseFunction, ms) {
console.log(`Sleeping for ${ms}`)
origPauseFunction(ms)
return ms
})
// usage
it('should use my overwrite command', () => {
browser.url('https://webdriver.io')
browser.pause(1000) // outputs "Sleeping for 1000"
})
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.