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.

2 Answers 2

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]]
Sign up to request clarification or add additional context in comments.

2 Comments

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
found a solution but Thank You for help.
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]]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.