Monika
Mon, 27 Feb 2023 15:12:02 +0000
Gatling (Open-Source)

Gatling-Scala : How to consolidated( group strings) from a loop output to a String Array or Vector Array

1. I need to loop with array value providing string output

2. consolidated all the retrieved string output as an array

3. use the consolidated array in next bulk api request.

My logic is not working, kindly help me.

Please help me if there are easier methods with gatling keywords

 var i = 0 // initialising i to 0 to increase the array index value in loop
.
.
...check(jsonPath("$.id").saveAs("ArrayValues"))
// saving this array to use in loop and at defining arraylength at last of the loop

//loop

    .foreach("#{ArrayValues}", "VValues") {
      exec(http("perftest values")
        .post("perftest")
        .body(StringBody(session =>
          s"""{
             |"id": "",
             |"perfTypeId": "00334-0000-0000-0345",
             |"legs":[{
             |      "valueTypeId": "111-220-3300-0444",
             |      "values": "${session("VValues").as[String]}"
             |    }]
             |     }""".stripMargin)).asJson
        .check(jsonPath("$.id").saveAs("perfvalue_singlevalue"))
        .check(status.is(201)))
        .exec(session => {
          val valuearraylen: Vector[String] = session("ArrayValues").as[Vector[String]]
          val perfvalue_array: Array[String] = new Array[String](valuearraylen.length)
          perfvalue_array(i) = session("perfvalue_singlevalue").as[String]
// ERROR in above logic
 // saving value in updated array index
          i = i + 1. // moving to next array index
          session.set("string_collected_array", perfvalue_array)
        })

//provide the created array value to next api request

.exec(http("Bulk_perftest")
    .delete("/perf/bulk")
    .body(StringBody(session => s"""[
    "${session("string_collected_array").as[Vector[String]].mkString("\",\"")}"]"""))
    .check(status.is(204)))

//ERROR cannot pass the value - error no attribute name defined “string_collected_array”

6 posts - 3 participants