[软件设计/软件工程] 如何使用 newman.js 对整个数据执行postman收集?

[复制链接]
发表于 2022-5-5 08:54:53
问题
.js
因为我需要提取响应并保存到文件中,所以下面是我使用的脚本
  1. var fs = require('fs'),
  2.     newman = require('newman'),
  3.     results = [];

  4. newman.run({
  5.         reporters: 'cli',
  6.         collection: '/Users/prasad/Documents/migration/export_uuid_emails.postman_collection.json',
  7.         iterationData: '/Users/prasad/Documents/migration/test.csv',
  8.         //data: '/Users/prasad/Documents/migration/test.csv', // this also doesn't work
  9.         iterationCount: 1,
  10.         //iterationCount: 2, // this is iterting the same data two times
  11.         environment: '/Users/prasad/Documents/migration/stage.postman_environment.json'
  12. }).on('request', function(err, args) {
  13.         if(!err) {
  14.                 var rawBody = args.response.stream,
  15.                  body = rawBody.toString();

  16.                 results.push(JSON.parse(body));
  17.         }
  18. }).on('done', function(err, summary) {
  19.         fs.writeFileSync('migration-report.json', JSON.stringify(results, null, 4));
  20. });
复制代码

下面是 test.csv 的内容
  1. userId
  2. 0e4aab3a-62cb-4e23-8f44-40b1f1c5f9eb
  3. a1d3e402-a83f-4918-9b7c-333d281be35d
复制代码

下面是环境文件
  1. {
  2.     "id": "8e50b25f-df1a-4c15-abe9-1f8e4728da13",
  3.     "name": "stage",
  4.     "values": [
  5.         {
  6.             "key": "baseUrl",
  7.             "value": "https://stage.api.auth.aws.pen.com",
  8.             "enabled": true
  9.         },
  10.         {
  11.             "key": "accountStatus",
  12.             "value": "active",
  13.             "enabled": true
  14.         }
  15.     ],
  16.     "_postman_variable_scope": "environment",
  17.     "_postman_exported_at": "2020-03-16T10:51:49.468Z",
  18.     "_postman_exported_using": "Postman/7.20.0"
  19. }
复制代码

根据脚本,它应该为两个 userId 执行,但它始终只为第一个 userId 执行,我尝试使用 2 执行迭代计数,但它为同一个 id 执行两次。

我遵循了纽曼的文档和参考资料,请问有人可以在这方面帮助我吗?

谢谢,普拉萨德

回答
在尝试了不同的方法之后,我想这是因为即使你不提供

下面是我的理解
  1. test.csv
  2. file are 3
  3. So it's choosing those many no.of entries which is equal to
  4. iterationCount if you don't specify any value then it's looping all entries which is 3 in this case.

  5. iterationCount
  6. whenever you are providing
  7. iterationData then it is working.

  8. iterationCount: 1
  9. when i changed that to
  10. iterationCount: 0 it started working.
复制代码

中的条目数

我希望这对其他人有帮助





上一篇:限制公网访问整个 WP 网站
下一篇:仅当输入数字时,如何才能使 socket.on 保持活动状态?

使用道具 举报

Archiver|手机版|小黑屋|吾爱开源 |网站地图

Copyright 2011 - 2012 Lnqq.NET.All Rights Reserved( ICP备案粤ICP备14042591号-1粤ICP14042591号 )

关于本站 - 版权申明 - 侵删联系 - Ln Studio! - 广告联系

本站资源来自互联网,仅供用户测试使用,相关版权归原作者所有

快速回复 返回顶部 返回列表