跳到主要内容

call 方法

你可以使用 call 在测试规范中执行任何异步操作。 它接受 Promise 并暂停执行,直到 Promise 被解决。

信息

随着 WebdriverIO 弃用同步使用(参见 RFC), 这个命令已经不太有用了。

用法
browser.call(callback)
参数
名称类型详情
callbackFunction要调用的函数
示例
call.js
it('some testing here', async () => {
await browser.url('http://google.com')
// make an asynchronous call using any 3rd party library supporting promises
// e.g. call to backend or db to inject fixture data
await browser.call(() => {
return somePromiseLibrary.someMethod().then(() => {
// ...
})
})

// example for async call to 3rd party library that doesn't support promises
const result = await browser.call(() => {
return new Promise((resolve, reject) => {
someOtherNodeLibrary.someMethod(param1, (err, res) => {
if (err) {
return reject(err)
}
resolve(res)
})
})
})
});

Welcome! How can I help?

WebdriverIO AI Copilot