The test expects the response status to be exactly 200.
Step 2: Compare actual status with expected
The actual status is 404, which does not match 200, so the test fails.
Final Answer:
Test fails because status is not 200 -> Option C
Quick Check:
Status 404 != 200 means test fail [OK]
Hint: Exact status match needed; 404 ≠ 200 means fail [OK]
Common Mistakes:
Assuming close status codes pass
Expecting syntax error instead of fail
Thinking warnings occur on mismatch
4. Identify the error in this Postman test code that checks if the response JSON has a 'name' field:
pm.test('Check name field', () => {
pm.expect(pm.response.json().name).to.equal;
});
medium
A. Missing value in to.equal assertion
B. Incorrect method pm.response.json() usage
C. pm.expect should be pm.test
D. No error, code is correct
Solution
Step 1: Analyze the assertion syntax
to.equal requires a value to compare against, but none is provided here.
Step 2: Confirm other parts are correct
pm.response.json() is valid, and pm.expect is correct for assertions.
Final Answer:
Missing value in to.equal assertion -> Option A
Quick Check:
to.equal needs a value to compare [OK]
Hint: Always provide a value inside to.equal() [OK]
Common Mistakes:
Leaving to.equal empty
Confusing pm.expect with pm.test
Misusing pm.response.json()
5. You want to confirm that the API response contains a 'status' field with value 'success' and the response time is less than 500ms. Which Postman test code correctly validates both conditions?
hard
A. pm.test('Status and time', () => {
pm.expect(pm.response.json().status).to.equal('success');
pm.expect(pm.response.responseTime).to.be.below(500);
});
B. pm.test('Status and time', () => {
pm.expect(pm.response.json().status).to.equal('success');
pm.expect(pm.response.time).to.be.below(500);
});
C. pm.test('Status and time', () => {
pm.expect(pm.response.status).to.equal('success');
pm.expect(pm.response.time).to.be.lessThan(500);
});
D. pm.test('Status and time', () => {
pm.expect(pm.response.status).to.equal('success');
pm.expect(pm.response.responseTime).to.be.lessThan(500);
});
Solution
Step 1: Check how to access JSON fields and response time
pm.response.json().status accesses the JSON 'status' field correctly. pm.response.responseTime gives response time in ms.
Step 2: Verify assertion methods
to.equal('success') checks the status value. to.be.below(500) correctly asserts response time less than 500ms.
Step 3: Identify incorrect options
pm.test('Status and time', () => {
pm.expect(pm.response.json().status).to.equal('success');
pm.expect(pm.response.time).to.be.below(500);
}); uses invalid pm.response.time. Options C and D use pm.response.status which is not the JSON field.
Final Answer:
pm.test('Status and time', () => {
pm.expect(pm.response.json().status).to.equal('success');
pm.expect(pm.response.responseTime).to.be.below(500);
}); -> Option A
Quick Check:
Use pm.response.json() and pm.response.responseTime for validation [OK]
Hint: Use pm.response.json() for data, pm.response.responseTime for timing [OK]
Common Mistakes:
Using pm.response.status instead of JSON field
Using wrong property for response time
Mixing to.be.below and to.be.lessThan incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.