- Ensure that you have
node
andnpm
installed. - Install newman with:
npm install newman
. - Create a file with the following contents:
var fs = require('fs'),
newman = require('newman'),
results = [];
newman.run({
reporters: 'cli',
collection: '/path/to/collection.json',
environment: '/path/to/environment.json' // This is not necessary
})
.on('request', function (err, args) {
if (!err) {
// here, args.response represents the entire response object
var rawBody = args.response.stream, // this is a buffer
body = rawBody.toString(); // stringified JSON
results.push(JSON.parse(body)); // this is just to aggregate all responses into one object
}
})
// a second argument is also passed to this handler, if more details are needed.
.on('done', function (err, summary) {
// write the details to any file of your choice. The format may vary depending on your use case
fs.writeFileSync('migration-report.json', JSON.stringify(results, null, 4));
});
Here is another example:
var express = require('express');
var fs = require('fs');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json()); // Body parser use JSON data
app.post('/launches', function(req, res) {
var outputFilename = './spaceReport.json'; // path of the file to output
fs.writeFileSync(outputFilename, JSON.stringify(JSON.parse(req.body.payload), null, 4)); // write to the file system
res.send('Saved to ' + outputFilename);
});
var port = 3000;
app.listen(port);
console.log('Express started on port %d ...', port);
Hi,
I started working with Postman from couple of days and I have the below issue where I currently struck.
I have a GET request XML with parameters (no request body) which I have parameterrized and able to send the request with multiple data sets using csv file (using collection runner). But I need to save the response of each and every request, but I am not sure how to do it using a script. I need to save response in XML format to local drive. Can you please help me?
Sorry for late response. This can be best accomplished within Postman’s CLI companion, Newman. You would then write a script to generate your custom reports via the following steps:
1. Ensure that you have node and npm installed.
2. Install newman with: npm install newman.
Create a file with the following contents:
Run the file with:
node script.js # Here, script.js is the file created in the previous step
Wonderful, what a weblog it is! This weblog provides valuable information to us, keep it up.|
Is anyone here in a position to recommend Triangle bikinis? Thanks xox