Store result from ArrayBuffer in session

Il want to do something like :

.get("/rest/historisation/findUserHistory")
.check(jsonPath("$…historique-recherche[*].id-variante").findAll.saveAs(“IDS_VAR_HISTO”))
)
.exec(session => {
session.set(“ID_VAR”, “${IDS_VAR_HISTO.random}”)
})

But when i’m accessing the value of my session variable i got : “${IDS_VAR_HISTO.random}”

How can i store the random result in an attribute of my session ?

I want to put the result from differents chains and not only from “IDS_VAR_HISTO” but from “IDS_VAR_HISTO”, “IDS_VAR_CNIT”, etc.
This aims to get always my id from "${ID_VAR} independently of the chain.

Thank you in advance for helping me.

Which version of Gatling are you using ?

I’m on Gatling 2.0.0-M3a

Hi,

.exec(session => {
session.set(“ID_VAR”, “${IDS_VAR_HISTO.random}”)
})

The red expression is a regular String, it won’t be interpreted as an EL-Expression.
Why do you do this in an extra step ?

If you really need to store that in the session, I would recommand to do something like that :

import java.util.concurrent.ThreadLocalRandom
import io.gatling.core.validation.Success

.exec(http(“TODO”).get("/rest/historisation/findUserHistory")
.check(jsonPath("$…historique-recherche[*].id-variante").ofType[Long].findAll.saveAs(“IDS_VAR_HISTO”))
)
.exec(session => {
session(“IDS_VAR_HISTO”).validate[Seq[Long]] match {
case Success(ids) =>
val index = ThreadLocalRandom.current.nextInt(ids.size)
session.set(“ID_VAR”, ids(index))
case _ => session
}
})

Does it help ?

Regards
Nicolas