4

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')
ehsan shirzadi
  • 4,709
  • 16
  • 69
  • 112

1 Answers1

2

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
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248