abortOnce
Overview
Use the abortOnce
command to abort a request once with a specified error.
A request can be aborted with one of the following errors:
- Failed
- Aborted
- TimedOut
- AccessDenied
- ConnectionClosed | ConnectionReset | ConnectionRefused | ConnectionAborted | ConnectionFailed
- NameNotResolved
- InternetDisconnected
- AddressUnreachable
- BlockedByClient | BlockedByResponse
Usage
mock.abortOnce(errorCode);
Command Parameters
Name | Type | Description |
errorCode | ErrorCode | The response error code. Possible values are listed above. |
Usage Examples
it("should block mock only once", async ({ browser }) => {
const mock = await browser.mock("https://webdriver.io");
mock.abortOnce("Failed");
await browser
.url("https://webdriver.io")
// catch exception as the request to the page will fail
.catch(() => console.log('Failed to get the page "https://webdriver.io"'));
await browser.url("https://webdriver.io");
console.log(await browser.getTitle());
// will output: "WebdriverIO · Next-gen browser and mobile automation test framework for Node.js"
});
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.