Hello!
I am trying to perform a request repeatedly based on the response of the previous one and I can’t seem to get it right.
I have a feeder that generates a List[Map[String, String]]
inside the virtual user’s session like the one below (the names have been changed):
requestParams -> List(Map(param1 -> , param2 -> , param3 -> 1234, param4_2777 -> 4, param5 -> false, param6 -> false)), ...)
The scenario conains a foreach("${requestParams}", "param") { ... }
that loops over every Map[String,String]
in the List
and passes the map using Gatling EL directly to a builder like the following
http("Do Action")
.post("/mypage.html")
.headers(default)
.formParam("CSRF_TOKEN", csrfToken)
.formParam("action", "")
.formParamMap(requestParams)
The param4_2777
parameter could have any number after it, like 2777 in our example here, and the value of it is what I want to change.
The target flow is as follows:
- Make the request with the map initially found in the session (e.g., the one shown above).
- If the request fails (this could be detected by a specific string on the response) decrease the number in the
param4_2777
parameter by 1and fire the request again. Repeat until the request succeeds or the number is 0.
As a first step, I am trying the simple case of updating the values in the session to no avail:
foreach("${requestParams}", "param") {
exec(
exec { session => println(session.update()); session},
exec { session => {
val rp = session("requestParams").as[List[Map[String, String]]]
val newrp = List(rp.head map {
case ("param4_2777", value) => "param4_2777" -> (value.toInt - 1)
case x => x
})
session.set("requestParams", newrp)
}}
)
}
When I run the map to update the value in the Scala REPL console I get the result fine but when I run the test in Gatling I get the following error and the update fails:
14:26:09.664 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - 'hook-3' crashed with 'j.l.ClassCastException: class java.lang.Boolean cannot be cast to class java.lang.String (java.lang.Boolean and java.lang.String are in module java.base of loader 'bootstrap')', forwarding to the next one
This could be due to the map containing boolean values on some keys as seen in the example above.
Also, updating the variable on which I loop inside the loop, even if it’ll work, doesn’t seem like a good idea overall. Is there a more Gatling way to do such a thing?
This is all part of a purchasing flow where I want to ask for fewer products if the initial number was too high (i.e., not enough products found or not allowed to purchase as many).
Thanks a lot in advance for the help and any information.
Regards,
George