How do you use Gatling's checkIf method?
Asked Answered
Y

2

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.

Yugoslav answered 13/7, 2018 at 15:54 Comment(0)
Y
14

I found an example in their unit tests as follows:

http("untypedCheckIf").get("/")
      .check(
        checkIf("${bool}") {
          jsonPath("$..foo")
        }
      )
Yugoslav answered 14/7, 2018 at 10:23 Comment(1)
I like idea ... most of Gatling docs doesn't have proper code snippets. finding it at their unitest is best place :)Straightway
W
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"));
Whiten answered 17/8, 2022 at 19:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.