How to supply parameter values to contents of a JSON file

Say I have a JSON request body file query.json with the following contents:

{
  "user_id": "#{userId}",
  "query": "SELECT * FROM example;"
}

I am using the body in a scenario like this:

  private final ScenarioBuilder scenario =
    scenario("Load test")
      .exec(
        http("Query")
          .post("<API>")
          .headers(ImmutableMap.of("content-type", "application/json"))
          .body(RawFileBody("bodies/query.json")));

I now wish to use Gatling functionality to supply the user ID but keep the query constant. How should I do that? I have looked into Gatling EL and I am aware that “Only Gatling DSL methods will interpolate Gatling EL Strings. You can’t use Gatling EL in your own methods or functions.”. I was unable to extract a working example from the docs, hence my question here.

Hi @GIGATeun,

Do you know about ElFileBody (to put instead your RawFileBody)

Hope it helps.

Cheers!

Yes, ElFileBody appears to be exactly what I need. However, I am not sure on how to use it. How do we set our parameter userId?

Please check our free online courses: https://academy.gatling.io/

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.