Skip to main content

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

NameTypeDescription
errorCodeErrorCodeThe 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"
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.