I need to define a custom annotations in cucumber runner class. I have a event handler class where i get a callback when a test case is finished/started etc.

The issue i am facing is i am not able to get the runner class inside the event handler class, and hence i am unable to read the custom annotations applied in the runner class.

Is there a way for that in cucumber.

Eg. in junit , i can get the custom annotation applied in the test class as : public void testFinished(Description description) { description.getTestClass();} from where i could read my annotation.

in testng, itestContext.getTestClass().getRealClass();.

Any help would be highly appreciated.

Many thanks in advance.

Eg. i need to read the annotations here,

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


1 Answers

Vedant Agrawal On Best Solutions

Solved this issue by :

  1. For Junit : Extending Cucumber runner class. class argument of the constructor returns the runner class where custom annotations are present.

  2. For TestNG : Extending AbstractTestNGCucumberTests in case of TestNG. this.getClass() returns the runner class where custom annotations are present.