How to compare CSV to Postman JSON Response values?
Try casting the csv integer value to a string and using to.equal
instead of to.eql
(which is equivalent to to.deep.equal
):
pm.expect(jsonData.args.ramen).to.equal(new String(pm.iterationData.get("Ramen")));
Using Postman to take values from two different responses to assert against each other
In your first request test, get required elements and push it to array and set that array into environment variable.
var jsonData = pm.response.json();
var array = [];
jsonData.forEach(function(element) {
array.push(element.name);
});
pm.environment.set("pre_request_array", array);
In your second request test, get environment variable we previously set and now can compare the both:
var jsonData = pm.response.json();
var currArray = [];
var prevArray = pm.environment.get("pre_request_array");
jsonData.sites.forEach(function(element) {
currArray.push(element.name);
});
console.log(prevArray);
console.log(currArray);
//TODO: add compare logic here
In console, you can find output as below screen.
How to compare two dates in Postman
I have a similar scenario: I need to compare two dates in postman, dates in a format like "2022-01-16T19:40:51.816".
So I use this:
// (dates from JSON for my case)
// var date1 = "2022-01-16T19:40:51.816";
// var date2 = "2022-01-16T17:40:51.816";
// (today for your case)
// var today = new Date();
pm.expect(Date.parse(date1)).to.be.above(Date.parse(date2));
Related Topics
How to Change Background Opacity When Bootstrap Modal Is Open
How to Change Height in Mat-Form-Field
How to Avoid the Setstate()/Render() Endless Loop When Passing Data from Child to Parent
Pdf Blob - Pop Up Window Not Showing Content
How to Export Json Data to Excel File Using JavaScript
Angular Load Async Data Before Component Initialization
Html5 and JavaScript to Play Videos Only When Visible
Javascript to Download a File from Amazon S3 Bucket
How to Redirect to Another Page Using Angularjs
Disable Right-Clicking in Html5 Video
How to Mock the JavaScript Window Object Using Jest
Uploading Multiple Files Using Formdata()
How to Split Date and Time from the Datetime Variable in JavaScript
Angular: How to Get Default @Input Value
Nodejs MySQL Get Correct Timestamp Format
React Enable Button After All Form Fields Are Not Empty
How to Remove Captcha Verification from Firebase Phone Auth Using JavaScript