Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber : How to skip subsequent steps and exit out of the scenario without failing the step / scenario?

I have had my feature file in Cucumber and am using Given, When, Then syntax(Gherkin) to write my scenarios in it and have the corresponding steps in the Step Definition file. I have a scenario, where I am checking if a particular data set exists(which is part of my Given step ) then continue with my next steps for "Then", "And" etc But if it's not, then it should skip rest of the steps and exit out of the Step Definition file without failing the scenario. Can someone please advise if this is supported in Cucumber? If yes, what is the best way to do it?

like image 844
user5252179 Avatar asked Jul 31 '18 14:07

user5252179


1 Answers

You can use JUnits Assume or TestNG's SkipException to mark a test as skipped if a specific assumption fails. Skipped tests are not considered failures.

From https://github.com/cucumber/cucumber-jvm/tree/master/junit

Through Assume JUnit provides:

a set of methods useful for stating assumptions about the conditions in which a test is meaningful. A failed assumption does not mean the code is broken, but that the test provides no useful information. The default JUnit runner skips tests with failing assumptions. Custom runners may behave differently.

The Cucumber runner supports Assume and will marked skipped scenarios as skipped.

From https://github.com/cucumber/cucumber-jvm/tree/master/testng

Cucumber provides limited support for SkipException.

  • Throwing a SkipException results in both Cucumber and TestNG marking the test as skipped.
  • Throwing a subclass of SkipException results in Cucumber marking the test as failed and TestNG marking the test as skipped.
like image 60
M.P. Korstanje Avatar answered Oct 01 '22 23:10

M.P. Korstanje