0
0
Postmantesting~10 mins

Why chaining simulates real workflows in Postman - Test Execution Impact

Choose your learning style9 modes available
Test Overview

This test checks how chaining API requests in Postman simulates real user workflows by passing data from one request to the next and verifying the final result.

Test Code - Postman
Postman
pm.test("Chained API workflow test", function () {
    // Step 1: Send first request to create a user
    pm.sendRequest({
        url: 'https://api.example.com/users',
        method: 'POST',
        header: { 'Content-Type': 'application/json' },
        body: {
            mode: 'raw',
            raw: JSON.stringify({ name: 'Alice', role: 'tester' })
        }
    }, function (err, res) {
        pm.expect(err).to.be.null;
        pm.expect(res).to.have.property('code', 201);
        const userId = res.json().id;

        // Step 2: Use userId from first response to get user details
        pm.sendRequest({
            url: `https://api.example.com/users/${userId}`,
            method: 'GET'
        }, function (err2, res2) {
            pm.expect(err2).to.be.null;
            pm.expect(res2).to.have.property('code', 200);
            pm.expect(res2.json()).to.have.property('name', 'Alice');

            // Step 3: Update user role
            pm.sendRequest({
                url: `https://api.example.com/users/${userId}`,
                method: 'PUT',
                header: { 'Content-Type': 'application/json' },
                body: {
                    mode: 'raw',
                    raw: JSON.stringify({ role: 'admin' })
                }
            }, function (err3, res3) {
                pm.expect(err3).to.be.null;
                pm.expect(res3).to.have.property('code', 200);

                // Step 4: Verify updated role
                pm.sendRequest({
                    url: `https://api.example.com/users/${userId}`,
                    method: 'GET'
                }, function (err4, res4) {
                    pm.expect(err4).to.be.null;
                    pm.expect(res4).to.have.property('code', 200);
                    pm.expect(res4.json()).to.have.property('role', 'admin');
                });
            });
        });
    });
});
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Send POST request to create a new user with name 'Alice' and role 'tester'API server receives user creation requestResponse code is 201 CreatedPASS
2Extract userId from response and send GET request to fetch user detailsAPI server returns user details for userIdResponse code is 200 OK and user name is 'Alice'PASS
3Send PUT request to update user's role to 'admin' using userIdAPI server updates user roleResponse code is 200 OKPASS
4Send GET request to verify user's updated roleAPI server returns updated user detailsResponse code is 200 OK and role is 'admin'PASS
Failure Scenario
Failing Condition: If any API response returns an error or unexpected data, such as missing userId or wrong role
Execution Trace Quiz - 3 Questions
Test your understanding
Why does the test extract userId from the first response?
ATo test if the server returns errors
BTo use it in the next requests simulating a real user workflow
CTo ignore it and send random IDs later
DTo check if the user name is correct
Key Result
Chaining API requests in tests helps simulate real user workflows by passing data between steps and verifying the entire process, making tests more realistic and reliable.