Reputation: 95
I would like to know best way to verify entire Json response in Jmeter. Can somebody help. Thanks.
Upvotes: 1
Views: 1393
Reputation: 168072
The easiest way is use JSR223 Assertion and JsonSlurper class like:
Put the anticipated JSON into expected
JMeter Variable using i.e. User Defined Variables test element like:
Put the following code into "Script" area:
def expected = new groovy.json.JsonSlurper().parseText(vars.get('expected'))
def actual = new groovy.json.JsonSlurper().parse(prev.getResponseData())
if (expected != actual) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('Mismatch between expected and actual JSON')
}
If there will be any difference between expected and actual JSON - the sampler will be marked as failed
Upvotes: 3