overwriteCommand
Overview
Use the overwriteCommand
command to override existing commands of the browser or an element.
info
Also see the recipe "How to add custom commands".
Usage
await browser.overwriteCommand(name, callback, elementScope);
Command Parameters
Name | Type | Description |
name | String | The name of the custom command. |
callback | Function | The function implementation of the command. |
elementScope | Boolean | If the value is true, add the command to the element instead of the browser. Default: false. |
Usage Examples
// log the pause duration in ms before the pause and then return the value
await browser.overwriteCommand("pause", function (origPauseFunction, ms) {
console.log(`Sleeping for ${ms}`);
origPauseFunction(ms);
return ms;
});
// use the overwritten pause command
it("should use my overwrite command", async ({ browser }) => {
await browser.url("https://webdriver.io");
await browser.pause(1000); // outputs: "Sleeping for 1000"
});
Related Commands
References
We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.