Home > database >  Gatling - Scala : How to repeat a request until a certain response variable exists in the API respon
Gatling - Scala : How to repeat a request until a certain response variable exists in the API respon

Time:12-07

Gatling - Scala : How to repeat a request until a certain response variable exists in the API response?

This is the request to find the response time of a cursor pagination API

.exec(http("APITests:Cursor Pagination")
  .get("/testapi")
  .queryParam("sortField", "ID")
  .queryParam("limit", limitCount)
  .queryParam("cursor", "#{CursorID}")
  .check(jsonPath("$.nextCursor")).exists
 .check(status.is(200))
)

I have to repeat the request execution until .check(jsonPath("$.nextCursor")).exists = False

Please provide suggestions and help

I tried below ending with error:

 doWhile(session => session(".check(jsonPath(\"$.nextCursor\").exists").as[Boolean]) {
    exec(http("APITests:Cursor Pagination")
      .get("/testapi")
      .queryParam("sortField", "ID")
      .queryParam("limit", limitCount)
      .queryParam("cursor", "#{CursorID}")
      .check(status.is(200))
      .check(jsonPath("$.nextCursor").exists
    ))
  }

But I end up with error : jsonPath($.nextCursor).find.exists, found nothing

CodePudding user response:

Use contains, but you have to save nextCursor into Session

    doWhile(session => !session.contains("nextCursor")) {
      exec(http("...")
        .get("/")
        .check(jsonPath("$.nextCursor").saveAs("nextCursor"))
      )
    }
  • Related