如何使用 newman.js 对整个数据执行postman收集?
问题.js
因为我需要提取响应并保存到文件中,所以下面是我使用的脚本
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));
});
下面是 test.csv 的内容
userId
0e4aab3a-62cb-4e23-8f44-40b1f1c5f9eb
a1d3e402-a83f-4918-9b7c-333d281be35d
下面是环境文件
{
"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"
}
根据脚本,它应该为两个 userId 执行,但它始终只为第一个 userId 执行,我尝试使用 2 执行迭代计数,但它为同一个 id 执行两次。
我遵循了纽曼的文档和参考资料,请问有人可以在这方面帮助我吗?
谢谢,普拉萨德
回答
在尝试了不同的方法之后,我想这是因为即使你不提供
下面是我的理解
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.
iterationCount
whenever you are providing
iterationData then it is working.
iterationCount: 1
when i changed that to
iterationCount: 0 it started working.
中的条目数
我希望这对其他人有帮助
页:
[1]