Bird
Raised Fist0
Postmantesting~10 mins

Response size in Postman - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check the response size in Postman.

Postman
pm.test('Response size is less than 2KB', function () {
    pm.expect(pm.response.size().bodySize).to.be.[1](2048);
});
Drag options to blanks, or click blank then click option'
AlessThan
Bbelow
CgreaterThan
Dabove
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'above' or 'greaterThan' which check for larger values.
2fill in blank
medium

Complete the code to assert the response size equals exactly 500 bytes.

Postman
pm.test('Response size equals 500 bytes', () => {
    pm.expect(pm.response.size().bodySize).to.equal([1]);
});
Drag options to blanks, or click blank then click option'
A500
B1024
C2048
D256
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong number for the expected size.
Using a method other than equal for exact match.
3fill in blank
hard

Fix the error in the code to correctly assert the response size is greater than 1KB.

Postman
pm.test('Response size is greater than 1KB', function() {
    pm.expect(pm.response.size().bodySize).to.be.[1](1024);
});
Drag options to blanks, or click blank then click option'
Abelow
Babove
ClessThan
Dequal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lessThan' or 'below' which check for smaller values.
Using 'equal' which checks for exact match.
4fill in blank
hard

Fill both blanks to assert the response size is between 1KB and 3KB.

Postman
pm.test('Response size is between 1KB and 3KB', () => {
    pm.expect(pm.response.size().bodySize).to.be.[1](1024).and.[2](3072);
});
Drag options to blanks, or click blank then click option'
Aabove
Bbelow
ClessThan
DgreaterThan
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up above and below.
5fill in blank
hard

Fill all three blanks to create a test that asserts the response size is not equal to 0 and less than 5KB.

Postman
pm.test('Response size is valid', () => {
    pm.expect(pm.response.size().bodySize).to.not.[1](0).and.[2]([3]);
});
Drag options to blanks, or click blank then click option'
Aequal
BlessThan
C5120
Dabove
Attempts:
3 left
💡 Hint
Common Mistakes
Using above instead of lessThan for the second assertion.
Using wrong numbers for the size limit.

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