Per the documentation it looks like this check should fail if the array returns empty:
.check(jsonPath("$..data").exists)
But we have noticed some of the responses are returning data[]
, and we do not see any failed requests in the report. If we do:
.check(jsonPath("$..data[]").exists)Enter code here...
Then the check will fail if the array is empty.
Per the documentation it looks like this check should fail if the array returns empty:
Could you please provide a pointer to the documentation you’re referring to?
The first one is expected to find something (an empty array here) when the node exists.
The second one should crash with a syntax error. It doesn’t and it’s a bug on our side that we’ll fix.
Sorry, assumed the section I was referring to would be known.
How to use HTTP specific checks, such as status, header or currentLocation, to validate your HTTP payloads and capture elements and store them in the Session.
Checks that the value exists and is not empty in case of multiple results:
jsonPath("$..foo").exists
Sounds like we would need to check for:
.check(jsonPath("$..data[0]").exists)
But again, wanted to double check, since documentation reads like just $…data should do the same thing.
Checks that the value exists and is not empty in case of multiple results:
OK, it’s probably not very clear.
“find” returns an Option[T] and exists will fail on None.
“findAll” returns a Seq[T] and “exists” will fail on empty Seq.
(more or less)
So in our case where we expect array we would want:
.check(jsonPath("$..data").findAll.exists)
I’m a bit confused on this snippet in the docs though, which seems to say find is implicitly added:
So in our case where we expect array we would want:
.check(jsonPath("$..data").findAll.exists)
Probably not. findAll would be if you have multiple occurrences of “data” nodes and wanted to collect them all.
I’m a bit confused on this snippet in the docs though, which seems to say find is implicitly added:
.check(jsonPath(“$…data”).find.exists
.check(jsonPath(“$…data”).find
.check(jsonPath(“$…data”).exists
.check(jsonPath(“$…data”)
are all equivalent as find and exists are the default values for their respective steps.
Stéphane Landelle
GatlingCorp CTO
slandelle@gatling.io
Yes, this is what I was assuming. But when the response returned:
{ "metaData": { "auditTrack": { "serviceTransactionID": "95516592-7524-448b-94b5-7f5f9a1d46db" } }, "data": [] }
.check(jsonPath("$..data").exists)
Was still passing. I’m missing something here, because I feel like I’ve circled back to my original post.
{
“metaData”: {
“auditTrack”: {
“serviceTransactionID”: “95516592-7524-448b-94b5-7f5f9a1d46db”
}
},
“data”: []
}
.check(jsonPath("$…data").exists)
Is there a node named data somewhere in the JSON tree? Yes, indeed, so check passes as expected.
If you want to check that the array exists AND is non empty, you can check $…data[0] existence.
Thanks, that is was we moved to, but wanted to confirm we properly understood the framework checks.
But still you need to be careful, because this response will not cause failure (see the nested “data” node):
`
{
“metaData”: {
“data”: [“gatling”, “rules”],
“auditTrack”: {
“serviceTransactionID”: “95516592-7524-448b-94b5-7f5f9a1d46db”
}
},
“data”: []
}
`
This is because this check is recursive:
`
$…data[0]
`
To make sure there is non empty “data” node on the root level you must use:
`
$.data[0]
`
Cheers,
Adam