5

I have a scenario like this.

 private val feeder = Array(200, 404).map(e => Map("code" -> e)).random.circular

 private val search = scenario("search")
                          .feed(feeder)
                          .exec(http("search")
                          .get("/search/")
                          .headers(headers)
                          .check( if "${code}".equals(200) jsonPath("$.body").exists else jsonPath("$.exception").exists )

Is there a way I can achieve this kinda conditional check. As of now, the observed behavior is, "${code}".equals(200) will always return false.

Sarath
  • 1,438
  • 4
  • 24
  • 40

2 Answers2

2

You can access a session inside jsonPath and extract code from it manually

.check(jsonPath(session => 
      if (session("code").as[Int].equals(200)) "$.body" 
      else "$.exception"
).exists)
Nazarii Bardiuk
  • 4,272
  • 1
  • 19
  • 22
0

According to the documentation, there is the following construct to achieve this:

// with a Gatling EL String condition that resolves a Boolean
.checkIf("#{bool}") {
  jsonPath("$..foo")
}
// with a function
.checkIf(session => session("key").as[String] == "executeCheck") {
  jsonPath("$..foo")
}
pme
  • 14,156
  • 3
  • 52
  • 95