如何在黄瓜事件处理程序中获取 Runner class

How to get Runner class inside cucumber event handler

我需要在 Cucumber runner 中定义自定义注释 class。我有一个事件处理程序 class,当测试用例为 finished/started 等时我会收到回调

我面临的问题是我无法在事件处理程序 class 中获取运行器 class,因此我无法读取运行器中应用的自定义注释 class.

黄瓜有办法吗?

例如。在 junit 中,我可以获得在测试 class 中应用的自定义注释,如下所示: public void testFinished(Description description) { description.getTestClass();} 从哪里可以看到我的注释。

在testng中,itestContext.getTestClass().getRealClass();.

非常感谢任何帮助。

非常感谢。

例如。我需要阅读这里的注释,

private EventHandler<TestCaseFinished> caseFinishedEventHandler = new EventHandler<TestCaseFinished>() {
    @Override
    public void receive(TestCaseFinished event) {
     //Read annotations here...
    }
}; /*Or here*/ private EventHandler<TestRunFinished> runFinishedEventHandler = new EventHandler<TestRunFinished>() {
    @Override
    public void receive(TestRunFinished event) {

    }
};

解决了这个问题:

  1. 对于 Junit:扩展 Cucumber runner class。 class 构造函数的参数 returns 运行器 class 其中存在自定义注释。

  2. 对于 TestNG:在 TestNG 的情况下扩展 AbstractTestNGCucumberTests。 this.getClass() returns runner class 其中存在自定义注释。