[英]Karate - How to call a function in a loop?
如何循環調用我的登錄功能?
Feature: Validate correct user login
Background:
* call read('classpath:cleanup.feature')
* def login = call read('classpath:account/init/init.user.feature')
請參閱有關數據驅動功能的文檔。 因此,如果您有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
這是使用普通JavaScript函數迭代JSON數組的另一種方法:
* 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.