automationkarateweb-api-testing

Capture an ids from API-1 and pass it into another API-2 path and execute dynamically


[
    {
        "id": 1,
        "location": "usa"
    },
    {
        "id": 2322,
        "location": "japan"
    },
    {
        "id": 33,
        "location": "uk"
    }
]

I have captured the all locationIds into a variable called locationId. But, I need to iterate the list of locationId dynamically for another API path.

GETGET https://example.com/location/<idNo>

Eg:

Is this possible?

What is the right approact to implement the above example by using Karate Framework?


Solution

  • Here you go. Explained here: https://stackoverflow.com/a/75027059/143475

    Feature:
    
      @setup
      Scenario:
        * def data = [ { id: 1, location: 'usa' }, { id: 2322, location: 'japan' }, { id: 33, location: 'uk' } ]
    
      Scenario Outline:
        * url 'https://httpbin.org/anything'
        * path id
        * method get
    
        Examples:
          | karate.setup().data |