0

I have a question about Gatling.
I need to get the following response:

[
{
"id": 1,
"name": "Jack"
},
{
"id": 2,
"name": "John"
} 
]

grab those ids, iterate over them and make a new request for each of them. So far I have this:

.exec(
            http("Image list")
                .get("/api/img")
                .headers(headers_0)
                .check(
                    jsonPath("$..id").findAll.saveAs("imgs")
                )
        )

It successfuly saves ids to "imgs" which is session variable but I am not able to iterate over them or process it at all.

How can I process it? I am new to Gatling and Scala so I have no idea how to approach this.
Please help.

malutki5200
  • 1,092
  • 7
  • 15

2 Answers2

1

You can treat the imgs session variable as a Scala List:

val ids = session("imgs").as[List[Int]]
ids.foreach(id => ...)

An update to reflect the fact that the internal implementation is now a Vector, as OP has discovered:

val ids = session("imgs").as[Seq[Int]]
Jeffrey Chung
  • 19,319
  • 8
  • 34
  • 54
  • I am getting the following error: `i.g.c.a.b.SessionHookBuilder$$anon$1 - 'hook-1' crashed with 'java.lang.ClassCastException: scala.collection.immutable.Vector cannot be cast to scala.collection.immutable.List', forwarding to the next one` – malutki5200 Jun 07 '17 at 11:15
  • found a solution but Thank You for help. – malutki5200 Jun 07 '17 at 11:25
0

I found a solution. The only possible format is Seq. In my case this solves the problem:

val imageIds = session("imgs").as[Seq[String]]
malutki5200
  • 1,092
  • 7
  • 15