Reporting PASSED/FAILED status for each scenario/user?

Hi, is there a way to list a PASSED/FAILED status for each scenario (not each request) in the report ? With the status based on wether or not the session has been marked as failed at the end of the scenario/user run, or something like that.

I have been searching for some hours how to have a JUnit-like html report, but I have not found what I’m looking for so far. The default report gives lots of useful statistics on how long the requests take and their statuses, but so far I’m having to rely on reading/parsing my logs to know wether or not the scenarios has failed, which I doubt is what’s intended

Something like :

Total PASSED : 33
Total FAILED: 11

| Name | PASSED | FAILED |
| MyScenario1 | 30 | 10 |
| MyScenario2 | 0 | 1 |
| MyScenario3 | 1 | 0 |

I have something, it’s not quite perfect, but it’s a start I think. I would appreciate any feedback
Apologies to those here that are used to scala, I’m working with gatling java

I have been unable to find a dummy request that doesn’t do anything, so I’m making my own. I start by launching gatling from inside spring

@SpringBootApplication
public class GatlingWithSpringApplication implements CommandLineRunner {

    private static ConfigurableApplicationContext ctx = null;
    
    public static void main(String[] args) {
         ctx = SpringApplication.run(GatlingWithSpringApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
          // Start Gatling
        GatlingPropertiesBuilder gatlingProperties = new GatlingPropertiesBuilder();
        gatlingProperties.simulationClass(MySimulation.class.getCanonicalName());
        int gatlingReturnCode = Gatling.fromMap(gatlingProperties.build());
        int exitCode = SpringApplication.exit(ctx, () -> gatlingReturnCode);
        System.exit(exitCode);
    }
}

So that I can have a dummy endpoint that is local and always OK

@RestController
class DummyController {
    @GetMapping("/dummy-endpoint")
    public String dummyEndpoint() {
        return "OK";
    }
}

I then create a helper class that will perform assertions after sending a dummy request to ourselves

public class ScenarioUtils {
    public static ChainBuilder assertOnDummy(String assertName, Function<Session, Boolean> assertion) {
        // TODO put the dummy on a less busy port
        return exec(http(assertName + " dummy request").get("http://localhost:8080/dummy-endpoint")
                        .check(status().is(200).name("dummy endpoint must answer for us to do our asserts"))
                        .check(bodyStream()
                               .find()
                               .validate(assertName, (inputStream,session) -> {
                                   Boolean result = assertion.apply(session);
                                   if(result != null && result == false) {
                                       throw new RuntimeException(assertName + " fail");
                                   }
                                   return inputStream;
                               })));
    }   
}

And the last step of my scenario is to check if the session has been marked as failed, which will log the dummy request as OK or KO in the report

            ScenarioBuilder gatlingScenario = scenario("MyScnName")
            .exec(...) // scenario logic 
            // dummy request to show the scenario status as a request status
            .exec(ScenarioUtils.assertOnDummy("MyScnName" + " should not fail",
                                              session -> { 
                                                          return !session.isFailed();
                                                      } ));

Thoughts ?

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.