isanma
isanma

Reputation: 175

Gatling set in queryParam value from response

I am working in creating some tests with Gatling for an API. I was able to complete the different tests for normal get and search endpoints. The problem comes when testing methods using ScrollAPI with Elastic. I need to get the value from the response, which would be the ScrollId, and then use this value as queryParam in the next requests until there is no scrollId returned in the response. I think I am able to save the value from the response, but I have not been able to use that value in the next requests: This is my code so far:

    builder
        .exec(http(s"$title")
          .post(endpoint)
          .headers(headers)
          .body(ElFileBody(requestBodyFilePath))
          .check(jsonPath("$..scrollId").optional.saveAs("scrollId")))
        .pause(1)
      //save value from response
          .exec(session => {
            val scrollId = session("scrollId").asOption[String]
            session.set("scrollId", scrollId)
          })
        .asLongAs("${scrollId.exists()}") {
          .exec(http(s"$title")
            .post(endpoint)
            .headers(headers)
            .body(ElFileBody(requestBodyFilePath))
            //use value in response
            .queryParam("scrollId", "${scrollId}")
            .check(jsonPath("$..scrollId").optional.saveAs("scrollId"))
            .check(status.is(200)))
        }

Thank you!!!

Upvotes: 0

Views: 324

Answers (1)

Stéphane LANDELLE
Stéphane LANDELLE

Reputation: 6623

pseudo code:

asLongAs("${scrollId.isUndefined()}") {
  // remove existing "scrollId" from session in a exec(function) block
  // perform request that saves scrollId with an option check
}

Upvotes: 1

Related Questions