vr3kba
Last Updated: February 25, 2016
·
6.048K
· jeantil
75da740d43c5780539214f24ce1148a6

Extract and reuse a list of identifiers with Gatling

If you are writing a bench for a batch create/read API, you may need to manipulate list of identifiers instead of a single id. Let's see how you can do that with gatling (1.3x-1.4x).

Let's say that we have the following JSON API :

POST /events 
GET  /events/:comma_separated_id_list

Where the post accepts a payload with multiple events and returns them with identifiers when they are created. You want to capture these identifiers and reuse them later to generate the :commaseparatedid_list.

First comes the capture. The naive approach would be to add the following check to the POST call

jsonPath("//events/id/text()").findAll.saveAs("idList")

Unfortunately that would save an ArrayBuffer of values in the idList session variable. With gatling you can't "transform" the captured value when you use it. This snippet won't work:

get("/events/${idList.mkString(\",\")}")

However you can apply transformations at capture time. Changing your check to

jsonPath("//events/id/text()").findAll.transform(_.mkString(",")).saveAs("idList")

and your call to

get("/events/${idList}")

further info on checks and transform can be found on the gatling wiki

Say Thanks
Respond