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")
)
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")) {
...
}