'earliest_timestamp is below latest_timestamp in postman test
im trying to create test script for condition earlier_timestamp is below that latest_timestamp
var moment = require('moment');
pm.test("Condition - Earliest Timestamp is < 1 day", function() {
var latest_Timestamp = pm.response.json();
var earliest_Timestamp = pm.response.json();
pm.expect(pm.earliest_timestamp.get(earliest_timestamp)).to.be.below(pm.latest_timestamp.get(latest_timestamp));
});
Im getting response
TypeError: Cannot read property 'get' of undefined
Solution 1:[1]
Assuming the following response body:
{
"latest_timestamp":"2022-03-18 13:01:14.619542+00:00",
"earliest_timestamp":"2022-03-17 13:01:14.619542+00:00"
}
this will work:
var jsonData = pm.response.json();
var latest = Date.parse(jsonData.latest_timestamp);
var earliest = Date.parse(jsonData.earliest_timestamp);
pm.test("Condition - Earliest Timestamp is < 1 day", function() {
pm.expect(latest).to.be.above(earliest);
});
Depending on your actual response body, you would need to adapt lines 3 & 4 a little bit.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Christian Baumann |
