0
0
Postmantesting~10 mins

Example requests and responses in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a GET request to a sample API endpoint and verifies that the response status code is 200 and the response body contains the expected data.

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

pm.test("Response has expected user data", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.have.property('user');
    pm.expect(jsonData.user).to.have.property('id').that.is.a('number');
    pm.expect(jsonData.user).to.have.property('name').that.is.a('string');
});
Execution Trace - 3 Steps
StepActionSystem StateAssertionResult
1Test starts and sends GET request to https://api.example.com/user/1Postman sends HTTP GET request to the API endpoint-PASS
2Receives HTTP response from the serverResponse status code is 200, response body contains JSON with user dataCheck that response status code is 200PASS
3Parse JSON response bodyJSON object with user property is availableVerify response JSON has 'user' property with 'id' as number and 'name' as stringPASS
Failure Scenario
Failing Condition: Response status code is not 200 or response JSON does not contain expected user data
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify first after sending the request?
AThat the response status code is 200
BThat the response body is empty
CThat the request method is POST
DThat the response time is less than 1 second
Key Result
Always verify the response status code before checking the response body to ensure the API call was successful.