【发布时间】:2020-04-26 17:31:54
【问题描述】:
集合有两个请求。
- 发布 - 创建帐户
- 发布 - 创建 AccountProfile
创建 AccountProfile 将 AccountProfile 对象添加到 Account。
有 13 种帐户配置文件类型。
我想做的是创建 13 个帐户,每个帐户类型一个。
这是Tests 中用于第二种方法的Javascript。
暂时不要介意硬编码。我稍后会解决这个问题。
var acctProfiles = [0,1,4,5,6,19,33,34,35,38,39,40]
for (var p in acctProfiles ) {
// Create account with that profile
console.log('creating account');
postman.setNextRequest("Create Account");
console.log(pm.collectionVariables.get("accountToken"));
pm.collectionVariables.set("profileType", profiles[p]);
console.log('creating profile');
// Now call this request to create the profile
postman.setNextRequest();
}
我在集合运行器中运行了这个集合。
它成功运行每个请求,但只运行一次。
它只使用了数组中的最后一个元素 40。
因此,创建了一个具有一个帐户配置文件的帐户,然后就没有了。
【问题讨论】:
标签: javascript loops postman postman-collection-runner postman-pre-request-script