Using a value set by a saveAs call as a variable inside a session call


I’ve gone through various examples and I have not been able to find an answer that seems to solve my problem. In a login call I’m using a regex to save the nonce value. I then want to access that as a variable for generating a MD5 response using the nonce as part of the constructed string.

What I have so far is

.exec(http("login") .post("/api/call") .check(headerRegex("X-Authenticate","""nonce="([^"]+)""").saveAs("nonce")) ) .exec(session=> { var nonce="${nonce}" })

Obviously there is more to this but this is effectively what I want to achieve. The above generates a string that is ${nonce}, so that doesn’t work.

However I have also tried all of the following

var nonce="%s".format(nonce) var nonce=session.get("nonce") var nonce=session.getAttribute("nonce")

None of these work either and the last one generates a compiler error. So how can I access a value set by a saveAs call as a variable? I am coming from a JMeter background and so currently looking at using gatling as an alternative.

Kind regards,

Got this working thanks to!topic/gatling/4xw5GRbNxDU

var nonce=session("nonce").as[String]

Actually, reading the documentation should be more effective than randomly searching the mailing list archive :slight_smile: