Let us say, there are two APIs which accept POST requests. Both the APIs perform the same job(one is an old API and another is the new API, there has been some migration of code and hence the API is also getting renewed).
As regression, I am required to send POST requests to both the APIs then compare the responses(the entire response body except few fields like ID, Timestamp etc). There SHOULD NOT be any difference. If there is a difference then it is a bug.
Here is the catch:
The comparison for the entire JSON response has to be done 100+ times with different bodies in the POST request. (I am not sure if getting the data from a csv file is a good option for 100+ data).
Looking forward to hearing from you on how you would like to proceed on this problem of comparing two JSON response bodies in POSTMAN and repeat for 100+ times EXCLUDING one or more fields like IDs, Timestamp which will never match.
were key1,key2 etc are keys you don’t want to compare.
so create two requests,
in first request (old endpoint) store value to an environment varaible say ‘oldresponse’
in second request ( new endpoint) store value to ‘newresponse’
And in test script session of second request just use
console.log(_.isEqual(pm.environment.get('oldresponse'),pm.environment.get('newresponse'), (value1, value2, key) => {
//this will ignore comparing the value if key is timestamp or id
return key === "timestamp" || key === "id" ? true : undefined;
}))
I have used the above script. At the end of the second POST response, it says false but at the end it says true. True is correct but not sure why it prints false as well.
remove the console.log inside the function , it is there to print each comparison . it will first stringify two object and validate if its equal if its not equal then it does a deep comparizon of values instead. I just added it for demo purpose
Understood, I actually want only the differences between the two. With the above I need to manually check where the difference is because it returns both same and difference.