Running a request in Postman multiple times with d

2020-06-18 03:41发布

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.

Pre-request script:

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);

Tests:

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.

Thanks!

1条回答
劫难
2楼-- · 2020-06-18 03:59

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

enter image description here

Then click to the Runner tab

enter image description here

Prepare csv file with data

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

And provide as data file, and run the sample.

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

enter image description here

查看更多
登录 后发表回答