使用不同的数据在 Postman 中多次运行请求只运行一次不同、数据、Postman

2023-09-08 08:51:58 作者:船到桥头自然沉

我是 Postman 的新手,遇到了一个我无法解决的反复出现的问题.我正在尝试使用在 Pre-request 脚本上建立的数据数组多次运行相同的请求,但是,当我转到运行器时,请求只运行一次,而不是 3 次.

I am new to Postman and running into a recurrent issue that I can’t figure out. I am trying to run the same request multiple times using an array of data established on the Pre-request script, however, when I go to the runner the request is only running once, rather than 3 times.

预请求脚本:

var uuids = pm.environment.get("uuids");

if(!uuids) {
uuids= ["1eb253c6-8784", "d3fb3ab3-4c57", "d3fb3ab3-4c78"];
}

var currentuuid = uuids.shift();
pm.environment.set("uuid", currentuuid);
pm.environment.set("uuids", uuids);

测试:

var uuids = pm.environment.get("uuids");

if (uuids && uuids.length>0) {
postman.setNextRequest(myurl/?userid={{uuid}});
} else {
postman.setNextRequest();
}

我查看了有关文档,但找不到我的代码有什么问题.

I have looked over regarding documentation and I cannot find what is wrong with my code.

谢谢!

推荐答案

预请求脚本不是测试不同数据的 api 的好方法.最好使用 Postman runner.

Pre-request script is not a good way to test api with different data. Better use Postman runner for the same.

首先,使用带有可变数据的邮递员准备一个请求.例如

First, prepare a request with postman with variable data. For e.g

然后点击 Runner 标签页

Then click to the Runner tab

用数据准备 csv 文件

Prepare csv file with data

uuids
1eb253c6-8784
d3fb3ab3-4c57
d3fb3ab3-4c78

并作为数据文件提供,并运行示例.

And provide as data file, and run the sample.

它将允许您使用不同的数据类型多次运行相同的 api,并且可以检查测试用例.

It will allow you run the same api, multiple times with different data types and can check test cases.