0
0
Postmantesting~10 mins

Chaining request data in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends two API requests in Postman. It verifies that data from the first response is correctly used in the second request, ensuring chaining of request data works.

Test Code - Postman
Postman
pm.test("Chaining request data test", function () {
    // First request: Get user info
    pm.sendRequest("https://jsonplaceholder.typicode.com/users/1", function (err, res) {
        pm.expect(err).to.be.null;
        pm.expect(res).to.have.property('status', 200);
        const userId = res.json().id;
        pm.expect(userId).to.eql(1);

        // Second request: Get posts by userId from first response
        pm.sendRequest({
            url: `https://jsonplaceholder.typicode.com/posts?userId=${userId}`,
            method: 'GET'
        }, function (err2, res2) {
            pm.expect(err2).to.be.null;
            pm.expect(res2).to.have.property('status', 200);
            const posts = res2.json();
            pm.expect(posts.length).to.be.greaterThan(0);
            // Check that all posts belong to userId
            posts.forEach(post => {
                pm.expect(post.userId).to.eql(userId);
            });
        });
    });
});
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsPostman test runner is ready to execute the test script-PASS
2Send first GET request to https://jsonplaceholder.typicode.com/users/1Browser/Postman sends HTTP GET request to user API endpointCheck response status code is 200PASS
3Parse JSON response and extract userIdResponse body contains user data with id=1Verify userId equals 1PASS
4Send second GET request to https://jsonplaceholder.typicode.com/posts?userId=1 using extracted userIdPostman sends HTTP GET request to posts API with userId query parameterCheck response status code is 200PASS
5Parse JSON response and verify posts belong to userId=1Response body contains array of posts with userId=1Verify posts array length > 0 and each post.userId equals 1PASS
6Test ends successfullyAll assertions passed, test completes-PASS
Failure Scenario
Failing Condition: If the first request fails or returns wrong userId, or second request returns no posts or posts with wrong userId
Execution Trace Quiz - 3 Questions
Test your understanding
What does the first request in this test do?
ASend posts data to server
BFetch user data and extract userId
CDelete a user
DUpdate user information
Key Result
Always verify that data extracted from one API response is correctly passed and used in subsequent requests to ensure reliable chaining.