Hi; apologies if I’ve missed how to do this in the docs.
I have a json response from my first API call; and I would like to randomly select one of the objects to use for the rest of the test.
Perhaps there is a much simpler way to tackle this; but I’ve come up with
Calls the first API
Save all of the response to the session
Save the length of the response’s array to the session
Reads the length of the Array
This step is not compiling, but the goal would be: Reprocess the response through jmesPath
and select an object by index.
The compile error is: [error] found : String [error] required: io.gatling.core.check.jmespath.JmesPaths
If this is a reasonable direction; how can I re-create JmesPaths
?
.exec(http("datasets")
.get("/api/datasets")
.headers(headers_0("#{api_key}"))
.check(
status.gte(200),
status.lte(299),
jmesPath("[]").saveAs("all_may_datasets"),
jmesPath("[] | length(@)").saveAs("all_may_datasets_length")
))
.pause(1)
.exec(http("Open_dataset")
.get(session => {
val all_may_datasets_length = session("all_may_datasets_length").as[Int]
println(s"***all_may_datasets_length: ${all_may_datasets_length}")
jmesPath(s"[${all_may_datasets_length-1}]")(session("all_may_datasets").as[String])
s"/"
})
)
Thanks