在循环中调用特征,并将被调用特征中的一个变量作为迭代次数

Call feature in a loop and have one variable in the called feature as iteration number

我在循环中 N 次调用该功能(它有一些验证)。此代码有效并调用了我的功能 3 次。

* def xxx =
    """
      function(times){
         for(i=0;i<times;i++){
          karate.call('classpath:api/test/hello.feature');
        }
      }
    """

* call xxx 3

在我调用的功能文件中,第一行代码是:

* def someVariable = 0;
* def index = response[someVariable]
* some other code

我需要 someVariable 根据 i 索引进行更改。例如在循环中,第一次调用特征* def someVariable = 0;第二次调用* def someVariable = 1;第三次调用* def someVariable = 2;

如何实现?或者我可以在 JS 循环中添加这个变量吗?或者,也许可以使用 __loop(查看示例,但无法实现)。提前致谢。

我不确定我是否理解不正确,但为什么不直接将索引变量传递给 someVariable,例如

for(i=0;i<times;i++){
   someVariable = i
   ...
}

简答(不推荐):

karate.call('classpath:api/test/hello.feature', { someVariable: i });

推荐方法,阅读文档的这一部分(如果可以的话):https://github.com/intuit/karate#loops

然后再阅读这些答案: