Search code examples
scalatestingload

Gatling 2 dynamic queryParam on each request


I am trying to run a load test using Gatling 2. I need to generate one of the query parameters dynamically on each request.

My scenario is defined like this:

val scn = scenario("Load Test Scenario")
        .exec(
            http("Test API")
            .post(url)
              .body(StringBody("Some XML"))
              .queryParam("x", DigestUtils.md5Hex(generateX().getBytes("UTF-8")))
          )

def generateX() : String = {
    // generate random string and return
}

This only calls generateX once and uses the result in each request. Is there anyway to have the generateX call on every request?


Solution

  • You have to pass a function, not a value. See Gatling documentation about Expression.

    Here, you can just discard the session input parameter as you don't use it, so you can simply write:

    .queryParam("x", _ => DigestUtils.md5Hex(generateX().getBytes("UTF-8")))