Extract Cookie Value

I wondered if there was a cleaner way to extract a cookie value than this?

.exec { session =>
      import org.asynchttpclient.uri.Uri
      import io.gatling.http.cookie.CookieJar
        session("gatling.http.cookies").as[CookieJar].get(Uri.create("https://xxx.com")).find(_.getName == "xxxxx").get.getValue



No. And we probably never will.
I fail to see a valid use case for getting cookies while Gatling automatically capture them and send them back.

People trying to get their hands on the cookies are typically doing so to try to bypass the authentication layer in the system under test.
IMO, this is a testability issue, if the authentication layer as to be bypassed during the load tests, it should be possible to disable/mock it instead of hacking the load test tool.

The use case is that a cookie value is required in the body of a subsequent post… I also need to do this.

I had to do something similar in a test environment where a captcha value was being passed back in a set-cookie header… in my case it was easy enough to get it from that header rather than from the CookieJar:

.check(headerRegex(“Set-Cookie”, “captchaValue=(.*?);”).find.saveAs(“captchaValue”))

That said, I do see some merit to being able to manipulate cookies - for example, an app that I needed to script against recently required a specific cookie to be added before it could be used in the functional test environment. Not sure of the reasons for that but that’s how it was.

So, without being able to add that cookie, I wouldn’t have been able to replay my script against the app.

Different use case. Gatling provides an API for adding cookies: http://gatling.io/docs/2.2.2/http/http_helpers.html#adding-a-cookie

Thanks Stéphane, that would have been useful for that particular use case.

As I remember, I was running simulations against the live environment and needed authentication cookies so as not to affect sign-in for real users.