Bird
Raised Fist0
Postmantesting~5 mins

Response size in Postman

Choose your learning style10 modes available
Introduction

Checking response size helps ensure the server sends the right amount of data. It can catch errors like missing or extra information.

When you want to confirm the API returns data within expected size limits.
When testing if large responses are handled properly by your app.
When verifying that no extra data is sent to save bandwidth.
When checking if a response is empty or too small, indicating a problem.
When monitoring response size changes after API updates.
Syntax
Postman
pm.test('Response size is correct', function () {
    pm.expect(pm.response.size().body).to.be.below(1000);
});

pm.response.size().body gives the size of the response body in bytes.

You can use comparison operators like .below(), .above(), or .equal() to check size.

Examples
This test checks if the response body size is smaller than 500 bytes.
Postman
pm.test('Response body size is less than 500 bytes', function () {
    pm.expect(pm.response.size().body).to.be.below(500);
});
This test verifies the response body size is exactly 1024 bytes.
Postman
pm.test('Response body size equals 1024 bytes', function () {
    pm.expect(pm.response.size().body).to.equal(1024);
});
This test ensures the response body size is more than 100 bytes.
Postman
pm.test('Response body size is above 100 bytes', function () {
    pm.expect(pm.response.size().body).to.be.above(100);
});
Sample Program

This test checks that the response body size is less than 2000 bytes to confirm the API is not sending too much data.

Postman
pm.test('Response size is under 2000 bytes', function () {
    pm.expect(pm.response.size().body).to.be.below(2000);
});
OutputSuccess
Important Notes

Response size includes only the body, not headers.

Use response size checks to catch unexpected large or empty responses.

Combine size checks with content checks for better test coverage.

Summary

Response size tests help verify data amount from APIs.

Use pm.response.size().body to get size in bytes.

Compare size with expected limits using assertions.

Practice

(1/5)
1. What does pm.response.size().body return in Postman?
easy
A. The total number of headers in the response
B. The HTTP status code of the response
C. The size of the response body in bytes
D. The time taken to receive the response

Solution

  1. Step 1: Understand the method pm.response.size()

    This method returns an object containing sizes of different parts of the response.
  2. Step 2: Identify what .body accesses

    The .body property specifically returns the size of the response body in bytes.
  3. Final Answer:

    The size of the response body in bytes -> Option C
  4. Quick Check:

    pm.response.size().body = response body size [OK]
Hint: Remember .body gives size in bytes of response content [OK]
Common Mistakes:
  • Confusing response size with status code
  • Thinking it returns header count
  • Assuming it returns response time
2. Which of the following is the correct syntax to assert that the response body size is less than 5000 bytes in Postman test script?
easy
A. pm.response.size().body < 5000;
B. pm.expect(pm.response.size().body).to.be.below(5000);
C. assert(pm.response.body.size < 5000);
D. pm.response.size.body < 5000;

Solution

  1. Step 1: Identify correct assertion syntax in Postman

    Postman uses Chai assertion library with pm.expect() for assertions.
  2. Step 2: Check the correct property and method usage

    The correct way to get response body size is pm.response.size().body, and to assert it is below 5000 bytes, use to.be.below(5000).
  3. Final Answer:

    pm.expect(pm.response.size().body).to.be.below(5000); -> Option B
  4. Quick Check:

    Use pm.expect() with to.be.below() [OK]
Hint: Use pm.expect() with to.be.below() for size assertions [OK]
Common Mistakes:
  • Using incorrect property like pm.response.body.size
  • Missing pm.expect() wrapper
  • Using plain comparison without assertion
3. Given the following Postman test script:
<pre>pm.test('Body size check', () => { const size = pm.response.size().body; pm.expect(size).to.be.above(1000); pm.expect(size).to.be.below(3000); });
What will happen if the response body size is 3500 bytes?
medium
A. The test will fail because 3500 is not below 3000
B. The test will pass because 3500 is above 1000
C. The test will fail because 3500 is not above 1000
D. The test will pass because both conditions are true

Solution

  1. Step 1: Analyze the assertions in the test

    There are two assertions: size must be above 1000 and below 3000 bytes.
  2. Step 2: Check the given size against assertions

    3500 is above 1000 (true) but not below 3000 (false), so the second assertion fails.
  3. Final Answer:

    The test will fail because 3500 is not below 3000 -> Option A
  4. Quick Check:

    3500 < 3000? No, test fails [OK]
Hint: Check all assertions; one fail means test fails [OK]
Common Mistakes:
  • Ignoring the upper bound assertion
  • Assuming test passes if one assertion passes
  • Confusing above and below conditions
4. You wrote this Postman test:
pm.test('Check response size', () => {
  pm.expect(pm.response.size.body).to.be.below(2000);
});

But the test always fails with an error. What is the problem?
medium
A. Incorrect property access; should use pm.response.size().body
B. The assertion method to.be.below() is invalid
C. pm.expect() cannot be used inside pm.test()
D. Response size cannot be checked in Postman tests

Solution

  1. Step 1: Identify the property access error

    The code uses pm.response.size.body which is incorrect because size is a function, not an object.
  2. Step 2: Correct the syntax

    The correct syntax is pm.response.size().body to get the response body size.
  3. Final Answer:

    Incorrect property access; should use pm.response.size().body -> Option A
  4. Quick Check:

    Use parentheses for size() function [OK]
Hint: Remember size() is a function, not a property [OK]
Common Mistakes:
  • Missing parentheses after size()
  • Misusing assertion methods
  • Thinking pm.expect() is invalid inside pm.test()
5. You want to write a Postman test that fails if the response body size is either too small (less than 100 bytes) or too large (more than 5000 bytes). Which test script correctly implements this?
hard
A. pm.test('Body size limits', () => { const size = pm.response.size().body; pm.expect(size).to.be.within(100, 5000); });
B. pm.test('Body size limits', () => { const size = pm.response.size().body; pm.expect(size < 100 || size > 5000).to.be.false; });
C. pm.test('Body size limits', () => { const size = pm.response.size().body; pm.expect(size).to.be.above(100) && pm.expect(size).to.be.below(5000); });
D. pm.test('Body size limits', () => { const size = pm.response.size().body; if(size < 100 || size > 5000) { throw new Error('Body size out of limits'); } });

Solution

  1. Step 1: Understand the requirement

    The test should fail if size is less than 100 or greater than 5000 bytes.
  2. Step 2: Evaluate each option's logic

    pm.test('Body size limits', () => { const size = pm.response.size().body; pm.expect(size).to.be.within(100, 5000); }); uses within(100, 5000) which includes 100 and 5000, but does not fail outside range explicitly.
    pm.test('Body size limits', () => { const size = pm.response.size().body; pm.expect(size < 100 || size > 5000).to.be.false; }); uses a boolean expression inside pm.expect() which is not a valid assertion.
    pm.test('Body size limits', () => { const size = pm.response.size().body; pm.expect(size).to.be.above(100) && pm.expect(size).to.be.below(5000); }); uses two assertions combined with && which does not work as expected in Postman.
    pm.test('Body size limits', () => { const size = pm.response.size().body; if(size < 100 || size > 5000) { throw new Error('Body size out of limits'); } }); throws an error explicitly if size is out of limits, causing the test to fail correctly.
  3. Final Answer:

    Option D correctly fails the test when size is out of limits -> Option D
  4. Quick Check:

    Throw error to fail test on condition [OK]
Hint: Use throw Error to fail test on size limits [OK]
Common Mistakes:
  • Using invalid assertion syntax for range checks
  • Combining assertions incorrectly with &&
  • Not explicitly failing test on condition
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard