I am creating an animal into a database and then attempting to retrieve the animal which I have just created. However, there is a time lag ~5-10secs in the database. Therefore, a sleep wait is not suitable for this scenario as the response time varies.
I would like to poll the message until animalId is returned in the array. It is also important that the requestId header is re-generated when the request is re-tried.
What is the most elegant way of achieving this?
Scenario:
Given path '/animals'
And header requestId = uniqueString(5)
When method post
Then status 200
* def animalId = response.animalId
Given path '/animals'
And header requestId = uniqueString(5)
When method get
Then status 200
{
"animals": [
{
"animalId": "12219958",
"reference": [
"12345"
]
}
]
}
* def animalDetails = karate.jsonPath (response, "$.animals.[?(@.reference[0]== '" + animalId + "' )]")[0]
* def animalId = '12345'