赶上承诺拒绝
Catch Promise Rejection
我正在 运行 使用 WebdriverIO 进行测试,并且恰好在这一行:
await browser.waitForVisible('#tx-sent li', 15000)
时不时地,我会收到 Promise 拒绝错误:
Error: Promise was rejected with the following reason: java.net.SocketException: Connection reset by peer (connect failed)
有没有办法捕捉到这个 promise 拒绝,这样它就不会导致整个测试失败?换句话说,我想抓住这个 Promise 拒绝并解决它。
您可以使用try/catch
try {
await browser.waitForVisible('#tx-sent li', 15000);
} catch(e) {
console.log(e);
}
您可以使用 try 和 catch 来处理 promise 中的错误。做这样的事情
try {
await browser.waitForVisible('#tx-sent li', 15000)
} catch(error) {
// thro or log erro as per you need
//throw error;
console.log(error);
}
我正在 运行 使用 WebdriverIO 进行测试,并且恰好在这一行:
await browser.waitForVisible('#tx-sent li', 15000)
时不时地,我会收到 Promise 拒绝错误:
Error: Promise was rejected with the following reason: java.net.SocketException: Connection reset by peer (connect failed)
有没有办法捕捉到这个 promise 拒绝,这样它就不会导致整个测试失败?换句话说,我想抓住这个 Promise 拒绝并解决它。
您可以使用try/catch
try {
await browser.waitForVisible('#tx-sent li', 15000);
} catch(e) {
console.log(e);
}
您可以使用 try 和 catch 来处理 promise 中的错误。做这样的事情
try {
await browser.waitForVisible('#tx-sent li', 15000)
} catch(error) {
// thro or log erro as per you need
//throw error;
console.log(error);
}