【问题标题】:After Step and before Step Cucumber步骤之后和步骤之前黄瓜
【发布时间】:2018-05-20 03:28:26
【问题描述】:

我想在每个步骤(不是场景)之前和之后执行一些操作。我如何在 Cucumber 中做到这一点?

就像 junit 中的 after 和 before。

** 我正在使用 java。

【问题讨论】:

  • @ttechen9 我已经复制了你的答案,但它不起作用。看起来有人需要调用 beforeRunningStep 。我需要完整的例子
  • Cucumber-JVM 有一个 Before 和一个 After 注释。它在每个场景之前和之后调用。这类似于在每次测试之前和之后调用的 JUnit 之前和之后注释。我不知道在每个步骤之前调用的任何内容。请分享有关您想要实现的目标的更多信息,我们或许可以为您提供替代解决方案。
  • @Thomas Sundberg 我知道你所说的一切,也从上面的链接中你可以看到其他人试图以某种方式实现这一点。在我们搬到 Cucumber 之前,我们使用了另一个自动化工具(jsystem),它使用了 junit 注释。我们有一段代码在每个 step/test 之前和之后执行。我想我现在必须在不使用这些注释的情况下调用这些代码块。
  • Cucumber-JVM 中目前没有@AfterStep。见:github.com/cucumber/cucumber-jvm/pull/938(打开 PR 合并冲突)

标签: java automation cucumber bdd


【解决方案1】:

应该有AfterStep之类的(还没找到BeforeStep)

AfterStep do #After every step #this is also before the next step... end

如果您想针对某些步骤过滤这些内容,请执行此操作

AfterStep('@cucumis', '@sativus') do # This will only run after steps within scenarios tagged # with @cucumis AND @sativus. end

参考:https://github.com/cucumber/cucumber/wiki/Hooks

【讨论】:

  • 这不在java中
【解决方案2】:

在 io.cucumber 的最新版本中,@AfterStep 和 @BeforeStep 钩子都可用,

import cucumber.api.java.AfterStep;
import cucumber.api.java.BeforeStep;

public class Hooks {

    @BeforeStep
    public void beforeStep() {
        System.out.println("======>  This is before step  <======");
        //Do something before executing the step
    }

    @AfterStep
    public void afterStep() {
        System.out.println("======>  This is after step  <======");
        //Do something after executing the step
    }

}

【讨论】:

    【解决方案3】:

    BeforeStep 和 AfterStep 钩子在最新的 cucumber jvm api 中可用。只需使用 cucumber-jvm 的最新版本更新您的 pom。欲了解更多信息,请点击以下链接:

    https://github.com/damianszczepanik/maven-cucumber-reporting/issues/100

    【讨论】:

      猜你喜欢
      • 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
      相关资源
      最近更新 更多