Madhuri R
Madhuri R

Reputation: 21

How to append to a list variable in session

I'm new to Gatling and struggling with a basic task. I'm setting up two scenarios. First scenario: I have a list of values, I want to make a request for each value, append the response of the request to a result list. I want to use this result list as a feeder to next scenario.

This is what I have so far,

val firstScn = scenario("Getting the name feeder")
  .feed(idFeeder)
  .exec(http("Get user name")
    .post(uri)
    .body(StringBody("""{ "userId":  """" + "${id}").asJson
    .check(jsonPath("$.username").exists.saveAs("name")))
  .exec(session => {
    var username = session("name").as[String]
    var names = session("allNames").validate[List[String]].onFailure(null)
    names +: username
    session.set("allNames", names)
    println(allNames)
    session
  })

I want to use the allNames as feeder to my next scenario.

However, I'm getting a NPE while appending to a list. I don't know how to initialize the list "allNames" in the session.

Also, further how do I convert this list of strings into a feeder for the next scenario.

Upvotes: 2

Views: 823

Answers (1)

James Warr
James Warr

Reputation: 2604

I think the preferred way to do this is to write your names out to a csv file and then have your subsequent scenario consume that via a feeder

Upvotes: 1

Related Questions