0
0
Postmantesting~10 mins

Response body assertions in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a GET request to an API endpoint and verifies that the response body contains the expected user data, including the user's name and email.

Test Code - Postman
Postman
pm.test("Response body contains correct user data", function () {
    const responseJson = pm.response.json();
    pm.expect(responseJson).to.have.property('name', 'John Doe');
    pm.expect(responseJson).to.have.property('email', 'john.doe@example.com');
});
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test startsPostman is ready to send the request-PASS
2Send GET request to API endpointRequest sent to https://api.example.com/users/123-PASS
3Receive response with status 200 and JSON bodyResponse body: {"id":123,"name":"John Doe","email":"john.doe@example.com"}Status code is 200PASS
4Parse response body as JSONParsed JSON object available for assertions-PASS
5Assert response JSON has property 'name' with value 'John Doe'Checking 'name' property in response JSONresponseJson.name === 'John Doe'PASS
6Assert response JSON has property 'email' with value 'john.doe@example.com'Checking 'email' property in response JSONresponseJson.email === 'john.doe@example.com'PASS
7Test endsAll assertions passed-PASS
Failure Scenario
Failing Condition: Response JSON does not contain the expected 'name' or 'email' properties with correct values
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the response body?
AIt confirms the response body is empty.
BIt verifies the response status code is 404.
CIt checks that the response JSON contains the correct 'name' and 'email' properties.
DIt checks that the response headers contain 'Content-Type: text/html'.
Key Result
Always assert specific properties and their expected values in the response body to ensure the API returns correct data.