0
0
Postmantesting~10 mins

Response body inspection 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 body contains the expected user data in JSON format.

Test Code - Postman
Postman
pm.test("Response body contains user data", function () {
    pm.response.to.have.status(200);
    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 - 6 Steps
StepActionSystem StateAssertionResult
1Send GET request to https://api.example.com/user/123Request sent, waiting for response-PASS
2Receive response with status 200 and JSON bodyResponse body: {"user":{"id":123,"name":"Alice"}}Check response status is 200PASS
3Parse response body as JSONParsed JSON object available-PASS
4Verify response JSON has property 'user'JSON contains 'user' objectAssert jsonData has property 'user'PASS
5Verify 'user' object has numeric 'id''user.id' is 123Assert user.id is a numberPASS
6Verify 'user' object has string 'name''user.name' is 'Alice'Assert user.name is a stringPASS
Failure Scenario
Failing Condition: Response body does not contain 'user' property or 'user.id' is not a number
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test check first after receiving the response?
AThat the response body is empty
BThat the response body contains 'name'
CThat the response status is 200
DThat the response time is less than 1 second
Key Result
Always verify the response status code before inspecting the response body to ensure the API call was successful.