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?
-
For curiosity why do you want to do that.. do you have any dependencies between scenarios?? – Ranjith's Jul 07 '16 at 15:05
-
Yes It does have dependency. – Samantha Jul 07 '16 at 15:52
-
1Ideal would be not having any dependencies between scenario's.. so that if one scenario fails we know where to look for and which scenario is failing.. And also biggest advantage is we can execute the tests in parallel !! – Ranjith's Jul 07 '16 at 15:57
-
Cucumber is not designed to support scenarios with dependencies between them. – Seb Rose Jul 12 '16 at 18:53
2 Answers
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...!!

- 1,387
- 1
- 12
- 22
-
-
Thank you @Seb, It should be `@Before` and `@After` from Cucumber package cucumber.annotation.After/Before – Praveen Jul 13 '16 at 10:12