Ivan Lytvynenko
Ivan Lytvynenko

Reputation: 21

How the order of 'After' hooks can be configured in Cucumber js?

There are several 'After' hooks and one of them should be first than others, how it could be configured in the Cucumber JS?

Upvotes: 2

Views: 2395

Answers (4)

Lunivore
Lunivore

Reputation: 17602

You can explicitly configure hooks to run in a certain order:

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

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

It seems this also works for @After hooks.

Edit: Leaving this in case it's useful for any Java people - missed that it was JS, sorry! But for Javascript:

Hooks are executed in the order in which they're defined. If that doesn't do it for you, create one hook and explicitly call the other methods.

Upvotes: 1

Sreenivasulu
Sreenivasulu

Reputation: 514

Hooks is a file which will be executed from top to bottom. If you have more After tags, go in such a way that which you want to close first of all will be first and the last what you want to execute to be last. If you have tags in your feature file, pass that information to the specific After

Upvotes: 0

Sreenivasulu
Sreenivasulu

Reputation: 514

You can use tags concept for each scenario in cucumber feature file and use same tag on each @After annotation which will resolve for which test scenario's that specific @After should execute

Upvotes: 0

Ray
Ray

Reputation: 1214

Ordered by top to bottom in the hooks file

After({}, async function() {
  return "This will run first";
});

After({}, async function() {
  return "tThis will run second";
});

Upvotes: 0

Related Questions