成功提交后,我正在尝试验证给定网页的标题(文本)。
我的命令:
async confirmSuccessfulSubmission() {
return $("#contact_reply h1").getText().then((value) => {
//incorrect text should be:Thank You for your Message!
expect(value.to.equal("Thank You for your Message!2"));
});
}
例外:
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
正确的标题是:谢谢您的留言!因此,如果标题为:“谢谢您的信息!” 2,则测试应失败(Chai声明)。
有什么想法吗?
感谢您的帮助
答案 0 :(得分:1)
async confirmSuccessfulSubmission() {
try{
let value = await $("#contact_reply h1").getText()
if(value)
return expect(value).to.equal("Thank You for your Message!2");
return null
} catch(e) {
console.log(e)
}
}
捕获异常,这样您就可以看到那里出了什么问题