Brief Comparison of Responses in Postman

Sometimes, as a test engineer, you need to quickly compare two API responses

Moreover, if you don’t need to look for differences and just want to get YES (they are the same) or NO (they are not) — Postman is a way to do that.

Let’s assume that you have a REST API with success code = 200 OK (I took for example one handler of SpaceX REST API) and the response comes in JSON format.

GET https://api.spacexdata.com/v4/capsules/{capsuleId}

For the first request in the Test tab you need:

pm.test("Status is OK", function () {    pm.response.to.have.status(200);});let jsonData = pm.response.json();pm.globals.set("response", jsonData);

For the second request in the Test tab you need:

pm.test("Status is OK", function () {    pm.response.to.have.status(200);});let jsonData = pm.response.json();let firstResponse = pm.globals.get("response");pm.test("Responses are equal", function () {    pm.expect(jsonData).to.deep.equal(firstResponse);});

In the case of a FAIL test you have two different data.

For more detailed research of the cause of the failure or the place of data discrepancy you’ll need a more advanced test script or a different tool.

Quality assurance engineer