I can't seem to frame my question correctly to get a useful answer.
I have a Postman collection. I have exported it as a JSON and I want to use node.js/newman to run it in several parallel instances to validate a fix for some code that wasn't thread safe.
I got a sample script (shown below) and made some small mods for my needs. I installed node.js and populated the registry with common libraries. (package.json shown below)
I type node loadTest.js and the script runs and executes all my calls.
I want to display and/or save the response body so I can go over the data in the response and I'm having a bit of trouble figuring out how to do that. I have very little familiarity with this environment (node.js) so I'm finding no useful answers.
Sample script with mods.
async = require('async'),
newman = require('newman'),
json = require('json'),
/**
* Collection run options.
*
* @type {Object}
*/
development = {
collection: path.join(__dirname, 'developmentserver.json'),
reporters: 'cli'
},
test = {
collection: path.join(__dirname, 'testserver.json'),
reporters: 'cli'
},
/**
* Collection runners.
*
* @param {Function} done - A callback function that marks the end of the current collection run, when called.
*/
devCollectionRun = function (done) {
newman.run(development, done);
};
testCollectionRun = function (done) {
newman.run(test, done);
};
/**
* Execute collection runs.
*/
async.parallel([
devCollectionRun,
devCollectionRun,
devCollectionRun
],
function (err, results) {
err && console.error(err);
results.forEach(function (result) {
var failures = result.run.failures;
var outp = result.collection.name + ' ran successfully.';
console.info(failures.length ? JSON.stringify(failures.failures, null, 2) : outp);
});
});
package.json
{
"name": "loadtest",
"version": "1.0.0",
"main": "loadTest.js",
"scripts": {
"test": "loadTest"
},
"author": "",
"license": "ISC",
"keywords": [],
"description": "runs load test package",
"dependencies": {
"async": "^3.2.4",
"cli": "^1.0.1",
"console": "^0.7.2",
"json": "^11.0.0",
"newman": "^5.3.2",
"newman-reporter-json-summary": "^1.0.14"
}
}
Edit: (Added here because it's just a wall of text in a comment)
I ended up adding the log statements in the collection json in the "exec" section like:
"script": {
"exec": [
"pm.test(\"Status must not equal E\", function () {\r",
" var jsonData = pm.response.json();\r",
" pm.expect(jsonData[0].STATUS_FLAG).not.to.eql(\"E\");\r",
" console.log(\"Case Number: \" + jsonData[0].CASE_NO);\r",
" console.log(\"Address: \" + jsonData[0].EAP_ADDRS);\r",
" console.log(\"Value: \" + jsonData[0].AVM_VALUE);\r",
"});"
],
"type": "text/javascript"
}
If there is a better way to do this I would love to hear it, but this works well enough for my purpose.