3
如何在循环中调用我的登录函数?空手道 - 如何在循环中调用函数?
Feature: Validate correct user login
Background:
* call read('classpath:cleanup.feature')
* def login = call read('classpath:account/init/init.user.feature')
如何在循环中调用我的登录函数?空手道 - 如何在循环中调用函数?
Feature: Validate correct user login
Background:
* call read('classpath:cleanup.feature')
* def login = call read('classpath:account/init/init.user.feature')
请参阅data-driven features的文档。所以,如果你有一个JSON数组,你可以这样做:
* def users = [{ username: 'foo1', password: 'bar1' }, { username: 'foo2', password: 'bar2' }]
* def login = call read('classpath:account/init/init-user.feature') users
编辑:因为这个问题并不清楚,添加注释和一个例子:
而且里面init-user.feature
可以只是做* print __arg
下面是一个替代的方式使用纯遍历JSON数组JavaScript函数:
* def users = [{ username: 'foo1', password: 'bar1' }, { username: 'foo2', password: 'bar2' }]
* def fun = function(array){ for (var i = 0; i < array.length; i++) karate.log(array[i]) }
* call fun users
这不是我要求的,我想知道如何循环列表,例如在用户内部打印每个对象 –
第一部分是不正确的。请删除它 –
@HomayounBehzadian确定。 –