I am using Cucumber JVM with Groovy and using try catch block in assertions like:
try {
assert response.status == 200
tr.pass("Status is 200")
} catch(AssertionError err) {
tr.fail(err.message)
}
Now, if somehow assertion fails then it will catch the exception and not stop the scenario at that time and start executing next step in same scenario. I have 2 choice: 1. after try catch I put my assertion again 2. Add some code in catch block which abort my scenario and proceed with next scenario.
I am preferring option 2. Please help me out.
Not tr.pass and tr.fail are user defined function to write status,
i think it is doing already if you do not use try catch in step definition. You could use assertion in step definition.
assertTrue(response.status == 200);
If it fails than stop scenario and skip other step (When,And and Then) and move on other scenario.