Search code examples
scalagatlingscala-gatling

How to set a cookie for a Gatling scenario


I have the following code. The problem is that the cookie is not being set for the requests that follow.

I would like to set a single cookie that is used by all of the subsequent requests (including the ajaxRequests).

val get = scenario("Page")
  .feed(myfeed)
  .group("Home Page") {
    exec(session => setSessionVariables(session))
      .exec(addCookie(Cookie("mycookie", "true").withDomain(baseurl)))
      .exec(http("Home Page")
        .get(pageUrl)
        .resources(
          ajaxRequest01,
          ajaxRequest02
        ))
  }

Solution

  • My best guess is that the problem here is that the baseUrl you are using includes the protocol - e.g. https://www.google.com/ etc.

    From my experimentation with this feature, this won't work, the cookie needs to be passed just the domain - e.g. www.google.com or just .google.com if you want it to apply across subdomains.