How to handle List session attributes and for loop in PebbleStringBody to create a bulk Json request.
Gatling-Scala
.exec(http("Find Perf")
.get("/Perf")
.queryParam("PerfId", PerfId)
.check(jsonPath("$.results[*].id").findAll.saveAs("PerfTestID"))
.check(jsonPath("$.results[*].name").findAll.saveAs("PerfName"))
.check(jsonPath("$.results").findAll.saveAs("TotalPerfdata"))
.check(status.is(200))
)
.exec(http("Perf_Execution")
.post("/Perf/bulk")
.header("Content-Type", "application/json")
.body(PebbleStringBody(
"""[
| {% for t in range(1,2) %}// I tried {{PerfTestID}} in range but it throws syntax error
| {
| "id": "{{PerfTestID}}",
| "name":{{PerfName}}",
| "value": {}
| }
| {% if loop.last %}
| {% else %},{% endif %}
| {% endfor %}
| ]""".stripMargin)).asJson)
setUp(scn.inject(atOnceUsers(nbUsers)))
.protocols(httpProtocol);
Error Result :
body:StringRequestBody{charset=UTF-8, content=[
{
"id": "[ed811977-0992a, bd34bc09-e748]",
"name": "[Perftest1,Perftest2]"
"value": {}
}
,
{
"id": "[ed811977-0992a, bd34bc09-e748]", // Value Identical at for loop iteration
"name": "[Perftest1,Perftest2]"
"value": {}
} ]}
Issues here :
- Cannot dynamically assign value to for loop
- do not know how List ( Session attributes) will work in Pebble string
- after the loop it gives same value at each iteration
– causing 400 error
Expected result :
body:StringRequestBody{charset=UTF-8, content=[
{
"id": "ed811977-0992a",
"name": "Perftest1"
"value": {}
} ,
{
"id": "bd34bc09-e748",
"name": "Perftest2"
"value": {}
} ]}
Please suggest a solution with example