Extract Cookie Value

846 views
Skip to first unread message

adrian...@hushmail.com

unread,
Sep 16, 2016, 10:28:22 AM9/16/16
to Gatling User Group
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
println(
session("gatling.http.cookies").as[CookieJar].get(Uri.create("https://xxx.com")).find(_.getName == "xxxxx").get.getValue
)
session
}

Thanks

Aidy

Stéphane LANDELLE

unread,
Sep 16, 2016, 1:36:56 PM9/16/16
to gat...@googlegroups.com
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.

Stéphane Landelle
GatlingCorp CEO



--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dominic Le Bredonchel

unread,
Sep 23, 2016, 12:44:11 PM9/23/16
to Gatling User Group
The use case is that a cookie value is required in the body of a subsequent post...  I also need to do this.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.

Barry Perez

unread,
Sep 29, 2016, 11:45:11 AM9/29/16
to Gatling User Group


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.

Stéphane LANDELLE

unread,
Sep 29, 2016, 11:53:15 AM9/29/16
to gat...@googlegroups.com
Different use case. Gatling provides an API for adding cookies: http://gatling.io/docs/2.2.2/http/http_helpers.html#adding-a-cookie

Stéphane Landelle
GatlingCorp CEO


To unsubscribe from this group and stop receiving emails from it, send an email to gatling+unsubscribe@googlegroups.com.

Barry Perez

unread,
Sep 29, 2016, 12:07:03 PM9/29/16
to Gatling User Group

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

adrian...@hushmail.com

unread,
Sep 29, 2016, 12:42:12 PM9/29/16
to gat...@googlegroups.com
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.

On 29/09/2016 at 5:07 PM, "Barry Perez" <barry...@gmail.com> wrote:
>
>Thanks Stéphane, that would have been useful for that particular
>use case.
>
>On Thursday, 29 September 2016 16:53:15 UTC+1, Stéphane Landelle
>wrote:
>>
>> Different use case. Gatling provides an API for adding cookies:
>> http://gatling.io/docs/2.2.2/http/http_helpers.html#adding-a-
>cookie
>>
>> *Stéphane Landelle*
>> *GatlingCorp CEO*
>> slan...@gatling.io <javascript:>
>>>>> *Stéphane Landelle*
>>>>> *GatlingCorp CEO*
>>>>> slan...@gatling.io
>>> email to gatling+u...@googlegroups.com <javascript:>.
Reply all
Reply to author
Forward
0 new messages