0
0
Postmantesting~10 mins

Reusable test scripts in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the reusable test script correctly validates the response status and content type for an API endpoint. It verifies that the response status is 200 and the content type is JSON.

Test Code - Postman
Postman
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Content-Type is application/json", function () {
    pm.response.to.have.header("Content-Type", /application\/json/);
});
Execution Trace - 3 Steps
StepActionSystem StateAssertionResult
1Test starts and sends API requestPostman sends HTTP request to the API endpoint-PASS
2Check if response status code is 200Response received with status code 200pm.response.to.have.status(200)PASS
3Check if Content-Type header includes 'application/json'Response headers include Content-Type: application/jsonpm.response.to.have.header("Content-Type", /application\/json/)PASS
Failure Scenario
Failing Condition: Response status code is not 200 or Content-Type header is missing or incorrect
Execution Trace Quiz - 3 Questions
Test your understanding
What does the first test in the script verify?
AResponse status code is 200
BResponse body contains JSON data
CResponse time is less than 200ms
DResponse header includes Authorization
Key Result
Using reusable test scripts in Postman helps quickly verify common response properties like status code and headers across multiple API requests, saving time and ensuring consistency.