【问题标题】:Postman: How to make multiple requests at the same time邮递员:如何同时发出多个请求
【发布时间】:2016-07-09 12:00:43
【问题描述】:

我想发布来自 Postman Google Chrome 扩展程序的数据。

我想用不同的数据发出 10 个请求,而且应该同时进行。

在 Postman 中可以这样做吗?

如果是,谁能向我解释如何实现?

【问题讨论】:

  • 打开请求的文件夹并点击运行,您将看到一个选择迭代次数的选项:)

标签: post postman httprequest


【解决方案1】:

我猜邮递员没有运行并发测试这样的功能。

如果我是你,我会考虑Apache jMeter,它正好用于此类场景。

关于 Postman,唯一能或多或少满足您需求的是 - Postman Runner。 您可以在此处指定详细信息:

  • 迭代次数,
  • 上传包含不同测试运行等数据的 CSV 文件。

运行不会并发,只会连续运行。

希望对您有所帮助。但是请考虑使用 jMeter(你会喜欢它的)。

【讨论】:

  • Ray 评论中的网站已经迁移到 Wordpress.com,here is a working link
  • 错了 :) 因为 postman 中提供了此功能.. 打开请求的文件夹并单击运行,您将看到一个选择迭代次数的选项 :)
【解决方案2】:

Postman 不这样做,但您可以在 Bash 中异步运行多个 curl 请求:

curl url1 & curl url2 & curl url3 & ...

记得在每个请求之后添加&,这意味着请求应该作为异步作业运行。

但是,Postman 可以为您的请求生成 curl sn-p:https://learning.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets/

【讨论】:

  • 这太棒了——对真正的异步行为进行如此简单、出色的测试。
  • 这是最好的解决方案
  • 如果我需要数千个请求怎么办?
  • 邮递员链接上的这个解决方案有效。但是,对于每个 curl,您需要添加 switch curl -k & curl -k ...如果 curl 抱怨 https ssl 证书问题,尤其是在本地服务器上。
【解决方案3】:

我不知道这个问题是否仍然相关,但现在 Postman 有这种可能性。他们在几个月前添加了它。

您只需要创建简单的 .js 文件并通过 node.js 运行它。它看起来像这样:

var path = require('path'),
  async = require('async'), //https://www.npmjs.com/package/async
  newman = require('newman'),

  parametersForTestRun = {
    collection: path.join(__dirname, 'postman_collection.json'), // your collection
    environment: path.join(__dirname, 'postman_environment.json'), //your env
  };

parallelCollectionRun = function(done) {
  newman.run(parametersForTestRun, done);
};

// Runs the Postman sample collection thrice, in parallel.
async.parallel([
    parallelCollectionRun,
    parallelCollectionRun,
    parallelCollectionRun
  ],
  function(err, results) {
    err && console.error(err);

    results.forEach(function(result) {
      var failures = result.run.failures;
      console.info(failures.length ? JSON.stringify(failures.failures, null, 2) :
        `${result.collection.name} ran successfully.`);
    });
  });

然后运行这个 .js 文件(cmd 中的'node fileName.js')。

更多详情here

【讨论】:

  • 有没有办法在不使用命令行工具 newman 的情况下也可以通过 postman ui 实现并发请求测试?
  • 所以尝试了这段代码,它可以运行相同的集合_A;但是如果我有 2 个不同的集合(collection_A 和 collection_B)我想并行运行呢? options 参数将如何变化?你试过这个吗?该实验室提供的开箱即用功能似乎更多用于负载测试用例,但我想并行运行多个集合;像 collection_A 和 collection B 一样并行;有什么想法吗?
  • 我更愿意写一个 bash 脚本而不是那个 .js 文件
  • failures.failures throws undefined 对我来说,必须访问不同的属性,因为 failures 是一个数组。对我来说 failures[0].error.message 是要走的路
  • 尝试 node simple.js & node simple.js & node simple.js & node simple.js & node simple.js & node simple.js & node simple.js 运行多次跨度>
【解决方案4】:

不确定人们是否仍在寻找简单的解决方案,但您可以在 Postman 中运行“Collection Runner”的多个实例。只需创建一个带有一些请求的运行器,然后多次单击“运行”按钮即可调出多个实例。

【讨论】:

  • 这不会按照问题要求并行运行请求
  • 外婆;每个测试运行器实例将并行运行。
  • 问题是关于 1 个集合中的请求
【解决方案5】:

并行运行一个文件夹中的所有集合:

'use strict';

global.Promise = require('bluebird');
const path = require('path');
const newman =  Promise.promisifyAll(require('newman'));
const fs = Promise.promisifyAll(require('fs'));
const environment = 'postman_environment.json';
const FOLDER = path.join(__dirname, 'Collections_Folder');


let files = fs.readdirSync(FOLDER);
files = files.map(file=> path.join(FOLDER, file))
console.log(files);

Promise.map(files, file => {

    return newman.runAsync({
    collection: file, // your collection
    environment: path.join(__dirname, environment), //your env
    reporters: ['cli']
    });

}, {
   concurrency: 2
});

【讨论】:

    【解决方案6】:

    在邮递员的收集运行器中,您不能同时发出异步请求,因此请改用Apache JMeter。它允许您添加多个线程并为其添加同步计时器

    【讨论】:

      【解决方案7】:

      如果您只执行 GET 请求,并且需要在 Chrome 浏览器中使用另一个简单的解决方案,只需安装“打开多个 URL”扩展程序:

      https://chrome.google.com/webstore/detail/open-multiple-urls/oifijhaokejakekmnjmphonojcfkpbbh?hl=en

      我一次只运行了 1500 个 url,确实有点落后于谷歌,但它确实有效。

      【讨论】:

        【解决方案8】:

        最简单的方法是获取 => Google Chrome "TALEND API TESTER" 转到帮助 + 输入创建场景 ...或者直接访问此链接 => https://help.talend.com/r/en-US/Cloud/api-tester-user-guide/creating-scenario

        我能够同时发送多个 POST API 调用。

        【讨论】:

          【解决方案9】:

          为什么只将 Postman 用于此目的? 您可以使用任何语言 pythong、javascript 等编写脚本。 Python 为我做到了这一点

          【讨论】:

          • 如果您是一名测试人员并且不知道如何编码?你是做什么的?
          猜你喜欢
          • 2022-10-18
          • 1970-01-01
          • 2021-08-15
          • 2021-12-14
          • 2018-05-07
          • 2019-05-12
          • 2018-07-16
          • 2020-11-15
          • 2018-05-18
          相关资源
          最近更新 更多