1

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?

3
  • can you provide sample how does your ids looks like? Commented Jul 1, 2020 at 20:32
  • its an array [ "val1", "val4", "val5" ] Commented Jul 1, 2020 at 20:34
  • url path is something like url/context/val1 , url/context/val4 , url/context/val5 Commented Jul 1, 2020 at 20:35

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.