2

I have multiple scenarios in a cucumber feature file. When a step in the first scenario fails, the next scenario will start to execute, but sometimes I want the test to stop execution on the failing scenario. I tried using an @After hook but I am not sure how to tell cucumber to stop the execution in java.

I tried this, but the code could not compile as CucumberHooks could not be resolved

@After
public void after(Scenario scenario) throws Exception {
  CucumberHooks.wantsToQuit = true == s.isFailed();
}

How can I tell cucumber java to stop execution after a scenario fails?

Testilla
  • 602
  • 8
  • 21

1 Answers1

0

In my case I have done it like this where-

@After(order = 1)
    public void afterScenario(Scenario scenario) {
        if (scenario.isFailed()) {
            driver.quit();

Let me know if it helps for you. Also I have added a code for taking screenshot for failed scenario.

Sobhit Sharma
  • 697
  • 14
  • 45
  • I tried your suggestion but getting an error: `java.lang.NullPointerException at StepDefinitions.DemoAppStepDefinition.afterScenario` at the line driver.quit – Testilla Oct 01 '18 at 10:36
  • @TesterMan Please show your code and file arrangement so we can debug. – Sobhit Sharma Oct 01 '18 at 10:51