mani9697
mani9697

Reputation: 53

JMeter: JSON Response body assertion

These are the sample responses for my API request

Sample 1: { "success": [{ "requestKey": "dac105de-2a1b-49a4-92d8-fce4462bbe4c", "externalKey": "0", "person": { "ID": "PAU1772881848" }, "business": { "ID": "BAU0264699094" } }], "error": [] }

Sample 2: { "success": [{ "requestKey": "d2e500b3-ce1d-41b6-bf8c-a1e337b436fe", "externalKey": "0", "person": { "ID": "PAU0917783377" }, "business": { "ID": "BAU0152754693" } }], "error": [{ "requestedUri": null, "requestKey": "fe9e7858-009d-4e10-8ba6-8b6d18666f7e", "errorCode": "BusinessPhoneNumberNotUnique", "errorMessage": "This phone number is already registered" }] }

I would like to add an assertion to check if the response body contains any errors. What's the best way to do it in JMeter? Thank you in advance.

Upvotes: 1

Views: 2421

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

You can use JMeter Assertions in order to conditionally mark samplers as failed basing on various criteria

For particular your case the most suitable option is JSON Assertion which allows execution of arbitrary JsonPath queries and validate their output values, given your examples I think you need to check that the length of error JSON Array is equal to 0

Relevant JSON Assertion configuration:

enter image description here

Upvotes: 1

Related Questions