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

103 views
Skip to first unread message

Sergey Dashko

unread,
Apr 26, 2017, 9:53:50 AM4/26/17
to Gatling User Group
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 :)
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

Siegfried Goeschl

unread,
Apr 29, 2017, 11:38:46 AM4/29/17
to Gatling User Group
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

Sergey Dashko

unread,
Apr 30, 2017, 4:14:33 AM4/30/17
to Gatling User Group
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

суббота, 29 апреля 2017 г., 18:38:46 UTC+3 пользователь Siegfried Goeschl написал:

Maksym Max

unread,
Jun 21, 2017, 10:30:43 AM6/21/17
to Gatling User Group
Yes, will be glad if you can.
Reply all
Reply to author
Forward
0 new messages