问题描述
我已经开始将 Protractor 与 Mocha 和 Chai 一起使用。我已经到了我做了一些断言等的部分:
const attributes = await TestingModal.getButtonAttributes(driver,myCss)
assert.equal(attributes.text,'Testing','Incorrect text button');
但是我意识到如果断言不匹配,它将打印出“不正确的文本按钮”并将其视为失败。但是,如果属性没有获得任何值,会发生什么等。这也会引发错误。我的问题是,在使用断言时,是否有一种方法可以将所有期望捕获为“失败的测试”?
看起来像这样:https://jestjs.io/docs/en/expect#expectassertionsnumber
解决方法
如何使用 if
语句?
const attributes = await TestingModal.getButtonAttributes(driver,myCss)
if (attributes != undefined && attributes != null) {
assert.equal(attributes.text,'Testing','Incorrect text button');
}