0
0
Postmantesting~15 mins

Why organizing requests improves workflow in Postman - Automation Benefits in Action

Choose your learning style9 modes available
Organize API requests into folders and verify workflow improvement
Preconditions (2)
Step 1: Open the existing collection with multiple API requests
Step 2: Create a new folder inside the collection named 'User Management'
Step 3: Drag and drop all user-related API requests into the 'User Management' folder
Step 4: Create another folder named 'Product Management'
Step 5: Move all product-related API requests into the 'Product Management' folder
Step 6: Save the collection
Step 7: Open the 'User Management' folder and run all requests sequentially
Step 8: Observe the order and ease of running grouped requests
Step 9: Open the 'Product Management' folder and run all requests sequentially
Step 10: Observe the order and ease of running grouped requests
✅ Expected Result: API requests are grouped logically into folders, making it easier to find and run related requests. Running requests in folders improves workflow by reducing time spent searching and organizing requests.
Automation Requirements - Postman Collection Runner with Newman
Assertions Needed:
Verify that requests are executed in the order defined by folders
Verify that all requests in 'User Management' folder return status code 200
Verify that all requests in 'Product Management' folder return status code 200
Best Practices:
Use folder structure in Postman collections to group related requests
Use Newman CLI to run collections and folders programmatically
Use assertions in Postman tests to validate response status and data
Keep collection organized for maintainability and collaboration
Automated Solution
Postman
const newman = require('newman');

// Run the 'User Management' folder
newman.run({
    collection: require('./MyCollection.json'),
    folder: 'User Management',
    reporters: 'cli'
}, function (err, summary) {
    if (err) { throw err; }
    const failures = summary.run.failures;
    if (failures.length > 0) {
        console.error('Some requests in User Management folder failed');
        process.exit(1);
    } else {
        console.log('All User Management requests passed');

        // After success, run the 'Product Management' folder
        newman.run({
            collection: require('./MyCollection.json'),
            folder: 'Product Management',
            reporters: 'cli'
        }, function (err2, summary2) {
            if (err2) { throw err2; }
            const failures2 = summary2.run.failures;
            if (failures2.length > 0) {
                console.error('Some requests in Product Management folder failed');
                process.exit(1);
            } else {
                console.log('All Product Management requests passed');
            }
        });
    }
});

This script uses Newman, the command-line tool for running Postman collections.

First, it runs all requests inside the 'User Management' folder. It checks if any request failed by inspecting summary.run.failures. If any request fails, it stops and reports the failure.

If all requests pass, it proceeds to run the 'Product Management' folder similarly.

This approach shows how organizing requests into folders allows running related requests together, improving workflow and test clarity.

Using Newman with folder option ensures only grouped requests run, matching the manual test case steps.

Common Mistakes - 3 Pitfalls
{'mistake': 'Running the entire collection without using folders', 'why_bad': 'It ignores the benefit of grouping requests, making it harder to isolate and run related tests.', 'correct_approach': "Use the 'folder' option in Newman to run specific groups of requests."}
Hardcoding request URLs or data inside the automation script
Not checking for failures after running requests
Bonus Challenge

Now add data-driven testing by running the 'User Management' folder with 3 different sets of environment variables

Show Hint