scalagatlingscala-gatling

Get a value from a CSV Gatling feeder to construct a request


I have a simple scenario, When I want to read the endpoints from the csv file in a circular. The request will be constructed based on the endpoint and same endpoint i need to pass to a function to generate a token and include in the headers.

val scn = scenario("Test").exitBlockOnFail{
    feed(csvFeeder)
    .group("Multiple tests") {
      exec(http("Multiple tests")
        .get("${endpoint}"+request_params)
        .headers(utils.HeaderUtils.create_header("${endpoint}").toMap)
        .check(status.is(200)))
    }.pause(1.seconds)
  }

The problem is, in the .get the ${endpoint} is replaced with actual value from the csv. But same value tried to pass to a fucntion under .headers the actual is not replaced. Its coming as string of ${endpoint} instead of the actual value from csv.

Can you please suggest here

Thanks


Solution

  • First, the ${} syntax has been deprecated for years and was finally dropped last week as of Gatling 3.11. You're supposed to use #{} nowadays.

    Then, the Gatling Expression Language is only interpreted by the methods of the Gatling SDK, not by your own custom code. If you want to fetch data from the Session in your own custom code, you must use the Session API, typically in functions.