Gatling version: 3.11.5 (must be up to date) Gatling flavor: java kotlin scala javascript typescript Gatling build tool: maven gradle sbt bundle npm
I read the guidelines and how to ask a question topics.
I provided a SSCCE (or at least, all information to help the community understand my topic)
I copied output I observe, and explain what I think should be.
I have a JSON object with a list of fruits, each with its own name, color, and quantity. I want to send each fruit as its own separate request to a server using Gatling. The request should be a POST request with the fruit data as the request body. How can I achieve this in Gatling?
without revealing the actual code, but I want something along the lines of this, disclaimer i am new to gatling and scala, and this is a one-off task for me that I need to do so please be lenient on me for not understanding the core principles of the “gatling way”.
So, I tried doing it in my Simulation class, which may not be ideal but it’s where they want it.
.exec(Basket.checkstats)
.exec { session =>
val fruitBasketsJson = session("fruitBaskets").asOption[JsArray]
val orchardId = session("orchardId").as[String]
if (fruitBasketsJson.isDefined) {
val fruitBaskets = fruitBasketsJson.get.as[Seq[FruitBasket]]
val fruitSalad = FruitCreator.createFruitSalad(fruitBaskets, orchardId)
(fruitSalad \ "fruit").as[Seq[JsValue]].foreach { fruit =>
exec { session =>
val fruitSmoothie = Json.stringify(fruit)
println(fruitSmoothie)
session.set("fruitSmoothie", fruitSmoothie)
println("Saved fruit smoothie in session")
session
}
.exec(Basket.submitFruits)
.exec { session =>
val inventoryResponse = session("inventoryResponse").as[String]
println("Inventory response is: " + inventoryResponse)
session
}
}
}
session
}
The submitFruits function resides in another object class that is a post but its response debug statements do not print, even though the simulation completes without errors
Unfortunately, it’s not static data. There is code that processes this and produces the final object for me, in a way similar to what is shown. And the painful part is this is the last step, I have the data, and can loop over it in the form i want as a payload just fine but I cannot for the life of me figure out how to send all of them via a post.