如何使用 newman.js 对整个数据执行邮递员收集?

How to execute postman collection using newman.js for entire data?


我正在尝试使用 newman.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"
}

根据脚本,它应该为两个用户 ID 执行,但它始终只为第一个用户 ID 执行,我尝试使用 iterationCount 和 2,但它执行相同的 ID 两次。
我关注了 newman documentation and a this reference
谁能帮我解决这个问题?
谢谢,
普拉萨德


在以不同的方式尝试之后,我认为这是因为 iterationCount: 1 当我将其更改为 iterationCount: 0 时它开始工作。
即使您在提供 iterationData 时不提供 iterationCount,它仍然有效。
以下是我的理解
No.of test.csv 文件中的条目是 3 因此,如果您未指定任何值,它会选择等于 iterationCount 的许多 no.of 条目,然后它会循环所有条目,在这种情况下为 3。


希望对其他人有所帮助