overwriteCommand
The browser method overwriteCommand
helps you to overwrite the browser's and element's native commands like pause
and click
.
You can view more info on
overwriteCommand
here
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
//print milliseconds before pause and return its value.
//pause - name of command to be overwritten
//origPauseFunction - original pause function
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"
})