跳至主要內容

call

您可以使用 call 在您的測試規範中執行任何非同步操作。它接受 Promise,並停止執行直到 Promise 被解析。

資訊

隨著 WebdriverIO 棄用同步使用 (請參閱 RFC),此命令不再那麼有用。

用法
browser.call(callback)
參數
名稱類型詳細資訊
callback函式要呼叫的函式
範例
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)
})
})
})
});

歡迎!我能如何幫你?

WebdriverIO AI Copilot