Using Session in Function-Based Feeders

Hi,

I’m trying to test an endpoint where the first “user’s” POST body looks something like this:

[
   {
      "foo":1,
      "bar":"<random value>"
   },
   {
      "foo":2,
      "bar":"<random value>"
   }
]

and the next “user” looks like this:

[
   {
      "foo":1,
      "bar":"<random value>"
   },
   {
      "foo":2,
      "bar":"<random value>"
   }
]

and so on.

Currently, I’ve been using a supplier-based feeder to generate something like this:

[
   {
      "foo":${foo(0)},
      "bar":"<random value>"
   },
   {
      "foo":${foo(1)},
      "bar":"<random value>"
   }
]

then using a method passed to StringBody(Function<Session, String>) to pull out that shell from the session, generate a value for foo(0) and foo(1) using session.userId(), and use Apache’s StringSubstitutor to substitute those values. Ideally, I’d like to just set a session variable to hold the values of foo and use Gatling EL, but I don’t think that works since the whole shell is already saved as a session variable and I don’t think Gatling EL evaluates more than one level deep.

Is there a better way to be doing this?

I think you are looking for pebble templates with PebbleFileBody.

Cheers!