Hi All,
I am new to Postman.
According to article.
I want to save requests and responses of each iteration data.
Could anyone please help me…!
My current Java script is overwriting the saved request and response file for each iteration.
Please have a look at my script:
const newman = require(‘newman’),
fs = require(‘fs’);
const fileName = Math.random().toString(36).substring(7) + ‘-Automation_Family_request.json’;
const fileName_1 = Math.random().toString(36).substring(7) + ‘-Automation_Family_response.json’;
newman.run({
collection: require(’./Automation_Family.postman_collection.json’),
environment: require(’./urlogi.postman_environment.json’),
globals: require(’./Globalenv.postman_globals.json’),
iterationData: require(’./Family.json’),
iterationCount: 192,
insecure: true,
reporters: ‘cli’
}).on(‘beforeRequest’, function (error, args) {
if (error) {
console.error(error);
} else {
fs.writeFile(fileName, args.request.body.raw, function (error) {
if (error) {
console.error(error);
}
});
}
}).on(‘request’, function (error, args) {
if (error) {
console.error(error);
}
else {
fs.writeFile(fileName_1, args.response.stream, function (error) {
if (error) {
console.error(error);
}
});
}
});
Thanks in advance.