在功能文件中的任何测试之前,我们在黄瓜中是否有任何注释 运行?

Do we have any annotation in cucumber where it will run before any of the tests in the feature file?

@Before 方法将在每个场景之前 运行。我们是否在任何场景之前有一个注释 运行,在所有场景执行之后有一个注释?

正如评论中指出的那样,cucumber 对此没有开箱即用的解决方案。

但是您可以只使用静态标志为 运行 创建一个前挂钩。

private static boolean skipFlag = false;

@Before
public void beforeHook() {

    if(!skipFlag) {
        do stuff
        skipFlag=true;
    }
}

将某些标签等的 Before 挂钩修改为 运行。

最后 运行 的 after hook 很难。要么专门创建一个场景,要么在最后一步完成所有的 after hook 操作。或者您可以将代码写在 JVM shutdown hook 中,尽管在所有功能文件都是 运行.

之后它会 运行

您可以使用 gerkin with qaf where you can use different TestNG listeners and annotations. In addition to that if you are using webdriver you can get additional driver and element listeners 支持。例如

package my.test.pkg
public class MyClass{
    @BeforeSuite
    public void beforeSuite() {
       //get executed before suite
    }

    @BeforeTest
    public void beforeTest() {
       //get executed before each xml test

    }
    @BeforeMethod
    public void beforeMethod() {
       //get executed before each test case/scenario

    }
    @BeforeGroups(["p1","p2"])
    public void beforeMethod() {
       //get executed before group

    }
    //same for after methods @afterXXXXX

 }

您需要在配置文件中添加class:

<test name="Gherkin-QAF-Test">
   <classes>
      <class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
      <class name="my.test.pkg.Myclass" />
   </classes>
</test>

这个例子没有使用监听器。您还可以使用不同的侦听器。