【问题标题】:Postman setNextRequest in for-loop not getting called from Runner没有从 Runner 调用 for 循环中的邮递员 setNextRequest
【发布时间】: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


    【解决方案1】:

    邮递员中的 For 循环不起作用。

    每次您在 Create AccountProfile 中使用 setNextRequest(); 时,它都会在 Create AccountProfile 中的整个代码执行后转到 Create Account不仅是循环。因此,只会执行循环中的第一次执行。

    您可以通过另一种方式实现您所需要的。 您可以将数组存储在全局变量中,每次执行 Create AccountProfile 时,您都可以从中删除一项。

    【讨论】:

    • - 可能需要做一个变体,因为我不想不断地重新输入全局变量。我想我会将全局变量存储在集合变量中,并迭代地对集合变量进行切片。
    猜你喜欢
    • 1970-01-01
    • 2017-02-21
    • 2018-07-21
    • 1970-01-01
    • 2012-12-11
    • 2021-01-04
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    相关资源
    最近更新 更多