使用Postman runner多次调用API进行基准测试

使用Postman runner多次调用API进行基准测试,postman,postman-collection-runner,postman-pre-request-script,Postman,Postman Collection Runner,Postman Pre Request Script,我正在编写一个新的API,希望能够看到它在遇到n个请求时是如何公平的 我曾尝试设置环境变量,并在Postman中使用runner工具,但没有效果 最终目标是运行它n次,我将[n]的值传递到主体中,以便我可以进行审计(该字段的值存储在数据库中) 我设置了2个环境变量 company=Bulk API Test requestcount=0 我的预请求脚本是 let requestCount = +postman.getEnvironmentVariable("requestcount"); if

我正在编写一个新的API,希望能够看到它在遇到n个请求时是如何公平的

我曾尝试设置环境变量,并在Postman中使用runner工具,但没有效果

最终目标是运行它n次,我将[n]的值传递到主体中,以便我可以进行审计(该字段的值存储在数据库中)

我设置了2个环境变量

company=Bulk API Test
requestcount=0
我的预请求脚本是

let requestCount = +postman.getEnvironmentVariable("requestcount");
if(!requestCount)
{
    requestCount = 0;
}

requestCount++;
postman.setEnvironmentVariable("requestcount", requestCount);
var currentCount = +postman.getEnvironmentVariable("requestcount");
if(currentCount < 5) // want it to run 5 times
{
    postman.setNextRequest("https://snipped");
}
else
{
    postman.setNextRequest(null);
}
每次都应该将环境变量requestcount更新为+1

我的测试脚本是

let requestCount = +postman.getEnvironmentVariable("requestcount");
if(!requestCount)
{
    requestCount = 0;
}

requestCount++;
postman.setEnvironmentVariable("requestcount", requestCount);
var currentCount = +postman.getEnvironmentVariable("requestcount");
if(currentCount < 5) // want it to run 5 times
{
    postman.setNextRequest("https://snipped");
}
else
{
    postman.setNextRequest(null);
}
var currentCount=+postman.getEnvironmentVariable(“requestcount”);
if(currentCount<5)//希望它运行5次
{
邮递员:setNextRequest(“https://snipped");
}
其他的
{
postman.setNextRequest(null);
}

当我通过运行程序运行它时,它需要比非运行程序执行更长的时间,结果是API只命中一次

如果您的API调用始终相同,请尝试使用postman runner的迭代计数。只要进入那里,例如5。您的收藏将重复5次

Cou无法通过以下属性访问迭代:

pm.info.iteration
找出它是哪个迭代

如果仍然需要执行变量,请确保它们被解析为整数

var currentCount =+ parseInt(postman.getEnvironmentVariable("requestcount"));

老实说:此基准测试的最佳方法是使用负载测试工具,例如Loadrunner,而不是Postman。

是的,但我需要在每次运行之间更改一个变量(增量为1)/iteration@adrewb我还添加了一个整数解析提示。如果从env或globals加载值,则必须将其解析为整数。这是必要的,因为postman将所有内容作为字符串存储在env和global变量中。