【发布时间】:2019-11-12 20:52:06
【问题描述】:
我需要帮助才能在 Postman 中使用不同的机构反复执行 Post 请求。下面给出的示例,其中公司名称必须更改。最好从文档中读取公司名称,或者从脚本中的数组中读取。请建议我该怎么做?
{
"d": "{{company}}"
}
我发现了类似的东西,但出现错误:(There was an error in evaluating the Pre-request Script: TypeError: Cannot read property 'get' of undefined)
预请求脚本:
if(!companies){
companies = ["111",
"222",
"333"];
}
var currentCompany = companies.shift();
pm.enviroment.set("company",currentCompany);
pm.enviroment.set("companies", companies);
测试:
var companies = pm.enviroment.get("companies");
if(companies && companies.length > 0){
postman.setNextRequest("my url");
} else {
postman.setNextRequest(null);
}
【问题讨论】:
-
可以在Postman中使用pre-request脚本,搜索一下。
-
感谢您的评论,我已编辑问题,请检查问题所在。