使用 assert

问题描述

我已经开始将 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');
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...