【问题标题】:Using soft assertion in cucumber在黄瓜中使用软断言
【发布时间】:2021-11-24 19:24:48
【问题描述】:

我正在使用带有 selenide 的 cucumber,当我在 Selenide 配置和运行场景中添加 assertionMode = SOFT 时,我收到此错误。

您必须使用 https://github.com/selenide/selenide/wiki/SoftAssertions 中记录的 JUnit4/JUnit5/TestNG 机制配置您的类

看来我应该在 before 和 after 方法的钩子中使用 ErrorsCollector。

我在 hooks 包中设置了驱动程序,并在方法之前设置了 selenide 功能。

谁能告诉我在哪里以及如何使用ErrorsCollector?

或者还有别的什么?

【问题讨论】:

  • 如何运行测试?你用的是哪个跑步者?您是否还在openBrowser 中设置了软断言?
  • @AlexeyR。我通过功能文件运行我的测试。 Runner 是 TestRunner 类: (@RunWith(Cucumber.class) @CucumberOptions(features = "src/test/resources/features", glue = {"hooks", "steps"},) 软断言设置: assertionMode = SOFT

标签: java cucumber selenide


【解决方案1】:

TestNG中存在Soft Assertion,所以请添加TestNG maven依赖

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.1.0</version>
</dependency>

和 在代码中,

SoftAssert aa = new SoftAssert();
aa.assertEquals(true, true);

【讨论】:

  • TestNg 用于测试注释,但在 Cucumber 框架中,测试是通过特征文件运行的。同样在 Selenide 中,您不需要使用 assertEquals,在 should 构造中使用条件。
【解决方案2】:

由于您在 @RunWith 注释的帮助下运行测试,因此我假设引擎盖下有 JUnit 4。

所以你可以尝试添加这个字段

@Rule 
public SoftAsserts softAsserts = new SoftAsserts();

到使用@RunWith 注释的类(TestRunner 类)。

【讨论】:

  • @Rule 不适用于 TestRunner 类中的类型
  • 什么意思?是错误信息吗?
  • 不知道。无法正确识别规则注释,当我将鼠标悬停在它上面时,会收到该消息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多