Monika Rajendran
Monika Rajendran

Reputation: 33

Scala-Gatling How to use Array.length to iterate/loop a post request and passing sequential array indexed value in post request?

Scala-Gatling How to use Array.length to iterate/loop a post request and passing sequential array indexed value in post request? Gatling : From the response of the below request I saved a String vector value/ String array value

.exec(http("testing")
.post("/testUrl")
.formParam("testvalue", "Testalert")
.check(jsonPath("$[*].id").findAll.saveAs("TestID"))) 
// datatype : vector string / single dimensional array

I have to iterate the below request with testID.length and pass the array indexed value (TestID[i] in to the json page

repeat(testID.length) {
  exec(http("ViewTestPage")
  .post(TestUrl + "/graphql")
  .body(ElFileBody("testpage/testPageView.json"))
 // pass value TestID[i], i++ at each iteration
  .check(status.is(200)))
}

for example : testPageView.json file contains

{"query":"query{api{test(limit:${TestID[i]}){edges{node{id type{role}}}}\"}

Please suggest a solution

Upvotes: 0

Views: 530

Answers (1)

Stéphane LANDELLE
Stéphane LANDELLE

Reputation: 6600

Use a foreach loop instead of repeat to expose the current element on each iteration, see https://docs.gatling.io/reference/script/core/scenario/#foreach

Upvotes: 0

Related Questions