0
0
Postmantesting~10 mins

Data file with Newman in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test runs a Postman collection using Newman with a data file to provide multiple sets of input. It verifies that the API responds correctly for each data row.

Test Code - Newman
Postman
const newman = require('newman');

newman.run({
    collection: require('./example_collection.json'),
    iterationData: './data.json',
    reporters: ['cli']
}, function (err, summary) {
    if (err) { throw err; }
    const failures = summary.run.failures.length;
    if (failures > 0) {
        console.error(`${failures} tests failed.`);
        process.exit(1);
    } else {
        console.log('All tests passed.');
    }
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Newman starts running the Postman collection with the data file './data.json'.Newman CLI initializes and loads the collection and data file.-PASS
2Newman runs the first iteration using the first row of data from the data file.API request is sent with first data set; response received.Check if response status is 200 and response body matches expected values for first data row.PASS
3Newman runs the second iteration using the second row of data from the data file.API request is sent with second data set; response received.Check if response status is 200 and response body matches expected values for second data row.PASS
4Newman completes all iterations from the data file and summarizes results.Summary shows zero failures.Verify that no test failures occurred during any iteration.PASS
5Test script logs 'All tests passed.' and exits with success code.Console output confirms success.-PASS
Failure Scenario
Failing Condition: One or more iterations fail due to incorrect API response or assertion failure.
Execution Trace Quiz - 3 Questions
Test your understanding
What does the data file provide to Newman during the test run?
AThe test report format
BThe Postman collection structure
CMultiple sets of input data for iterations
DThe API server URL
Key Result
Using a data file with Newman allows running the same test multiple times with different inputs, improving test coverage and catching edge cases efficiently.