Newman - run collections in paralel

Create the new npm project

  • Intialize a proejct

    1
    npm init -y
  • Install dependencies:

    1
    npm i async newman path
  • Result example

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    {
    "name": "newman_parallel",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
    "start": "node index.js"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
    "async": "^3.1.0",
    "newman": "^4.5.6",
    "path": "^0.12.7"
    }
    }

Scripting

Steps

  1. Update the path for your postman collection and environment
  2. Sspecify the number of concurrent run you want to launch with the constant PARALLEL_RUN_COUNT
  3. Execute it with npm start

Example script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const path = require('path')
const async = require('async')
const newman = require('newman')

const PARALLEL_RUN_COUNT = 3

const parametersForTestRun = {
collection: path.join(__dirname, 'postman/postman_collection.json'),
environment: path.join(__dirname, 'postman/localhost.postman_environment.json'),
reporters: 'cli'
};

parallelCollectionRun = function (done) {
newman.run(parametersForTestRun, done);
};

let commands = []
for (let index = 0; index < PARALLEL_RUN_COUNT; index++) {
commands.push(parallelCollectionRun);
}

// Runs the Postman sample collection thrice, in parallel.
async.parallel(
commands,
(err, results) => {
err && console.error(err);
results.forEach(function (result) {
var failures = result.run.failures;
console.info(failures.length ? JSON.stringify(failures.failures, null, 2) :
'${result.collection.name} ran successfully.');
});
});