Whenever I run following from command line
newman run https://www.getpostman.com/collections/abcd1234
I get output displaying the statistics of failed and execute.
But I am looking for the complete HTML or JSON response from the URL to be printed on terminal after executing the above Newman query.How can I achieve this?
You have to add some log output in your requests.
For the requests where you want to see the response output add the following in the Postman Tests tab:
console.log(responseBody); // full response body
If you want to log a specific part you have to parse the response body into a JSON object:
let response = JSON.parse(responseBody);
console.log(reponse.myprop); // part of the full response body
Now if you run this collection with newman the CLI reporter will print the console log parts as well.
You need to use Postman API.
So you need to run something like this
newman run https://api.getpostman.com/collections/myPostmanCollectionUid?apikey=myPostmanApiKey
(see http://blog.getpostman.com/2018/06/21/newman-run-and-test-your-collections-from-the-command-line/)
You can get ApiKey in your Postman Cloud. You need to go to the workspace -> Integrations -> Browse Integrations -> Postman API View details -> Detail Get API Key/Existing API Keys
If you also need to add environment (if you use Variables), what you need is to run the same command with -e parameter 'newman run https://api.getpostman.com/collections/myPostmanCollectionUid?apikey=myPostmanApiKey -e dev_environment.json'
But what if you have your environment in the cloud as well? According to this document https://www.getpostman.com/docs/v6/postman/collection_runs/command_line_integration_with_newman you can pass URL as value. So you may run something like this
newman run https://api.getpostman.com/collections/myPostmanCollectionUid?apikey=myPostmanApiKey -e environments/{{environment_uid}}?apikey=myPostmanApiKey
It worked for me, hope this will help
I am using newman for webservices and microservices testing. This works fine for me.
summary.run.executions[0].response.text().toString()
After done event you should be able to get the response.
d is the collection exported from Postman.
newman.run({
collection: d,
// reporters: 'cli',
iterationCount: 1,
timeoutRequest: 10000,
timeoutScript: 5000,
delayRequest: 0,
insecure: false,
}).on('done', (err, summary) => {
if (err || summary.error) {
console.error('\ncollection run encountered an error.');
reject(summary.error);
}
else {
var xml = summary.run.executions[0].response.text().toString();
console.log(xml)
}
})
})