Chethan Swaroop
Chethan Swaroop

Reputation: 192

Passing a JSON array while calling another feature file

As Per https://github.com/intuit/karate#data-driven-features when we pass a JSON array as an argument to the call of another feature file, the feature is invoked for each item in the array.

Is there a way to avoid this? I want to consider the complete JSON array as my request for another feature file Example:

[
 {
   "attr1" :"123",
   "attr2" :"456"
 },
 {
   "attr1" :"789",
   "attr2" :"101112"
 }
]

I'm currently passing this payload to another feature file as:

* call read('classpath:com/example/Test.feature') myReq

Now my Test.feature gets executed twice, once for each item in the JSON array. But my complete JSON array is to be passed as Request to Test.feature. How can we achieve this?

Upvotes: 1

Views: 1726

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Wrap it:

* def array = []
* def arg = { data: '#(array)' }
* call read('classpath:com/example/Test.feature') arg

Upvotes: 1

Related Questions