HTTP Helpers

Add and retrieve manually a cookie with Gatling

Dealing with Cookies

Cookie support is enabled by default and then Gatling handles Cookies transparently, just like a browser would.

However, some use cases require a more fine grain control.

One might want to manually add or compute a cookie:

exec(addCookie(Cookie("name", "value")))

Cookie can also take more optional parameters:

Cookie(name: String, value: Expression[String])
  .withDomain(domain: String)
  .withPath(path: String)
  .withMaxAge(maxAge: Int)
  .withSecure(secure: Boolean)

domain is optional, defaulting to base url domain

path is optional, defaulting to “/”

maxAge is optional, defaulting to Long.MinValue

secure is optional, defaulting to false

Get the cookie value and put it in the session

exec(getCookieValue(CookieKey("name")))

CookieKey can also take more optional parameters:

CookieKey(name: String)
  .withDomain(domain: String)
  .withPath(path: String)
  .withSecure(secure: Boolean)
  .saveAs(key: String)

domain is optional, defaulting to base url domain

path is optional, defaulting to “/”

secure is optional, defaulting to false, means you only want secured cookies

saveAs is optional, defaulting to name param

Flushing Session Cookies

One might want to simulate closing a browser, so Session cookies are dropped but permanent cookies are still there:

exec(flushSessionCookies)

Flushing All Cookies

One might want to flush the whole CookieJar:

exec(flushCookieJar)

Dealing with Caching

Flushing the Cache

One might want to flush the whole HTTP cache (for the virtual user):

exec(flushHttpCache)

Edit this page on GitHub