1

I am trying to fetch the list of dynamic id's one at a time by application ID as a parameter in GET URL

Example : below response is for POST call {"Car": 1, content:[{ "type" : "A" "Id" : "1" }, { "type" : "B" "Id" : "2" } ]}

Now for the above POST response I am trying to fetch the data using dynamic Id as a parameter in GET URL ex:

  • def ID = karate.jsonPath(response, '$.content[*].id') Given URL 'https://localhost:8080' And path '/'+ID+'/id When method GET Then status 200

in GET response I am getting list of Id's instead of single Id in URL as shown below This is the output : http://localhost:8080/1,2/id

As Id's are generating dynamically, so instead of calling one by one ID manually I want to call using parameter
Can any one suggest me how can I fetch one ID at a time using GET URL ?

cha dee
  • 33
  • 3

1 Answers1

0

Try this example, and observe the output and then try to understand how it works:

* def response = {"Car": 1, content:[{ "type" : "A", "Id" : "1" }, { "type" : "B", "Id" : "2" } ]}
* def ids = $response.content[*].Id
* match ids == ['1', '2']
* def data = karate.mapWithKey(ids, 'id')
* call read('called.feature') data

And called.feature looks like this:

@ignore
Feature:

Scenario:
* url 'https://httpbin.org/anything'
* param id = id
* method get

Please try to read the docs, it is worth it: https://github.com/karatelabs/karate#json-transforms

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248