So I tried the available solution provided online but I don't know where I am making a mistake. I am suppose to get the ids in an array that I am getting in response from an api and pass those ids in a loop to other api to get the response of each id for this I have written the below code.
Scenario Outline : Fetching booking details of ids via checkin/check out parameter
Given url 'https://restful-booker.herokuapp.com/booking'
And params { checkin : 2016-01-16, checkout : 2020-07-10 }
When method GET
Then status 200
And match response == '#notnull'
* def value = response
* def ids = karate.map(response, function(value){ var i = 0; var id = value[i].bookingid; i++; return id; })
And print 'Ids are' , ids
Given path 'https://restful-booker.herokuapp.com/booking'
And path '<ids>'
* header Accept = 'application/json'
When method GET
Then status 200
Examples:
| ids |
Its giving the error
javax.script.ScriptException: TypeError: Cannot get property "bookingid" of null in <eval> at line number 1
I am able to get the specific booking id in a variable by using
value[0].bookingid
But in a loop I am getting error. Any help would be appreciated. Thanks in advance!