Gatling for functional tests: how to build chain of requests and access session?

I want to use Gatling for functional tests.
I’ve tried basic tests and they work fine.
Now I want to implement some useful test :slight_smile:
But I can’t find any non - trivial example.
I want to test REST API and I need to build a chain of requests.
On each request retrieve Json data and check for content.
Then use retrieved data in next request.
Is this possible with Functional tests? If so, please give me direction.

Regards,
Sergey

Hi Sergey,

I did a medium complex functional test setup with Gatling - below you find an example request which uses a couple of JSONPath expression to extract values to be used in the next request

val get: ChainBuilder = exec(http(“my/accounts”)
.get(ConfigurationTool.getURL(“george”, “/my/accounts”))
.header(“Authorization”, “bearer ${token}”)
.header(X_REQUEST_ID, XRequestId())
.queryParam("_", “${user}”)
.check(
bodyString.saveAs(“lastResponse”),
jsonPath("$.collection[*].id").ofType[String].findAll.optional.saveAs(“accountIds”),
jsonPath("$.collection[?(@.balance.currency)].id").ofType[String].findAll.optional.saveAs(“accountIdsHavingBalance”),
jsonPath("$.collection[?(@.hasImage == true)].id").ofType[String].findAll.optional.saveAs(“accountIdsHavingImage”),
jsonPath("$.collection[?(@.type == ‘CURRENT’ || @.type == ‘SAVING’)].id").ofType[String].findAll.optional.saveAs(“accountIdsForStatsCall”),
jsonPath("$.collection[?(@.type == ‘CURRENT’ || @.type == ‘SAVING’ || @.type == ‘LOAN’)].id").ofType[String].findAll.optional.saveAs(“accountIdsForTransactionCall”))
)

Thanks in advance,

Siegfried Goeschl

Thank you Siegfried Goeschl.
Can you show bigger part of your code?
With second request using results from first request?
Also interested in spec part. How to combine exec with spec?

Regards,
Sergey Dashko

Yes, will be glad if you can.