session.set() and string interpolation

I’m getting an error with the following code. I’m trying to use session.set() so I can capture certain things in the sequence I’m saving and using them elsewhere in my script.

.exec(http(“Get Tasks”)
.get("/" + site + “//Main/portal/lists/index.cfm?list=tasks”)
.check(css("#column_packet_nm.listPageTableCell > a", “href”).findAll.saveAs(“tasks”)))
.exec { session =>
val myTaskID = session(“tasks”).asSeq[String].split(""",""")(1)
session.set(“test”, myTaskID)
session
}
.pause(4)
.exec(http("${test}")
.get("/" + site + “/Main/portal/lists/index.cfm?list=tasks”))

I am getting the following error from this script. There is something I’m missing with session.set(). I’m sure it’s something easy.:

[ERROR] i.g.h.a.HttpRequestAction - No attribute named ‘test’ is defined

The session is an immutable object, so, you are not returning the updated version.

This should work :

.exec { session =>
val myTaskID = session(“tasks”).asSeq[String].split(""",""")(1)
session.set(“test”, myTaskID)
}

Wow. Taking out the returned session worked!

But what if I want multiple things that I set in the session? Can I do that?

I just tried using the session.set() twice and it wouldn’t find the first one, but will find the second one I set.

session.set(“foo”, “bar”).set(“baz”, “qix”)
or
session.setAll(“foo” → “bar”, “baz” → “qix”)

Awesome!!!

Thank you so much! This just changed the outcome of my whole project. I am forever grateful.

–Matt Royer

You’re very welcome.
Have fun!