如何通过for循环在Postman中创建多个请求?

问题描述 投票:1回答:1

我想按顺序使用变量('ID')向Postman发送请求到同一端点,该变量的值范围为1-10000。这就是我做的:

**JSON Request:**
{
    "UCPID": "{{ID}}",
    "Data": [
        {
            "Ref1":"LVM",
            "Ref2":"DLV",
            "Ref3":"DLV",
            "StartDate":"2016-05-08",
            "EndDate":"2016-05-12",
            ..
}
**In the Pre-request script:**
/*jshint loopfunc:true */

var count;
for(count = 0; count < 10000; count++){
    pm.globals.set("ID", count);
console.log("value:" + count);
//var jsonData = JSON.parse(responseBody);
//tests["ucp id = " + count] = true;              // debug message

pm.sendRequest("https://postman-echo.com/get", function (err, response) {
    console.log(response.json());
});
}

我预计这会跑10000次;相反,它只运行一次!我知道Postman允许CSV中的数据文件在Postman的Runner中传递;但我不想这样做,我的ID只是1到10000,我不想为此创建一个CSV ..我想以编程方式执行此操作!我错过了什么吗?谢谢!马特

postman
1个回答
0
投票

这是我在预请求脚本中所做的:

 pm.globals.set("ID", '\"'+Number(Math.floor(Math.random() * 1000)+1) +'\"');

因此我不再需要使用CSV了

© www.soinside.com 2019 - 2024. All rights reserved.