Bird
Raised Fist0
Postmantesting~15 mins

Collection runner results in Postman - Build an Automation Script

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Run a Postman collection and verify the results
Preconditions (3)
Step 1: Open the Postman app
Step 2: Select the collection to run
Step 3: Click the 'Run' button to open the Collection Runner
Step 4: In the Collection Runner, click 'Start Run' to execute all requests
Step 5: Wait for the collection run to complete
Step 6: Observe the results summary showing number of requests, passed tests, and failed tests
✅ Expected Result: The collection runner completes all requests, showing a summary with the total requests run, number of passed tests, and number of failed tests. Each request's test results are displayed correctly.
Automation Requirements - Newman (Postman CLI)
Assertions Needed:
Verify the total number of requests run matches the collection size
Verify all tests in each request pass
Verify the summary shows zero failed tests
Best Practices:
Use Newman CLI to run collections programmatically
Parse the JSON output from Newman to assert test results
Use explicit assertions on summary statistics
Handle asynchronous execution properly
Automated Solution
Postman
import { exec } from 'child_process';

const collectionPath = './my_collection.json';

exec(`newman run ${collectionPath} -r json`, (error, stdout, stderr) => {
  if (error) {
    console.error(`Execution error: ${error}`);
    process.exit(1);
  }

  try {
    // Newman outputs JSON report after the run
    const outputStart = stdout.indexOf('{');
    const outputJson = stdout.substring(outputStart);
    const result = JSON.parse(outputJson);

    const totalRequests = result.run.stats.requests.total;
    const totalTests = result.run.stats.tests.total;
    const failedTests = result.run.stats.tests.failed;

    console.assert(totalRequests === result.run.executions.length, `Expected total requests ${result.run.executions.length}, got ${totalRequests}`);
    console.assert(failedTests === 0, `Expected 0 failed tests, got ${failedTests}`);

    console.log('Collection run successful with all tests passing.');
  } catch (parseError) {
    console.error('Failed to parse Newman JSON output:', parseError);
    process.exit(1);
  }
});

This script uses Node.js child_process.exec to run Newman CLI with the -r json reporter, which outputs the collection run results in JSON format.

It captures the standard output, extracts the JSON part, and parses it to an object.

Assertions check that the total number of requests run matches the number of executions and that there are zero failed tests.

If assertions pass, it logs success; otherwise, it throws an error.

This approach automates running the Postman collection and verifying the collection runner results programmatically.

Common Mistakes - 3 Pitfalls
Parsing Newman output as plain text without extracting JSON
Not asserting the number of requests run
Ignoring failed tests count in assertions
Bonus Challenge

Now add data-driven testing by running the collection with three different environment files

Show Hint

Practice

(1/5)
1. What information does the Postman Collection Runner primarily show after running a collection?
easy
A. The source code of the API server
B. Only the request URLs
C. Status codes, response bodies, and test pass/fail results
D. User login credentials

Solution

  1. Step 1: Understand Collection Runner output

    The Collection Runner shows results of running multiple API requests together, including status codes, response bodies, and test results.
  2. Step 2: Identify what is NOT shown

    It does not show server source code, only URLs, or user credentials.
  3. Final Answer:

    Status codes, response bodies, and test pass/fail results -> Option C
  4. Quick Check:

    Collection Runner output = status codes + responses + test results [OK]
Hint: Remember: Collection Runner shows results, not server code [OK]
Common Mistakes:
  • Thinking it shows server source code
  • Confusing request URLs with results
  • Expecting user credentials in results
2. Which of the following is the correct way to export Collection Runner results in Postman?
easy
A. Click the 'Export Results' button after running the collection
B. Right-click the collection and select 'Export Results'
C. Use the Postman console to save results manually
D. Results cannot be exported from Postman

Solution

  1. Step 1: Locate export option after running collection

    After running a collection in the Collection Runner, a button labeled 'Export Results' appears to save the run data.
  2. Step 2: Confirm other options are incorrect

    Right-clicking the collection does not export results, console is for logs, and results can be exported.
  3. Final Answer:

    Click the 'Export Results' button after running the collection -> Option A
  4. Quick Check:

    Export button appears after run [OK]
Hint: Export results only after collection run completes [OK]
Common Mistakes:
  • Trying to export before running collection
  • Using console logs to export results
  • Assuming export is unavailable
3. After running a collection with 3 requests, the Collection Runner shows these status codes: 200, 404, 200. What does this indicate?
medium
A. All requests succeeded
B. One request failed with 'Not Found' error
C. All requests failed
D. The collection did not run

Solution

  1. Step 1: Interpret HTTP status codes

    Status code 200 means success; 404 means 'Not Found' error indicating failure for that request.
  2. Step 2: Analyze the sequence of codes

    Two requests succeeded (200), one failed (404), so not all succeeded.
  3. Final Answer:

    One request failed with 'Not Found' error -> Option B
  4. Quick Check:

    200 = success, 404 = failure [OK]
Hint: 200 means success; 404 means resource missing [OK]
Common Mistakes:
  • Assuming all requests succeeded
  • Confusing 404 with success
  • Ignoring mixed status codes
4. You ran a collection but the Collection Runner shows no results and an error message. What is the likely cause?
medium
A. Postman is offline or disconnected
B. The collection has no requests
C. You forgot to click the 'Run' button
D. The API server returned 500 errors

Solution

  1. Step 1: Understand why no results appear

    If Postman is offline or disconnected, it cannot run requests, so no results show.
  2. Step 2: Check other options

    Clicking 'Run' is required but error message suggests connection issue; empty collection or server errors still produce results.
  3. Final Answer:

    Postman is offline or disconnected -> Option A
  4. Quick Check:

    No results + error = connection problem [OK]
Hint: Check internet connection if no results appear [OK]
Common Mistakes:
  • Assuming forgot to click run
  • Thinking empty collection causes error
  • Confusing server errors with no results
5. You want to share your Collection Runner results with a teammate. Which method ensures they see the exact test pass/fail details and response data?
hard
A. Copy only the request URLs and share
B. Take a screenshot of the Collection Runner window
C. Send the collection file without running it
D. Export the results as a JSON file and send it

Solution

  1. Step 1: Identify how to share detailed results

    Exporting results as JSON includes all test pass/fail info and response data for exact sharing.
  2. Step 2: Evaluate other options

    Screenshots may miss details, sending collection without run lacks results, URLs alone miss responses and tests.
  3. Final Answer:

    Export the results as a JSON file and send it -> Option D
  4. Quick Check:

    JSON export = full detailed results [OK]
Hint: Export results JSON for full detail sharing [OK]
Common Mistakes:
  • Relying on screenshots only
  • Sharing collection without results
  • Sharing URLs without responses