Verify API response size is within expected limit
Preconditions (2)
✅ Expected Result: The response size is less than or equal to 5000 bytes
pm.test('Response size is within 5000 bytes', function () { const responseSize = pm.response.responseSize(); pm.expect(responseSize).to.be.at.most(5000); });
This Postman test script checks the size of the response body.
First, it gets the response size in bytes using pm.response.responseSize().
Then, it asserts that the size is at most 5000 bytes using pm.expect.
This ensures the API response is not too large, which helps with performance and bandwidth.
Now add data-driven testing with 3 different API endpoints and verify their response sizes are within limits
pm.response.size().body return in Postman?pm.response.size().body accesses.body property specifically returns the size of the response body in bytes.pm.response.size().body = response body size [OK]pm.expect() for assertions.pm.response.size().body, and to assert it is below 5000 bytes, use to.be.below(5000).pm.expect() with to.be.below() [OK]pm.test('Check response size', () => {
pm.expect(pm.response.size.body).to.be.below(2000);
});pm.response.size.body which is incorrect because size is a function, not an object.pm.response.size().body to get the response body size.within(100, 5000) which includes 100 and 5000, but does not fail outside range explicitly.pm.expect() which is not a valid assertion.Pass the test and this pattern moves unknown