0
0
Postmantesting~10 mins

REST API fundamentals review in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a GET request to a REST API endpoint to retrieve user data. It verifies that the response status is 200 OK and that the response body contains the expected user ID and name.

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

pm.test("Response has correct user data", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.id).to.eql(1);
    pm.expect(jsonData.name).to.eql("John Doe");
});
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Send GET request to https://api.example.com/users/1Postman sends HTTP GET request to the API endpoint-PASS
2Receive HTTP response from the serverResponse received with status code 200 and JSON body {"id":1,"name":"John Doe"}-PASS
3Check that response status code is 200Response status code is 200 OKpm.response.to.have.status(200)PASS
4Parse response JSON and verify user id and nameResponse JSON parsed as {id:1, name:"John Doe"}pm.expect(jsonData.id).to.eql(1) and pm.expect(jsonData.name).to.eql("John Doe")PASS
Failure Scenario
Failing Condition: Response status code is not 200 or user data does not match expected values
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify first after sending the GET request?
AThat the response status code is 200
BThat the response body contains a list of users
CThat the request method is POST
DThat the response time is less than 1 second
Key Result
Always verify both the HTTP status code and the response body content to ensure the API behaves as expected.