1
votes

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?

1
can you provide sample how does your ids looks like?Babu Sekaran
its an array [ "val1", "val4", "val5" ]varkashy
url path is something like url/context/val1 , url/context/val4 , url/context/val5varkashy

1 Answers

2
votes

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