Search code examples
karateintuit-partner-platform

Can we fail Scenario/Scenario-Outline from afterScenario in Karate


Can we fail a scenario/scenario-outline from afterScenario in karate, As there are no soft assertions in karate.

I want my karate code to run complete scenario and finally it should report what are failure and pass.

Work Around:- 1. I tried karate loggers by calling own Java class from afterScenario but it is not reporting in karate report. 2. Tried with Assert statement in own Java class from afterScenario but it is not showing fail status in karate report

Work Around 1:-

** After Scenario in Background **

* configure afterScenario =
"""
function(){
var LoggerPage = Java.type('karate.LoggersPage');
new LoggerPage().error();
}
"""

** Custom Java class method Logger Page **

public void error() {
Logger logger = new Logger();
LogAppender appender = null;
logger.setAppender(appender);
logger.error("Srinu Verifying");
}

Work Around 2:- ** After Scenario in Background **

* configure afterScenario =
"""
function(){
var AssertPage = Java.type('karate.AssetPage');
new AssertPage ().assert();
}
"""

** Asset statement in Java class **

public void error() {
 Assert.assertTrue(false);
}

Solution

  • Can we fail a scenario/scenario-outline from afterScenario

    No you can't. This is never planned to be implemented in Karate, so if you are so interested in this, please contribute code.

    You actually never need "soft assertions" in the first place, because a Scenario Outline (or a call loop using an array of JSON-s as an argument) - will execute all rows of Examples (or the whole array) even if one fails.