javascript - 没有从 Runner 调用 for 循环中的邮递员 setNextRequest
问题描述
集合有两个请求。
- 发布 - 创建帐户
- 发布 - 创建 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。因此,创建了一个具有一个帐户配置文件的帐户,仅此而已。
解决方案
邮递员中的 for 循环不起作用。
每次您在 Create AccountProfile 中使用时,它都会setNextRequest();
在 Create AccountProfile中的整个代码不仅执行循环之后转到Create Account 。因此,只会执行循环中的第一次执行。
你可以通过另一种方式实现你所需要的。您可以将数组存储在全局变量中,每次执行Create AccountProfile时,您都可以从中删除一项。
推荐阅读
- bash - 我可以对 BASH 中的条件使用多个 AND (&&) 运算符吗
- python - Python 的子进程在使用 PIPE 读取很长的输出时返回截断的输出
- javascript - AWS S3 上传完成时间限制
- kubernetes - Kubernetes - ReplicaSet 与 PodDisruptionBudget
- windows - NW.js Windows 10 任务栏图标始终显示为默认值
- java - 计算给定年份的平均价格
- python - 这是我应该如何在 discord.py 中使用“on_guild_join”吗?
- java - 制作定制的 guacamole Web 应用程序所需的配置
- ionic-framework - 我的 Visual Studio Code Intellisense 根本不起作用(Ionic/Angular 项目)
- ide - WebStorm 在编辑时保存文件