1
votes

In my Gatling scenario, a value is stored in the session for a user. Later in the same scenario, feed is called and passed a custom feeder. The custom feeder needs to generate its next value using the stored value in the session.

val MyScenario = scenario("ScenerioName")
  .repeat(10, "repetition") {
    exitBlockOnFail {
      group("WorkflowGroupName") {
        exec(session => {
            // SETTING A VALUE INTO THE USER'S SESSION
            session.set("sessionVariable", 99)  // value that is stored changes for every run of the workflow (99 just for example purposes)
        })
        // CUSTOM FEEDER THAT GENERATES ITS NEXT VALUE USING THE SESSION VARIABLE 'sessionVariable' STORED ABOVE
        .feed(myFeeder)
        .group("RequestGroup1") {
          exec(httpPost1)
        }
      }
    }
  }

val myFeeder = Iterator.continually(Map("jsonFileValue" -> {

  // WANT TO RETRIEVE VALUE OF 'sessionVariable' STORED IN THE SESSION
  val returnValue = /* logic that generates its value based on value of 'sessionVariable' retrieved */
  returnValue

}
))

val httpPost1 = http("Request1")
  .post("http://IPAddress/service.svc")
  .headers(httpHeaders)
  .body(ELFileBody("MyJsonFile.json"))
  .check(status.is(200))
val httpHeaders = Map(
  "Content-Type" -> "application/json; charset=UTF-8",
  "X-Pod" -> ""
)

How can I pass this stored session value to the feeder or have the feeder retrieve this value from the session?

1

1 Answers

1
votes

As the documentation states:

Sometimes, you could want to filter the injected data depending on some information from the Session.

Feeder can’t achieve this as it’s just an Iterator, so it’s unaware of the context.

If your values are independent of the tests you run, maybe a good way can be to generate a csv before you run your tests and then feed this csv to your tests.