Kirill
Kirill

Reputation: 1538

Cucumber: How to find out either current scenario is last one or not in After hook?

I need to execute specific function after each scenario, except the last one in the queue. Is there a way to do that?

Upvotes: 0

Views: 773

Answers (1)

alannichols
alannichols

Reputation: 1506

Could you not move the function to be in the Before hook instead? That way it would never run on the last scenario, but would run for all other scenarios.

If you don't want it to run before the first scenario for whatever reason, you can set a global variable to store whether this scenario is the first one.

e.g.

In env or somewhere create and set

$first_scenario = true

Then in the before hook

run_your_function unless $first_scenario
$first_scenario = false

Upvotes: 1

Related Questions