How to call my login 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')
Refer to the documentation on data-driven features . So if you have a JSON array, you can do something like this:
* def users = [{ username: 'foo1', password: 'bar1' }, { username: 'foo2', password: 'bar2' }]
* def login = call read('classpath:account/init/init-user.feature') users
edit : since the question was not clear, adding a comment and one more example:
And inside init-user.feature
you can just do * print __arg
Here is a an alternate way to iterate over a JSON array using a plain JavaScript function:
* 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.