跳到主要内容

终止一次

使用以下错误代码之一终止请求一次: Failed, Aborted, TimedOut, AccessDenied, ConnectionClosed, ConnectionReset, ConnectionRefused, ConnectionAborted, ConnectionFailed, NameNotResolved, InternetDisconnected, AddressUnreachable, BlockedByClient, BlockedByResponse

用法
mock.abortOnce(errorCode)
参数
名称类型详情
errorCodeErrorCode响应的错误代码,可以是以下之一:Failed, Aborted, TimedOut, AccessDenied, ConnectionClosed, ConnectionReset, ConnectionRefused, ConnectionAborted, ConnectionFailed, NameNotResolved, InternetDisconnected, AddressUnreachable, BlockedByClient, BlockedByResponse
示例
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"
})

Welcome! How can I help?

WebdriverIO AI Copilot