Add Cookie and getCookie don't seem to work

Hello,

I am try to do a post request with a Cookie that I create. Here is the snippet:

.exec(session => {
addCookie(Cookie(“foo”,session(“bar”).as[String]))
.withDomain(“XXXXXX”)
.withPath("/"))
session
})
.exec(getCookieValue(CookieKey(“foo”)))

‘getCookie-4’ failed to execute: No CookieJar in session

It seems that there is no Cookie jar in session and I am not sure how to resolve this.

Please read the documentation, you’re not using Gatling DSL components properly.

Warning

Gatling DSL components are immutable ActionBuilder(s) that have to be chained altogether and are only built once on startup. The results is a workflow chain of Action(s). These builders don’t do anything by themselves, they don’t trigger any side effect, they are just definitions. As a result, creating such DSL components at runtime in functions is completely meaningless. If you want conditional paths in your execution flow, use the proper DSL components (doIf, randomSwitch, etc)

What you want to do is exec(addCookie(Cookie(“foo”,"${bar}")))