跳至主要内容

abortOnce

使用以下错误代码之一,仅中止一次请求:FailedAbortedTimedOutAccessDeniedConnectionClosedConnectionResetConnectionRefusedConnectionAbortedConnectionFailedNameNotResolvedInternetDisconnectedAddressUnreachableBlockedByClientBlockedByResponse

用法
mock.abortOnce(errorCode)
参数
名称类型详情
errorCodeErrorCode响应的错误代码,可以是以下之一:FailedAbortedTimedOutAccessDeniedConnectionClosedConnectionResetConnectionRefusedConnectionAbortedConnectionFailedNameNotResolvedInternetDisconnectedAddressUnreachableBlockedByClientBlockedByResponse
示例
abortOnce.js
it('should block mock only once', async () => {
const mock = await browser.mock('https://webdriverio.node.org.cn')
mock.abortOnce('Failed')

await browser.url('https://webdriverio.node.org.cn')
// catch failing command as page can't be loaded
.catch(() => {})
console.log(await browser.getTitle()) // outputs: ""

await browser.url('https://webdriverio.node.org.cn')
console.log(await browser.getTitle()) // outputs: "WebdriverIO · Next-gen browser and mobile automation test framework for Node.js"
})

欢迎!我如何帮助您?

WebdriverIO AI Copilot