In my scenario I need to use Node as the operating environment and pass variables out of Newman and used from within the .js that will be executing the script to start the collection:
newman.run({
collection: require('./somename.postman_collection.json'),
reporters: ['cli', 'html']
delay: ['200']
}).on('beforeRequest', function (error, args) {
if (error) {
console.error(error);
} else {
fs.writeFile(`request.txt`, args.request.body.raw, function (error) {
if (error) {
console.error(error);
}
});
}
}).on('request', function (error, args) {
if (error) {
console.error(error);
}
else {
fs.writeFile(`response${getDateString()}.txt`, args.response.stream, function (error) {
if (error) {
console.error(error);
}
});
}
});
This .js will also be processing some data-files (which are the names of the variables that would be passed out of Newman) then use the new data-file (using appendFile to make multiple files one larger file) as input for the collection to be run. The alternative would be to use JS to make the HTTP:POST request and parse the JSON outside of Newman; however, this solution has eluded me as well. Any help would be GREATLY appreciated.