0
0
Postmantesting~20 mins

Default and conditional responses in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Default and Conditional Responses
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the test result of this Postman test script?
Given the following Postman test script, what will be the test result if the response status code is 404?
Postman
pm.test('Status code is 200 or 201', function () {
    pm.expect(pm.response.code).to.be.oneOf([200, 201]);
});
ATest fails because 404 is not in [200, 201]
BTest passes because 404 is considered a success
CTest throws an error due to invalid syntax
DTest is skipped automatically
Attempts:
2 left
💡 Hint
Check which status codes are accepted by the oneOf assertion.
assertion
intermediate
2:00remaining
Which assertion correctly checks for a default JSON property in Postman?
You want to verify that the JSON response always contains a property named 'success' with a boolean value. Which assertion is correct?
Apm.expect(pm.response.json().success).to.be.a('boolean');
Bpm.expect(pm.response.json().success).to.be.true || false;
Cpm.expect(pm.response.json().success).to.equal('true');
Dpm.expect(pm.response.json().success).to.be('boolean');
Attempts:
2 left
💡 Hint
Check the syntax for type checking in Postman assertions.
🧠 Conceptual
advanced
2:00remaining
What happens if no conditional test matches in a Postman test script?
In a Postman test script, you have multiple conditional tests checking response codes 200, 201, and 404. What is the default behavior if the response code is 500 and no condition matches?
ANo test runs and the test suite passes by default
BAll tests fail automatically because no condition matched
CPostman throws a runtime error due to unmatched conditions
DTests not matching conditions are skipped, but overall test result depends on other tests
Attempts:
2 left
💡 Hint
Think about how Postman handles tests that are not explicitly triggered.
🔧 Debug
advanced
2:00remaining
Why does this Postman test script always fail?
Analyze the following Postman test script and identify why it always fails regardless of response status code: pm.test('Check status', () => { if (pm.response.code === 200) { pm.expect(true).to.be.true; } else if (pm.response.code === 404) { pm.expect(true).to.be.true; } });
Postman
pm.test('Check status', () => {
  if (pm.response.code === 200) {
    pm.expect(true).to.be.true;
  } else if (pm.response.code === 404) {
    pm.expect(true).to.be.true;
  }
});
AThe test always fails because pm.expect(true).to.be.true is incorrect
BThe test syntax is invalid causing failure
CThe test fails when response code is neither 200 nor 404 because no assertion runs
DThe test fails because pm.response.code is undefined
Attempts:
2 left
💡 Hint
What happens if the response code is 500?
framework
expert
3:00remaining
How to implement a default response handler in Postman tests?
You want to write a Postman test script that handles multiple response codes (200, 201, 404) with specific assertions and also has a default assertion for any other response code. Which script correctly implements this?
A
pm.test('Response code check', () => {
  pm.expect(pm.response.code).to.be.oneOf([200,201,404]);
});
B
pm.test('Response code check', () => {
  switch(pm.response.code) {
    case 200:
      pm.expect(pm.response.code).to.equal(200);
      break;
    case 201:
      pm.expect(pm.response.code).to.equal(201);
      break;
    case 404:
      pm.expect(pm.response.code).to.equal(404);
      break;
    default:
      pm.expect.fail(`Unexpected status code: ${pm.response.code}`);
  }
});
C
pm.test('Response code check', () => {
  if ([200,201,404].includes(pm.response.code)) {
    pm.expect(pm.response.code).to.be.oneOf([200,201,404]);
  }
});
D
pm.test('Response code check', () => {
  if (pm.response.code === 200) {
    pm.expect(pm.response.code).to.equal(200);
  } else if (pm.response.code === 201) {
    pm.expect(pm.response.code).to.equal(201);
  } else if (pm.response.code === 404) {
    pm.expect(pm.response.code).to.equal(404);
  } else {
    pm.expect(pm.response.code).to.be.oneOf([200,201,404]);
  }
});
Attempts:
2 left
💡 Hint
Look for a default case that fails the test explicitly.