Not able to set session attribute

Hi,

I am trying to execute a sequence of chains and setting a session attribute in between somewhere. The problem is this variable is not getting set correctly and I get an error saying No attribute named ‘toUpdate’ is defined. Here is the code

No attribute named ‘toUpdate’ is defined

scenario(“Test”).exec(postChain("/orders", Helper.generateRequestBody(order)))
.exec(getChain("/orders", “${id}”))
.exec((session: Session) => {

val jsonString = session(“object”).as[String]
val pojo = Helper.generatePojo(jsonString, classOf[Order]).asInstanceOf[Order]
pojo.setName(pojo.getName + “Updated”)
val toUpdate = Helper.generateRequestBody(pojo)
session.set(“toUpdate”, toUpdate)
session
}
)
.exec(putChain("/orders", “${id}”, “${toUpdate}”))

I want to do the chains in this sequence POST → GET → UPDATE → DELETE and need the toUpdate attribute for the PUT request . Any suggestions?

Thanks,
Akash

Hi Akash,

As stated in the documentation(http://gatling.io/docs/2.1.6/session/session_api.html#setting-attributes), Sessions are immutable and session.set(…) returns the modified session, which is discarded in your case.
Simply remove the last “session” in your exec block and it’ll work.

Cheers,

Pierre

Works now ! Thanks a lot Pierre !