Test Overview
This test sends a GET request to an API endpoint and verifies that the response size is within the expected limit.
This test sends a GET request to an API endpoint and verifies that the response size is within the expected limit.
pm.test("Response size is less than 500KB", function () { const responseSize = pm.response.size().body; pm.expect(responseSize).to.be.below(500 * 1024); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman app is open with the test script loaded | — | PASS |
| 2 | Sends GET request to the API endpoint | Request sent, waiting for response | — | PASS |
| 3 | Receives response from the server | Response received with status 200 and body content | — | PASS |
| 4 | Calculates response body size in bytes using pm.response.size().body | Response size calculated | Response size is less than 512000 bytes (500KB) | PASS |
| 5 | Assertion checks if response size is below 500KB | Assertion executed | pm.expect(responseSize).to.be.below(500 * 1024) | PASS |
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