What will be the test result if the server responds with status code 200?
medium
A. Test will pass
B. Test will be skipped
C. Test will error out
D. Test will fail
Solution
Step 1: Understand the assertion
The test expects status code 201 (Created) exactly.
Step 2: Compare actual response code
The server returned 200 (OK), which does not match 201, so assertion fails.
Final Answer:
Test will fail -> Option D
Quick Check:
Expected 201 but got 200 = Fail [OK]
Hint: Exact status code must match to pass assertion [OK]
Common Mistakes:
Assuming 200 and 201 are interchangeable
Thinking test errors instead of fails
Believing test skips on mismatch
4. You wrote this Postman test:
pm.test('Status is 200', () => {
pm.response.to.have.status = 200;
});
What is wrong with this test?
medium
A. Status code 200 is invalid
B. Missing semicolon at the end
C. Incorrect use of assignment instead of function call
D. pm.test syntax is wrong
Solution
Step 1: Check assertion syntax
The code uses = which assigns a value instead of calling status(200) as a function.
Step 2: Identify correct usage
The correct syntax is pm.response.to.have.status(200); to assert status code.
Final Answer:
Incorrect use of assignment instead of function call -> Option C
Quick Check:
Use parentheses for function calls, not assignment [OK]
Hint: Use parentheses () to call status function, not = [OK]
Common Mistakes:
Using = instead of calling status()
Ignoring syntax errors thinking test runs
Confusing semicolon importance
5. You want to write a Postman test that passes only if the response status code is either 200 or 201. Which code snippet correctly asserts this?
hard
A. pm.test('Status is 200 or 201', () => {
pm.expect(pm.response.code === 200 || pm.response.code === 201).to.be.true;
});
B. pm.test('Status is 200 or 201', () => {
pm.response.to.have.status(200 || 201);
});
C. pm.test('Status is 200 or 201', () => {
pm.response.to.have.status(200) || pm.response.to.have.status(201);
});
D. pm.test('Status is 200 or 201', () => {
pm.response.to.have.status([200, 201]);
});
Solution
Step 1: Understand how to check multiple status codes
Postman does not support passing multiple codes directly to status().
Step 2: Use logical OR with pm.expect
pm.test('Status is 200 or 201', () => {
pm.expect(pm.response.code === 200 || pm.response.code === 201).to.be.true;
}); uses pm.expect with a boolean expression checking if code is 200 or 201, which is correct.
Final Answer:
pm.test('Status is 200 or 201', () => {
pm.expect(pm.response.code === 200 || pm.response.code === 201).to.be.true;
}); -> Option A
Quick Check:
Use pm.expect with OR condition for multiple codes [OK]
Hint: Use pm.expect with OR to check multiple status codes [OK]