Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 252
slarge Avatar asked Dec 25 '22 02:12

slarge


1 Answers

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")))
like image 100
Stephane Landelle Avatar answered Jan 08 '23 11:01

Stephane Landelle