Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber Ordered Tagged Hooks

Tags:

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

like image 625
Walter Kelt Avatar asked Jan 03 '18 18:01

Walter Kelt


People also ask

How do you define an order of execution of hooks in Cucumber?

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.

What are tagged Hooks Cucumber?

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.

Do Cucumber scenarios run in order?

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.


2 Answers

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.

like image 144
Jithu Paul Avatar answered Sep 22 '22 13:09

Jithu Paul


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

like image 20
andydavies Avatar answered Sep 20 '22 13:09

andydavies