SaveAs with println

I’m trying to find the contents of elements in my page and print them out to the console.

This is what I’ve tried (I’m using Gatling 2 by the way) based on other posts I’ve seen here. I’m just testing this on a simple element in this example to try to get it working:

.exec(session => {

I am getting a type mismatch error. I have also tried the session variable like this: println(session(tasks))

Which says that tasks isn’t a value…

Any help on finding out how to print the contents of elements out to the console would be very much appreciated.

Thank you,

–Matt Royer

type mismatch error

Which one? Where?

Ho, yes.

See Session manipulation:

The signature of this kind of exec is exec(Session => Session) (actually Session => Validation[Session] but the first form will work too), so you need to return a session, even if it’s the original one.

exec { session =>

Great! Thank you! I got that working.

I do have another question though. Here is the code I am actually using:


session(“tasks”) returns an Attribute object that wraps the actual value.

Ue one of the extract methods ( in order to get the ArrayBuffer in your case, then you can get a value like this: buffer(rank)

Gatling EL:


I’m using the EL to select the element I want with “tasks(0)”.

But I don’t understand the “extract method” in that link. Do I need to transform the “tasks” into an array buffer or something with:


I guess I don’t get how to get at the underlying values.

I'm using the EL to select the element I want with "tasks(0)".

But I don't understand the "extract method" in that link.

"extract method": as, asOption, or validate

Do I need to transform the "tasks" into an array buffer or something with:



Don't try to mix EL and programming approaches, they are mutually exclusive.

Thanks again for helping me. Sorry I’m not catching on quickly.

I changed my code to your suggestion:

ArrayBuffer is not automatically imported. Just use Seq instead.

Ahhh… Thank you so much! That’s exactly what I needed.

Thanks again,



I’m new to Scala/Gatling and was trying to print a session variable. I’m using Gatling 2.2.2. I imported ArrayBuffer before trying the belo.


I was gettting the error " type mismatch;
found : Int(1)
required: io.gatling.commons.NotNothing[scala.collection.mutable.ArrayBuffer[String]]"

Can you please help?


For some dark reasons I won’t elaborate (implicit parameter), don’t use a one-liner.

val abcd = session(“abcd”).as[ArrayBuffer[String]]


Thanks Stephane,

There’s no compilation error now, however, there’s a run time error now. But never mind, I managed to display it with session.get(“abcd”).asOption[String]


Hi Stéphane

I wish to use below randomValue to generate email Ids for registration.

val randomSeq = exec(session => {
session.set(“randomValue”,ThreadLocalRandom.current.nextInt(2000).toString + System.currentTimeMillis.toString )

val RegisterFlow =
.exec { session =>
println(" Random User → " + session.get(“randomValue”).asOption[Int])

.headers(headers_2) .body(StringBody("""{“preferredName”:“perftest_${randomValue}”,“familyName”:“perftest_${randomValue}”,“email”:“perftest_${randomValue}”,“password”:“Password1”}""")).asJSON

I am getting output as none. Please let me know how to print this value and use it another request.