Cookies not included in request

I’ve been trying to add cookies to my requests using addCookie action but it seems that Gatling is ignoring that.

I requested Gatling to print cookies sent in request:

.extraInfoExtractor(extraInfo => List(extraInfo.request.getCookies))

An entry from simulation.log shows that cookies are not sent in the request (the last element in the array, a collection, is empty):

Try 1022245772750469446-0 REQUEST search 1440576287486 1440576287662 1440576287698 1440576287699 KO status.find.in(200,304,201,202,203,204,205,206,207,208,209), but actually found 302 []

I also verified with proxy (Charles) to sniff the traffic coming from Gatling and it also was not seeing the cookie included, which suggests that it’s not problem with printing but rather that Gatling is not including cookies in the requests.

Gatling is also printing cookies included in the cookstore but mine (“SOMETHING”) is not there:

Session:
Session(Try,7988202680681807492-0,Map(gatling.http.cookies → CookieJar(Map(CookieKey(pref,google.com,/) → StoredCookie(PREF=ID=1111111111111111:FF=0:TM=1440577318:LM=1440577318:V=1:S=v_XjjA5ACrL5BPAY; domain=.google.com; path=/; expires=1451577737000,false,true,1440577318345), CookieKey(nid,google.com,/) → StoredCookie(NID=70=g5FwbH3OqSJreNSfMBNVJlV5BdV4rYD1ctKsNaqAbmkmPiqdGvMIwiZUR8yu67GwKT1HntP3vxFTFNjgzAZDV69isOQi4EH_uv8-Ci3_Q3wK3D9uGX2jWzvsJkXvOnw_; domain=.google.com; path=/; expires=1456388518000; HTTPOnly,false,true,1440577318346))), gatling.http.referer → http://www.google.com/?q=x),1440577318230,0,KO,List(),)

What am I doing wrong? I’m using Gatling 2.1.6. Below is my code to reproduce the problem.

Thank you,
Maciej

class Bug extends Simulation {

val httpConf = http
.baseURL(“http://www.google.com”)
.disableFollowRedirect
.extraInfoExtractor(extraInfo => List(extraInfo.request.getCookies))
.proxy(Proxy(“localhost”, 8888))

object NewPulsarSession {
val scn = scenario(“Try”)
.exec(addCookie(Cookie(“SOMETHING”, “58948498494894894894”)
.withDomain(“www.google.com”)
.withPath("/")
))
.exec(http(“search”)
.get("/")
.queryParam(“q”, “x”)
)
}

setUp(
NewPulsarSession.scn.inject(rampUsers(1) over (10 seconds))
)
.protocols(httpConf)

}

Hi Maciej,

Have you first checked the release notes for a possible bug that might have already been fixed in a more recent version? :slight_smile:

Cheers,

Thanks. Upgrading to 2.1.7 helped.

Hi Stephane,

I am also trying to add cookies in request and not able to see that in request.
I am Gatling highcharts version 2.2.3.
Below is my code snippet for your reference:

scenario.exec( session =>

{

println("token recieved------->> "+authCache.get( Constant.defaultUserName ))

addCookie(Cookie(“usrtkn”,authCache.get( Constant.defaultUserName )).withDomain("/").withMaxAge(Integer.MAX_VALUE))

session

})

Not sure what is wrong here.

Thanks
Richhpal

Have you tried like this?

scenario.exec(addCookie(Cookie(“usrtkn”,authCache.get(Constant.defaultUserName )).withDomain("/").withMaxAge(Integer.MAX_VALUE)))
.exec(next request here)

Yes, I tried this too.

.exec(addCookie(Cookie(“usrtkn”,tokenCache.get( Constant.defaultUserName )).withDomain("/").withMaxAge(Integer.MAX_VALUE) ))

But still not luck.

Thanks

Richhpal

Haven’t tried but I imagine you need either: the actual domain (instead of ‘/’), or just drop the withDomain.