varkashy
varkashy

Reputation: 395

Karate how to loop through array and update path param

I need to do clean up after running my karate tests and invoke a clean up endpoint for all objects i created . Something of the sort of:

for all objects i created:
      invoke rest endpoint path/object.id

I followed Can we loop feature files and execute using multiple login users in karate

And also checked https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/callarray/call-json-array.feature

They allow to pass param in the request but not in the path param. I tried doing:

def result = call read(clean-up.feature) ids

But this fails as the clean-up.feature needs two params path and id

Given Path resourcePath ,  resourceId

I also tried

Given id: '#(ids)'
And path resourcePath, id   

and

Given path resourcePath,id: '#(ids)'        

But that doesn't work. Is there a way to do that?

Upvotes: 1

Views: 1045

Answers (1)

Babu Sekaran
Babu Sekaran

Reputation: 4239

you need to transform your ids to a valid JSON array

* def ids = [ "val1", "val4", "val5" ] 
* def ids = karate.mapWithKey(ids, 'id')
* def result = call read(clean-up.feature) ids

inside called feature

And path 'url' , 'context' , id   

refer: https://github.com/intuit/karate#json-transforms

Upvotes: 3

Related Questions