通过或失败场景时的Cucumber-jvm挂钩 [英] Cucumber-jvm Hooks when Scenario is passed or failed

查看:107
本文介绍了通过或失败场景时的Cucumber-jvm挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jbehave 中,我们可以根据方案成功/失败的结果执行方法。以下提到的方法之一将在失败和成功之后执行。

  @AfterScenario(uponOutcome = AfterScenario.Outcome.SUCCESS)
public void afterSuccessfulScenario(){
//一些要执行的代码...
}

@AfterScenario(uponOutcome = AfterScenario.Outcome.FAILURE)
public void afterFailedScenario(){
//一些要执行的代码...
}

我正在尝试在 Cucumber-jvm 中实现相同的目的。场景挂钩 @Before @After 将在每个场景之后执行。但是我想为每种失败情况执行一些代码。



我不确定如何在cumulage-jvm中实现它。有任何线索吗?

解决方案

您可以使用 cucumber-jvm钩子实现它。
如果一个钩子收到 Scenario 作为参数,您可以知道它是否失败。



示例:

  @ 
之后(场景场景){
if(scenario.isFailed()){
//一些要执行的代码...
}
if(scenario.isPassed()){
//一些要执行的代码...
}
}

注意在 @After 的导入: java.after;

希望有帮助。


In Jbehave we can execute method upon outcome of scenario success/failure. One of the below mentioned methods will execute after failure and success.

@AfterScenario(uponOutcome=AfterScenario.Outcome.SUCCESS)
public void afterSuccessfulScenario() {
// Some code to execute...
}

@AfterScenario(uponOutcome=AfterScenario.Outcome.FAILURE)
public void afterFailedScenario() {
// Some code to execute...
}

I'm trying to achieve the same thing in Cucumber-jvm. The scenario Hooks @Before and @After will execute after each scenario. But I want to execute some code for each failure scenario.

I am not sure how to implement it in cucumber-jvm. Any clue?

解决方案

You can achieve it using cucumber-jvm hooks. If a hook receive a Scenario as a parameter, you can know if it has failed or not.

Example:

@After
public void afterScenario(Scenario scenario) {
  if (scenario.isFailed()) {
     // Some code to execute...
  }
  if(scenario.isPassed()) {
     // Some code to execute...
  }
}

Note the import of @After:

import cucumber.api.java.After;

Hope it helps.

这篇关于通过或失败场景时的Cucumber-jvm挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆