Need help with EL session variables (newbie question)

I have the following code:

val feeder = csv(“uri.csv”).random

val scn = scenario(“Post query”)

.repeat(2) {

feed(feeder)

.exec(session => {

println("Session*${code} "+session(“code”).as[String])

session

})

}

When I dump out the string, I get the following output: Session*${code} 211122. Why is the EL variable ${code} not being evaluated properly – is it that EL variables are only interpreted by gatling functions?

The deeper reason behind the toy example above is that I am trying to inject a variable from a feeder into a POST method with JSON parameter. As the JSON is huge, I’m trying to do the following (build_query is a function which takes a string and plops it at the right place):

exec(
http(“post code”)

.post("/myEndpoint")
.body(StringBody(build_query(${code}))

)

and just as in the simple case above, ${code} seems to not be bound (but unlike the toy example I don’t have a session parameter in scope either…

Any tips/pointers greatly appreciated…

Gatling version is 2.0.0-M3

Hi Yana,

Have you tried to use triple quotes arount the EL param ?

println( “”" Session*${code} “”"+session(“code”).as[String])

Regards,

GerraldG

Hi,

I’ve added an explanation in the wiki:
https://github.com/excilys/gatling/wiki/Session#wiki-el

Cheers,

Stéphane