1

I am trying to test a scenario where I need to post a request 100 times (this is not a performance testing). I could use the table functionality by setting up each 100 rows, where each row represent a request. However this will be long tedious.

So I found Karate.repeat and was hoping this could solve the problem. I'm just wondering if there is another way to achieve my goal.

* def users = function(i){ call read("classpath:v1/createCustomer.feature") { "firstName": '#(firstName)', "lastName": '#(lastName)' }
* def usersResult = karate.repeat(2, users )
* match usersResult [*].responseStatus == [204, 204]

I expect the feature to be called twice.

Babu Sekaran
  • 4,129
  • 1
  • 9
  • 20
Patrick
  • 119
  • 1
  • 3
  • 14

1 Answers1

3

you should be able to use repeat for this, but instead of using call in DSL use karate.call

* def users = function(i){ return karate.call("classpath:v1/createCustomer.feature", { "firstName": '#(firstName)', "lastName": '#(lastName)' }) 
* def usersResult = karate.repeat(2, users ) 
* match each usersResult[*].responseStatus == 204

also suggest you to check data driven and dynamic scenario outline options in karate if you want different data to be used for each call. As you mentioned in the question instead of table for 100 rows of data you could use json array or csv to achieve the same.

Babu Sekaran
  • 4,129
  • 1
  • 9
  • 20
  • Thanks Babu, the above code worked. I prefer that technique than having to create an external csv file. This technique is neat and easy to understand – Patrick Jul 31 '19 at 09:39