Hey me again. I need to maintain a session cookie across a user's
requests. I think the easiest way would be to extract the SET-COOKIE
header from my first request, save that to the session, and then
inject that into each subsequent request. Unfortunately I'm having
trouble with the first step. Here is what I'm trying:
val resourceGet = chain.exec(
I adapted this from the "Saving values" section here:
This doesn't work and i've tried other combinations like removing the
'find' but all throw errors something like:
error: value find is not a member of
So my first question would be how can I extract a header and save it
to a session variable?
Also from looking at the code it seems like headers expect 1 value for
a specific header name. For SET-COOKIE headers in particular it is
common to have multiple with the same name. Is there any way in
Gatling to extract the one I want? I would need to find the
SET-COOKIE header with a value like
"JSESSIONID=E2F98A8757AC931AEE67AAE5E3B769DC; Path=/" and then extract
the token from that.
Gatling already does that for you and automatically stores cookies in the session and pass them to the next requests.
2012/2/2 Chris Carrier <firstname.lastname@example.org>
Cookies are transferred from one request to another automatically!
You do not have to worry about them. If one is received, it will be sent in the subsequent requests
i have a problem with this, when gatling automatically adds the cookie it looks like:
What does your scenario look like?
Could you for example provide a gist?
2012/2/3 mediamana <email@example.com>
i’ve resolved my problem it was a rule in mod_security that doesn’t like $Path="/Admin" even if it is a valid part for a cookie
sorry for the inconvenience
I'm not getting my cookie set automagically so maybe you can help me
understand how the cookie handling works. Will the cookie be applied
to every request after it is set? Will it apply across different
chains as long as they're in the same scenario? Here's what i'm
trying to do
val chain1 = //some http call that will return multiple Set-Cookie headers
val chain2 = //a bunch of static content requests that don't require
the cookie is set
val chain3 = //another http cal that needs the cookie from chain1
val scn = scenario("...").insertChain(chain1).insertChain(chain2).insertChain(chain3)
But on the chain3 request it doesn't seem like the cookie is being set
in the request. The cookie should be set for all requests for a
particular user right? Is there any way for me to debug what gatling
is actually sending? Can I somehow config Gatling to print the full
request in the simulation.log? Or can I println session attributes
but so far I haven't been able to find what attribute the cookie is
I imagine I'm doing something wrong but I'm not sure the best way to
debug what Gatling thinks should be sent for each request.
OK I may have found the issue. I used a debug chain like this to
print out the Session attributes:
val debugChain = chain.exec( (s: Session) => println( s.data) )
When I do this right after chain1 (that sets the JSESSIONID cookie) I see:
gatling.http.cookies -> Map(JSESSIONID -> Cookie: domain=null,
name=JSESSIONID, value=9862CA687E7D7F8885EFC4416B29CCDB, path=/,
But after chain2 I print it again and see:
gatling.http.cookies -> Map(JSESSIONID -> Cookie:
domain=.facebook.com, name=JSESSIONID, value=deleted, path=/,
Is the 'value=deleted' something that Gatling is doing? Is there any
way to tell it to retain the cookies over the life of a user's
session? I figure as a workaround I can manually extract the
'gatling.http.cookies' from the session and grab the cookie value and
then use it wherever I want. Gonna give that a shot right now.
Actually, Cookies are really passed through the session. The thing is that we map them by their name.
In your case, it seems that both cookies are named jsessionid, which leads to an overriding of the first one by the second.
Maybe we should map them by both name and domain, so that cookies will never be overridden by mistake.
Thanks for pointing it out Chris!
I opened the following issue and will start fixing it today :
2012/2/4 Romain Sertelon <firstname.lastname@example.org>
Great this will be a big help for us.
I think I’ll have something ready for friday (sadly not much time until then) and I’ll upload a 1.1 snapshot somewhere then.
Thanks for your patience,
2012/2/7 Chris Carrier <email@example.com>
I’ve uploaded a snapshot of the next 1.1.0 release, with a fix for cookie handling.
I’m quite in a rush and barely had the time to test the fix…
Could you please let me know if it indeed solves your problem?
Warning : Check DSL change :
- eq becomes is
- neq becomes not
Don’t forget to modify your existing scenarios.
2012/2/7 Stéphane Landelle <firstname.lastname@example.org>
I'll do a quick code review and test it out and let you know if I see anything.
Thanks for the quick turn around!
So far this fix seems to be working great. Thanks again!
Thanks for your feed back and have fun,
2012/2/9 Chris Carrier <email@example.com>