tosha tosha - 3 months ago 15
Java Question

How to stop execution of a Cucumber feature if any of the scenarios had failed

If I have 10 scenarios in a feature file and if one scenario fails then I want to stop executing or proceeding with next scenario. I want to terminate the execution for that particular feature file. How can I do that in Java?


I notice that the question is tagged with Java. I've not tested the below answer. Its just based on assumption..

Well, we need to tweak the code based on the requirement.. - We have the @Before and @After in Cucumber to serve this requirement.

If I were you, I would do like this...

In @Before, I would check (if any) scenarios were failed or not. If failed, then I'd terminate the thread for the current test and update the results.

In @After, I would update the scenario status and update the result json after test execution.

So, in every iteration (for every scenario) first the @Before will be invoked, in which the logic will look for scenarios which were executed prior to the current scenario.

Also, needless to mention that, I agree with the comments added on the question. All the scenarios should be independent. (But with respect to the requirement, one is allowed to tweak ;) )

Expert Tips mentioned really adds value to the quality of Cucumber and its usage. Hope this helps.

Good luck...!!