how to assign response value to next request

Hi All,

In below code, i am capturing response in UserId variable. I am failing to pass this UserId variable in next request, it is throwing errors.

.exec(http(“Create USer”)
.post(""“Urlxxxx”"")
.body(StringBody("""{“email”:“sample@gmail.com”}"""))
.check(headerRegex(“Location”, “(.*)”).saveAs(“userId”))) // capturing dynamic value in UserId variable

// System.out.println("UserID: " + userId+ “\n”) // i tried to print like this, no use

//exec(
(s:Session) => println(s.getAttribute("
userId")) // tried this also, but no use to conform what i am getting in UserId
)

/**************** next request*******************************/

val scn1 = scenario(“Identity”)
.exec(http(“request_0”)
.post("""/urlxxxx""")
.body(StringBody("""{
“username”:“anitha156”,
“password”:“anitha56”,
“userId”:"${userId}", // passing that userid in this request.
}""")))

}

Can anyone please help me on this?

Thanks in advance…

Regards,
Anitha.

Except if you disabled followRedirect, you’ll never see Location headers, so your headerRegex won’t work.
Use currentLocationRegex instead. http://gatling.io/docs/2.0.1/http/http_check.html?highlight=currentlocation#page-location

Hi Stephane,

Thank you for your reply…

When i used ".check(currentLocationheaderRegex(“Location”, “(.*)”).saveAs(“userId”)))"i got below error message.

[ERROR] i.g.a.ZincCompiler$ - C:\Users\anitha\Desktop\gatling-chart
s-highcharts-2.0.1\user-files\simulations\CreateUser.scala:128: too many arg
uments for method apply: (v1: io.gatling.core.session.Session => io.gatling.core
.validation.Validation[String])io.gatling.http.check.url.CurrentLocationRegexChe
ckBuilder[String] with io.gatling.http.check.url.CurrentLocationRegexOfType in t
rait Function1

In documentation i saw below syntax , if i use this , where should I save my userId value?

__currentLocationRegex("http://foo.com/bar?(.*)=(.*)").ofType[(String, String)]__

And one more point here, i am trying to pass this value to next request in same script, like ,"{userId}", But i am getting "No attribute name userId is found.

So, can you please help me on how to pass this value to next request?

Thanks for your help in advance.
Regards,
Anitha. 

Please properly read the documentation.

__currentLocationRegex("[http://foo.com/bar?(.*)=(.*)](http://foo.com/bar?(.*)=(.*))")__

Not currentLocationheaderRegex("****Location", “(.*)”)

I found answer for the not answered part of the question (how to capture more than one regex group and pass it to further code) in another group: https://groups.google.com/d/msg/gatling/yvGxQKkKzsA/O8bQ6JJcoF0J . Examples on how to use Tuples in Scalal: http://alvinalexander.com/scala/scala-tuple-examples-syntax. The way described there should be already implemented for Gatling (https://github.com/gatling/gatling/issues/1991), but I was not able to make it work with Gatling 2.2.2.
I am posting reply to this old group for future users looking for a solution who might find it useful.