3

I am trying to loop over array values in a karate feature file. In a Feature1.feature - Scenario1, I have some values in the array ["UUID1","UUID2","UUID3"] and I want to call another feature file (Feature2.feature) (having a code to call a DELETE endpoint) of a service

Feature2.feature:

 @ignore

Feature: Delete

  Background:

    * url baseUrl
    * headers {content-type:'application/json'}

  Scenario: Delete Test Assets

    Given headers {uid: '#(UId)', cid:'#(CId)'}
    And path 'type', Type, 'id', AssetId
    When method delete
    Then status 204

What approach should I use to Feature1.feature to call the Feature2.feature in a loop?

1

1 Answer 1

4

If you have an array of primitives, you need to convert it into an array of JSON objects before doing a "loop call". Refer to the docs for karate.mapWithKey(): https://github.com/intuit/karate#json-transforms

So do this:

* def data =  ["UUID1","UUID2","UUID3"]
* def data = karate.mapWithKey(data, 'uid')
* call read('second.feature') data

And in second.feature:

* headers { uid: '#(uid)' }

Of course, read the docs for call if needed: https://github.com/intuit/karate#data-driven-features

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

1 Comment

This worked like a charm. That was actually what I wanted to do.Thanks @peter-thomas

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.