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確定。 –