Reputation: 1149
While testing my API, and When something is wrong in the request I got messages like:
{
"errorTimeStamp": "2021-10-21T14:08:11.7298099+02:00",
"errorMessage": "Ticket with id 0 not found",
"errorCode": 1001,
"hasError": true
}
How to mark the httpRequest as failed(red into View Results Tree) based on: "hasError": true
I prefer to use JSR223 Assertion sampler, so later I can extend and include other matchers
Upvotes: 0
Views: 246
Reputation: 168157
Something like:
def hasError = new groovy.json.JsonSlurper().parse(prev.getResponseData()).hasError
if (hasError) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('Response data has error')
}
should do the trick for you
More information:
prev
) documentationUpvotes: 2