Walter Kelt
Walter Kelt

Reputation: 2279

Cucumber Ordered Tagged Hooks

I am trying to use an ordered, tagged hook using Java cucumber. For example:

@Before("@quicklink", order = 20)

The compiler doesn't seem to like it. Is it not possible to have an ordered, tagged hook ? Seems like a reasonable combination of functionality. If so, what is the syntax ?

thnx

Upvotes: 6

Views: 5823

Answers (3)

Jithu Paul
Jithu Paul

Reputation: 174

I have tried the same but in a different way

@Before(value = "@quicklink", order = 20)

But, this may create odd issues if you have another hook method with the same order number for other tests. Like both the methods will run for this scenario.

So I suggest using the tagged expressions if you are using same order like as follows:

For other methods use
@Before(value = "~@quicklink", order = 20) this will make sure this scenario will never run on other methods

and for this scenario alone,

@Before(value = "@quicklink", order = 20)

this will make sure the above method will never run for those.

If you are using 2x version of tagged expressions in your project, you can replace the '~' with a 'not'

This might come handy if you want to replace a method in hooks class in just a specific scenario.

Upvotes: 3

andydavies
andydavies

Reputation: 3293

@Before(value = "@quicklink", order = 20)

Upvotes: 1

Marit
Marit

Reputation: 3026

You should be able to specify the order for hooks like this:

Annotated method style (if you are using cucumber-java):

@Before(order = 10)
public void doSomething(){
    // Do something before each scenario
}

Lambda style (if you are using cucumber-java8):

Before(10, () -> {
    // Do something before each scenario
});

Upvotes: 0

Related Questions