Question

I am using Cucumber-JVM (Groovy) and I was wondering if it is possible intercepting a customized annotation on top of a feature. Ex:

@MyAnnotation
Feature: Something here

//and somewhere a method like this:
def doSomethingForMyAnnotation() {...}

and if it is not possible, if there is an alternative to run some code before a specific feature is run (no @Before that is relative to Scenario).

Was it helpful?

Solution

Of course, you can refer to any of your custom annotations like this in your Groovy-code:

@Before("@MyAnnotation")
public void beforeMyAnnotation() {
    // Do something
}

@After("@MyAnnotation")
public void afterMyAnnotation() {
    // Do something
}

Those are tagged hooks BTW, you can also use more than one. Have look here for a quick example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top