[
{
"id": 1,
"name": "Jack",
},
{
"id": 2,
"name": "Jill"
}
]
val getAllPersons= http("Get all persons")
.get("/persons")
.check(status.is(200), jsonPath("$..id").findAll.optional.saveAs("personIds"))
The above code will extract id values and store as list in personIds.
If REST response returns empty list then the above code will fail with error -
jsonPath($..id).findAll.exists, found nothing
Using optional in the chain helps avert the error. Only if the findAll returns any thing the saveAs will execute and will work without failure.
No comments:
Post a Comment