0
0
Postmantesting~15 mins

Workflow sequencing in Postman - Build an Automation Script

Choose your learning style9 modes available
Verify API workflow sequencing for user registration and login
Preconditions (3)
Step 1: Send POST request to /register endpoint with valid user data
Step 2: Verify response status code is 201 Created
Step 3: Extract user ID from registration response
Step 4: Send POST request to /login endpoint with registered user credentials
Step 5: Verify response status code is 200 OK
Step 6: Verify response contains authentication token
✅ Expected Result: User registration succeeds with status 201, login succeeds with status 200, and authentication token is returned
Automation Requirements - Postman with JavaScript tests
Assertions Needed:
Status code is 201 for registration
Status code is 200 for login
Authentication token exists in login response
Best Practices:
Use environment variables to store and reuse user ID and token
Use pm.expect assertions for validation
Chain requests using Postman collection runner or scripts
Handle asynchronous requests properly
Automated Solution
Postman
/* Registration Request Test Script */
pm.test("Registration status code is 201", function () {
    pm.response.to.have.status(201);
});

// Save user ID from registration response
const jsonData = pm.response.json();
pm.environment.set("userId", jsonData.id);

/* Login Request Pre-request Script */
// Use stored user credentials
pm.variables.set("email", "testuser@example.com");
pm.variables.set("password", "TestPass123");

/* Login Request Test Script */
pm.test("Login status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Authentication token is present", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.have.property('token');
    pm.environment.set("authToken", jsonData.token);
});

The first part tests the registration response status code is 201, which means the user was created successfully. It extracts the user ID from the JSON response and saves it in an environment variable for reuse.

The login request uses stored user credentials. The test script verifies the login response status code is 200, indicating success, and checks that the response contains an authentication token. The token is saved for future requests.

This approach ensures the workflow sequence is automated: register first, then login using the registered user data. Using environment variables allows data sharing between requests. Assertions with pm.expect validate the expected outcomes.

Common Mistakes - 3 Pitfalls
Not waiting for registration response before sending login request
Hardcoding user data in multiple requests
Not checking response status codes before extracting data
Bonus Challenge

Now add data-driven testing with 3 different user registrations and logins

Show Hint