Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If else condition inside check in gatling

Tags:

scala

gatling

I need to implement an if-else condition in my gatling check.

For example:- Below, I might get items array in JSON response as empty. So I need to check if items is empty. I need to execute another set of action. Can you please let me know how can I achieve this?

.check(
       jsonPath("$..items[(@.length-1)].id").saveAs("MyAlbumId")
    ) 
like image 352
Kalava Avatar asked Oct 03 '22 22:10

Kalava


1 Answers

As explained on the Gatling ML:

When using a check, the default verify step is exists, so you have to use whatever instead if having your check find nothing is acceptable: https://github.com/excilys/gatling/wiki/Checks#wiki-verifying

Then, you can use a doIf in order to perform a chain of actions on certain conditions: https://github.com/excilys/gatling/wiki/Structure-Elements#wiki-do-if

For example:

doIf(session => !session.isAttributeDefined("MyAlbumId")) {
...
}
like image 113
Stephane Landelle Avatar answered Oct 07 '22 21:10

Stephane Landelle