Bird
Raised Fist0
Postmantesting~10 mins

Status codes reading 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 if the response status code is 200.

Postman
pm.test("Status code is 200", function () {
    pm.response.to.have.status([1]);
});
Drag options to blanks, or click blank then click option'
A200
B404
C500
D301
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 which means Not Found.
Using 500 which means Server Error.
2fill in blank
medium

Complete the code to verify the response status code is in the 4xx client error range.

Postman
pm.test("Status code is client error", function () {
    pm.expect(pm.response.code).to.be.[1];
});
Drag options to blanks, or click blank then click option'
Abelow(400)
Bwithin(400, 499)
Cabove(400)
Dequal(400)
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'below(400)' which checks for codes less than 400.
Using 'equal(400)' which only checks for exactly 400.
3fill in blank
hard

Fix the error in the code to correctly assert the status code is 201.

Postman
pm.test("Status code is 201", function () {
    pm.response.to.have.status([1]);
});
Drag options to blanks, or click blank then click option'
Astatus201
B"201"
C201
Dtwo hundred one
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number making it a string.
Using descriptive text instead of the numeric code.
4fill in blank
hard

Fill both blanks to check if the status code is either 200 or 204.

Postman
pm.test("Status code is 200 or 204", function () {
    pm.expect(pm.response.code).to.be.oneOf([[1], [2]]);
});
Drag options to blanks, or click blank then click option'
A200
B201
C204
D400
Attempts:
3 left
💡 Hint
Common Mistakes
Using 201 which means Created, not requested here.
Using 400 which is a client error.
5fill in blank
hard

Fill all three blanks to assert the status code is between 200 and 299 inclusive.

Postman
pm.test("Status code is success range", function () {
    pm.expect(pm.response.code).to.be.within([1], [2]);
    pm.expect(pm.response.code).to.not.equal([3]);
});
Drag options to blanks, or click blank then click option'
A199
B200
C299
D300
Attempts:
3 left
💡 Hint
Common Mistakes
Using 199 as lower bound which is not a valid success code.
Including 300 which is outside the success range.

Practice

(1/5)
1. What does the status code 200 usually mean in Postman response testing?
easy
A. The request was successful and the server returned the expected data.
B. The requested resource was not found on the server.
C. The server encountered an internal error.
D. The client is not authorized to access the resource.

Solution

  1. Step 1: Understand HTTP status codes

    Status code 200 means OK, indicating success in HTTP responses.
  2. Step 2: Interpret 200 in Postman context

    In Postman, a 200 status means the request succeeded and data was returned.
  3. Final Answer:

    The request was successful and the server returned the expected data. -> Option A
  4. Quick Check:

    Status code 200 = Success [OK]
Hint: 200 means success, like a green light [OK]
Common Mistakes:
  • Confusing 200 with error codes like 404 or 500
  • Thinking 200 means unauthorized access
  • Assuming 200 means no data returned
2. Which of the following is the correct way to check for a 404 status code in a Postman test script?
easy
A. pm.test('Status is 404', () => pm.response.code === 404);"
B. pm.test('Status is 404', () => pm.response.code == 404);
C. pm.test('Status is 404', () => pm.response.code === 404);
D. pm.test('Status is 404', () => pm.response.code = 404);

Solution

  1. Step 1: Understand Postman test syntax

    Postman tests use pm.test with a callback function containing an assertion.
  2. Step 2: Use correct assertion method

    While pm.expect(pm.response.code).to.eql(404) is preferred, the direct comparison requires strict ===, proper arrow function syntax, and no extra characters or assignment operators.
  3. Final Answer:

    pm.test('Status is 404', () => pm.response.code === 404); -> Option C
  4. Quick Check:

    Use triple equals and arrow function in pm.test [OK]
Hint: Use arrow function and triple equals for status check [OK]
Common Mistakes:
  • Using single equals (=) instead of comparison
  • Missing arrow function syntax
  • Using double quotes inconsistently
3. Given this Postman test script:
pm.test('Check status', () => {
  pm.expect(pm.response.code).to.be.oneOf([200, 201]);
});

What will happen if the response status code is 201?
medium
A. The test will fail because 201 is not in the list.
B. The test will be skipped automatically.
C. The test will throw a syntax error.
D. The test will pass because 201 is included in the allowed codes.

Solution

  1. Step 1: Understand the oneOf assertion

    pm.expect(...).to.be.oneOf([200, 201]) passes if the response code matches any value in the array.
  2. Step 2: Check if 201 is in the array

    201 is included in [200, 201], so the assertion passes.
  3. Final Answer:

    The test will pass because 201 is included in the allowed codes. -> Option D
  4. Quick Check:

    201 in [200, 201] = pass [OK]
Hint: oneOf passes if code matches any listed status [OK]
Common Mistakes:
  • Thinking 201 is not allowed
  • Confusing oneOf with equals
  • Assuming syntax error from array
4. You wrote this Postman test:
pm.test('Status is 200', () => {
  pm.expect(pm.response.code = 200);
});

Why does this test always pass even if the response code is not 200?
medium
A. Because the single equals sign assigns 200 instead of comparing, so assertion is always true.
B. Because pm.response.code is read-only and cannot be changed.
C. Because Postman ignores the test function if syntax is wrong.
D. Because the test is missing a semicolon.

Solution

  1. Step 1: Identify the use of single equals in assertion

    The code uses pm.response.code = 200, which is assignment, not comparison.
  2. Step 2: Understand effect of assignment in assertion

    Assignment returns 200 (truthy), so pm.expect always receives a truthy value, making the test pass regardless of actual status.
  3. Final Answer:

    Because the single equals sign assigns 200 instead of comparing, so assertion is always true. -> Option A
  4. Quick Check:

    Use '===' for comparison, not '=' [OK]
Hint: Use triple equals (===) for comparison, not single equals (=) [OK]
Common Mistakes:
  • Confusing assignment (=) with comparison (===)
  • Ignoring that assignment returns a truthy value
  • Assuming syntax error instead of logic error
5. You want to write a Postman test that passes only if the response status code is between 200 and 299 inclusive. Which code snippet correctly implements this?
hard
A. pm.test('Status is 2xx', () => pm.expect(pm.response.code).to.equal(2));
B. pm.test('Status is 2xx', () => pm.expect(pm.response.code).to.be.within(200, 299));
C. pm.test('Status is 2xx', () => pm.expect(pm.response.code >= 200 && pm.response.code <= 299));
D. pm.test('Status is 2xx', () => pm.expect(pm.response.code).to.be.oneOf([200, 201, 202, 203, 204, 205]));

Solution

  1. Step 1: Identify the correct assertion for range check

    pm.expect(...).to.be.within(min, max) checks if value is between min and max inclusive.
  2. Step 2: Evaluate each option

    pm.test('Status is 2xx', () => pm.expect(pm.response.code).to.be.within(200, 299)); uses .within(200, 299) correctly. pm.test('Status is 2xx', () => pm.expect(pm.response.code).to.be.oneOf([200, 201, 202, 203, 204, 205])); lists only some codes, incomplete for full 2xx range. pm.test('Status is 2xx', () => pm.expect(pm.response.code >= 200 && pm.response.code <= 299)); uses invalid syntax inside pm.expect. pm.test('Status is 2xx', () => pm.expect(pm.response.code).to.equal(2)); checks for exact 2, which is wrong.
  3. Final Answer:

    pm.test('Status is 2xx', () => pm.expect(pm.response.code).to.be.within(200, 299)); -> Option B
  4. Quick Check:

    Use .within(200, 299) for range checks [OK]
Hint: Use .within(200, 299) to check 2xx status codes [OK]
Common Mistakes:
  • Listing all codes instead of using range
  • Using invalid boolean inside pm.expect
  • Checking for exact number 2 instead of range
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