This article will show you how to use JSONPath in Gatling tests.

Our sample RESTful web service is https://jsonplaceholder.typicode.com/ and we are going to use /todos endpoint in our tutorial. This endpoint will return a bunch of items, then we’ll fetch the ids’ from the response and make an individual request to /todos endpoint as /todos/{id}.

Define HTTP Protocol

That’s where we define our base url and other configuration like headers, etc. For this example, all we need to have is baseUrl.

Make GET Request to Endpoint

This step is very straight forward. All you need to do is to make a basic GET request.

Extract IDs from Response

You need to use the check function to be able to extract data. Then you can use any jsonpath expression according to your need. After getting the value(s), you should store by using findAll.saveAs() function by giving a variable name.

Make Specific GET Request

Now we have all the ID’s fetch from the response. We create a foreach loop and assign the saved value to another variable and make another get request. In order to call you variable in Scala script, you need to use ${variableName} convention.

Setup Test Configuration

We define our scenario by assigning the test case. Then we configure the virtual user number and ramp up times.

Now you can run your Gatling test like a charm.

The whole source code is below

Canberk.