Validating a get request response body against a previous response body

Hi,

I am looking to validate a get request response body against a previously run request using the same data.

So essentially if I send a get request and receive this response -

{
“Name”: “Dan”,
“Jobtitle”: “QA Tester”,
“Location”: UK
},

I know I will get that same response every time I call this API. What I want to validate as part of my automated tests is that static data doesn’t change, if it does change I want it to flag this so I can check it against our API docs.

Currently I am using basic string validation to ensure “Name”, “Job Title” and “Location” are displaying for example but that process has resulted in over 800 tests which is painful to maintain and still doesn’t tell me if new lines have been added into the response.

In an ideal world it would be as simple as save the current JSON request as a text document, then in my tests reference that document essentially saying “Your response should match this, if no, test fails”, does this exist or will I just have to make do by writing another thousand or so string validations to check each response line?

Thanks for the help!

@d.baldwin

You can use an environment variable to validate the response is correct if the response is always the same.

Example:
Save the response you want to compare it to in an environment variable “oldData”.

In your Tests add:

var newData = responseBody;
var oldData = pm.variables.get(“oldData”);

pm.test(“Response body is the same as oldData”, function () {
pm.expect(newData).to.eql(oldData);
});
});

Hope this helps,
Mick

Hi Mick,

Thanks for the suggestion, I ended up going similar and manually copying the response into an environment variable, which in hind sight isn’t as easy as your suggestion… May quickly swap this out, thanks for the help!

Dan