Verify the output block in Postman test script
Preconditions (2)
✅ Expected Result: The Postman console shows the response status code and the response body logged correctly in the output block
pm.test('Status code is 200', () => { pm.response.to.have.status(200); }); const responseBody = pm.response.json(); console.log('Response Status:', pm.response.code); console.log('Response Body:', responseBody); pm.test('Response body has userId', () => { pm.expect(responseBody).to.have.property('userId'); });
This script first checks if the response status code is 200 using pm.test and pm.response.to.have.status. Then it parses the response body as JSON and logs the status code and body to the Postman console using console.log, which acts as the output block. Finally, it asserts that the response body contains a key named userId. This approach helps verify the API response and outputs useful information for debugging.
Now add data-driven testing with 3 different API endpoints and verify their status codes and output blocks
Output block in Postman primarily display after running a request?console.log() is the standard way to log messages.print(), log(), and echo() are not valid in Postman scripts.pm.test('Status code is 200', () => {
pm.response.to.have.status(200);
});
console.log('Test completed');pm.test('Response time is less than 200ms', () => {
pm.expect(pm.response.responseTime).to.be.below(200);
});
console.log('Check complete');userId with value 5, and log 'User verified' only if the test passes. Which test script will correctly show this in the Output block?Pass the test and this pattern moves unknown