Save response in CSV file via newman

It looks like using Newman as a library, rather than from the command line with a specific reporter is going to be the option here.

You can tap into the different events and extract the data you want from the response and feed this into a CSV file.

The node ‘fs’ module will allow you to write the data into a file.

https://nodejs.org/api/fs.html

Just a hacky example piece of code and is not a finished or polished solution:

const newman = require('newman'),
      fs = require('fs')

newman.run({
  collection: '<Collection File>',
}).on('console', function (error, args) {
      fs.appendFileSync('./results.csv', args.messages, function (error) {
  })
})

Add this to your request:

let itemOne = "<location of value in the response>",
    itemTwo = "<location of value in the response>";

console.log(`\n${itemTwo},${itemOne}`)

This will save the console statements to a csv file, it has multiple limitations and you could do the same thing to get the dat via the request event and narrow it down to just a specific request but this was a quick hack :smiley:

2 Likes