Skip to content Skip to sidebar Skip to footer

Postman: Comparing Object Environment Variable With Response's Object

I am having a problem with comparing object typed Env variable with the response's object in Postman even though it seems the same and couldn't find answers anywhere. Here's the ex

Solution 1:

I have found a solution, I've used:

tests["user contains correct data" = JSON.stringify(data.user) == JSON.stringify(user);

And I can also just delete the test script and use bare postman.getEnvironmentVariable instead of the second stringify().

Solution 2:

You can find better solutions to your problem in a very similar question here: How to write a postman test to compare the response json against another json?

I had a similar problem to solve except that my JSON also contained an array of objects. My answer in this question or one of the other answers will provide a more stable solution for comparison.

I created an array of global functions called "assert", which contained helper functions such as "areEqual" and "areArraysOfObjectsEqual" and saved these under the "Tests" tab at a top folder level of my tests.

Post a Comment for "Postman: Comparing Object Environment Variable With Response's Object"