Bird
Raised Fist0
Postmantesting~10 mins

Response size in Postman - Test Execution Trace

Choose your learning style10 modes available
Test Overview

This test sends a GET request to an API endpoint and verifies that the response size is within the expected limit.

Test Code - Postman
Postman
pm.test("Response size is less than 500KB", function () {
    const responseSize = pm.response.size().body;
    pm.expect(responseSize).to.be.below(500 * 1024);
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsPostman app is open with the test script loaded—PASS
2Sends GET request to the API endpointRequest sent, waiting for response—PASS
3Receives response from the serverResponse received with status 200 and body content—PASS
4Calculates response body size in bytes using pm.response.size().bodyResponse size calculatedResponse size is less than 512000 bytes (500KB)PASS
5Assertion checks if response size is below 500KBAssertion executedpm.expect(responseSize).to.be.below(500 * 1024)PASS
Failure Scenario
Failing Condition: Response body size is 500KB or more
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the API response?
AThe response status code is 404
BThe response size is less than 500KB
CThe response contains a specific JSON key
DThe response time is under 1 second
Key Result
Always verify response size to ensure API responses are efficient and within expected limits, preventing performance issues.

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