4

I am trying to make a test in Postman to verify some content in a JSON response. If I just try to verify a single line from the JSON response everything is fine. My problem starts when I need to test multiple lines of the JSON response. Is always failing. Any suggestion?

tests["Body matches string"] = responseBody.has("\"name\": null,
                \"nameType\": \"NON_REFUNDABLE\"");

1 Answer 1

2

If I understand your question correctly I'd like to suggest that you approach this in a different way.

Instead of looking at the entire response body and seeing if the strings match you could alternatively test the individual Json properties that make up the response body. For example you could do the following:

var data = JSON.parse(responseBody);

tests["name is null"] = data.name === null;
tests["nameType is non-refundable"] = data.nameType === "NON_REFUNDABLE";

There are other alternatives as well but this is the first that comes to mind. For some more ideas about testing using postman check out their documentation and examples.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the comment but this doesnt solve my problem since this lines might appear in some other part of the same response. I need to test more than one line to get the combinations.
I'm sorry I guess I'm wondering why you need to verify the JSON response on a line by line basis? If you know the parameters you are looking for then I see no reason why you can't search for them anywhere in the response body (one by one, piece by piece).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.