abortOnce
Abort the request once with one of the following error codes:
Failed
, Aborted
, TimedOut
, AccessDenied
, ConnectionClosed
,
ConnectionReset
, ConnectionRefused
, ConnectionAborted
,
ConnectionFailed
, NameNotResolved
, InternetDisconnected
,
AddressUnreachable
, BlockedByClient
, BlockedByResponse
.
Usage
mock.abortOnce(errorCode)
Parameters
Name | Type | Details |
---|---|---|
errorCode | ErrorCode | error code of the response, can be one of: Failed , Aborted , TimedOut , AccessDenied , ConnectionClosed , ConnectionReset , ConnectionRefused , ConnectionAborted , ConnectionFailed , NameNotResolved , InternetDisconnected , AddressUnreachable , BlockedByClient , BlockedByResponse |
Example
- Asynchronous Mode
- Synchronous Mode
abortOnce.js
it('should block mock only once', async () => {
const mock = await browser.mock('https://webdriver.io')
mock.abortOnce('Failed')
await browser.url('https://webdriver.io')
// catch failing command as page can't be loaded
.catch(() => {})
console.log(await browser.getTitle()) // outputs: ""
await browser.url('https://webdriver.io')
console.log(await browser.getTitle()) // outputs: "WebdriverIO · Next-gen browser and mobile automation test framework for Node.js"
})
abortOnce.js
it('should block mock only once', () => {
const mock = browser.mock('https://webdriver.io')
mock.abortOnce('Failed')
browser.url('https://webdriver.io')
// catch failing command as page can't be loaded
.catch(() => {})
console.log(browser.getTitle()) // outputs: ""
browser.url('https://webdriver.io')
console.log(browser.getTitle()) // outputs: "WebdriverIO · Next-gen browser and mobile automation test framework for Node.js"
})
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.