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
The execution order of Hooks Execution order will be Before Hook 0 -> Before Hook 1 -> Scenario -> After Hook 1 -> After Hook 0. Before the first step of each scenario, Before hooks will be run. Execution order is the same order of which they are registered.
Now, tagging is nothing but a simple annotation. So, you can provide your annotation using a conventional symbol “@” On the other hand, hooks in Cucumber is the code block which can have optional definition in step definition file (with each scenario) by using the annotation @Before and @After.
Cucumber feature files are run in Alphabetical order by feature file name as default. But if you want to try something different by changing the order i.e. by changing the order of the scenarios -- order = random etc.
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.
@Before(value = "@quicklink", order = 20)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With