Reputation: 1302
i am trying to execute postman collection using newman.js
because i need to extract the response and save to a file, below is the script i am using for that
var fs = require('fs'),
newman = require('newman'),
results = [];
newman.run({
reporters: 'cli',
collection: '/Users/prasad/Documents/migration/export_uuid_emails.postman_collection.json',
iterationData: '/Users/prasad/Documents/migration/test.csv',
//data: '/Users/prasad/Documents/migration/test.csv', // this also doesn't work
iterationCount: 1,
//iterationCount: 2, // this is iterting the same data two times
environment: '/Users/prasad/Documents/migration/stage.postman_environment.json'
}).on('request', function(err, args) {
if(!err) {
var rawBody = args.response.stream,
body = rawBody.toString();
results.push(JSON.parse(body));
}
}).on('done', function(err, summary) {
fs.writeFileSync('migration-report.json', JSON.stringify(results, null, 4));
});
below is the contents of test.csv
userId
0e4aab3a-62cb-4e23-8f44-40b1f1c5f9eb
a1d3e402-a83f-4918-9b7c-333d281be35d
below is the environment file
{
"id": "8e50b25f-df1a-4c15-abe9-1f8e4728da13",
"name": "stage",
"values": [
{
"key": "baseUrl",
"value": "https://stage.api.auth.aws.pen.com",
"enabled": true
},
{
"key": "accountStatus",
"value": "active",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2020-03-16T10:51:49.468Z",
"_postman_exported_using": "Postman/7.20.0"
}
According to the script it should execute for two userId's but it is always executing for only first userId, i tried with iterationCount with 2 but it's executing same id two times.
i followed newman documentation and a this reference
Can any one please help me on this ?
Thanks,
Prasad
Upvotes: 0
Views: 1981
Reputation: 1302
After trying in different ways then i figured that it's because of iterationCount: 1
when i changed that to iterationCount: 0
it started working.
Even if you don't provide iterationCount
whenever you are providing iterationData
then it is working.
Below is my understanding
No.of entries in test.csv
file are 3
So it's choosing those many no.of entries which is equal to iterationCount
if you don't specify any value then it's looping all entries which is 3 in this case.
i hope it will helpful for some other people
Upvotes: 1