0
0
Postmantesting~15 mins

Response size in Postman - Build an Automation Script

Choose your learning style9 modes available
Verify API response size is within expected limit
Preconditions (2)
Step 1: Send a GET request to the API endpoint https://api.example.com/data
Step 2: Check the size of the response body in bytes
Step 3: Verify that the response size is less than or equal to 5000 bytes
✅ Expected Result: The response size is less than or equal to 5000 bytes
Automation Requirements - Postman test scripts
Assertions Needed:
Response size is less than or equal to 5000 bytes
Best Practices:
Use pm.response.to.have.property('responseSize') to get response size
Use pm.expect for assertions
Write clear and simple test scripts
Avoid hardcoding values except for limits
Add comments for clarity
Automated Solution
Postman
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.

Common Mistakes - 3 Pitfalls
Using pm.response.size instead of pm.response.responseSize()
Hardcoding the response size value inside the test without explanation
Not using pm.expect for assertions
Bonus Challenge

Now add data-driven testing with 3 different API endpoints and verify their response sizes are within limits

Show Hint