【问题标题】:Cucumber execution stops for execution if initial @then fails for Automation如果初始 @then 自动化失败,黄瓜执行将停止执行
【发布时间】:2020-06-05 02:37:42
【问题描述】:

我正在使用黄瓜框架进行测试。我有三个 @then 条件,如果第一个 @then 条件失败,它不会进入第二个 @then 条件。我该如何克服?

   @Then("^I check first result$")
public void verifyFirstResult() {
    Assert.assertEquals(results.get("first"), true);    --> This gets failed as its returning false.    
}


@Then("^I check second result$")
public void verifySecondResult() {
    Assert.assertEquals(results.get("second"), true);  --> This is not even triggering, the execution stops at the first method itself 
}


 @Then("^I check third result$")
public void verifyThirdResult() {
    Assert.assertEquals(results.get("third"), true);  
}

我该如何克服这个问题?

【问题讨论】:

    标签: java automation cucumber


    【解决方案1】:

    在编写步骤时,您无法克服此问题。这就是黄瓜的工作原理。如果某个步骤失败,则会跳过所有后续步骤,直到场景结束。

    如果您想在一个Then 步骤中检查多个条件,您可以创建一个检查多个条件的“复合”步骤,这将导致这一步失败。这通常使用数据表来完成:

    Then the results should be:
        | Field  | Value |
        | First  | true  |
        | Second | true  |
        | Third  | true  |
    

    参考资料:

    【讨论】:

    • 谢谢。但是那些文档没有提供任何 sn-ps。你可以发布一个 sn-p
    【解决方案2】:

    您能否更好地澄清这个问题? 1)您是否尝试同时检查三个条件,以便如果其中任何一个(无论哪一个)失败,测试都会失败? 2) 或者您是否有兴趣了解发生错误时哪个特定条件失败?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 2018-04-17
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      相关资源
      最近更新 更多