4

Documented here, Gatling's checkIf method is intended for conditional checking. It's not available on ScenarioBuilder's fluent API but I can see it in the CheckSupport class. I have scoured the internet and cannot find a single example.

I'm using Gatling 2.3.1.

Robert Bain
  • 9,113
  • 8
  • 44
  • 63

2 Answers2

14

I found an example in their unit tests as follows:

http("untypedCheckIf").get("/")
      .check(
        checkIf("${bool}") {
          jsonPath("$..foo")
        }
      )
Robert Bain
  • 9,113
  • 8
  • 44
  • 63
0

Under Gatling 3.7.6, this worked for me:

http("Test Gatling checkIf()")
    .get("/")
    .check(status().in(200, 404).saveAs("httpStatus"))
    .checkIf(session -> "200".equals(session.getString("httpStatus")))
        .then(
            jmesPath("someField")
                .saveAs("fieldName"))
    .checkIf(session -> "404".equals(session.getString("httpStatus")))
        .then(
            jmesPath("someField")
                .withDefault("some default value")
                .saveAs("fieldName"));
lpacheco
  • 976
  • 1
  • 14
  • 27