Problem with data usage from feeder in the jsonPath check

Hi Gatling community!

Could you please help with the following issue:

In Gatling test I want to get requests from Wiremock and save some data (e.g. “responseId”).
I’m trying to use loop and save find(0), find(1)… find(n) elements to the session. But when I used find("${id}".toInt) in my code Gatling returns error: java.lang.NumberFormatException: For input string: “${id}”

At the same time ${id} returns needed value for exec(http()) section.

Please take a look at code below and help me define what is wrong:

  val users = 2

  val finiteFeeder = (for (i <- 0 until users) yield {
    Map("id" -> s"$i")
  })

  val parseLogs: ScenarioBuilder = {
    scenario("Parse logs")
      .repeat(users) {
        feed(finiteFeeder)
          .exec(http("Get mock service request ${id}")
            .get("/__admin/requests/")
            .body(StringBody("""{ "method": "POST", "url": "/api/v4.1/event/sync" }""")).asJson
            .check(jsonPath("$..id").find("${id}".toInt).saveAs("responseId"))
          )
      }
  }

Thank you in advance!

find does not take Gatling Expression Language parameter, you cannot use session variable in it.

In your case, I recommend to change the jsonPath:

jsonPath("$..id[#{id}]").saveAs("responseId")

Note: I used the new #{...} notation. as ${...} is deprecated to avoid conflict with scala or kotlin string interpolation.

Thank you, it works and meet the needs.