Karate has built-in support for re-trying an HTTP request until a certain condition has been met. The default setting for the max retry-attempts is 3 with a poll interval of 3000 milliseconds (3 seconds). If needed, this can be changed by using configure – any time during a test, or set globally via karate-config.js
* configure retry = { count: 10, interval: 5000 }
The retry
keyword is designed to extend the existing method
syntax (and should appear before a method
step) like so:
Scenario: get all employer details
Given def query = read('queryEmployers.graphql')
And request { query: '#(query)' }
And retry until response.id > 3
When method get
Then status 200
When method post
* print response
Then status 200
Any JavaScript expression that uses any variable in scope can be placed after the “retry until” part. So you can refer to the response, responseStatus or even responseHeaders if needed.
For example:
Given url demoBaseUrl
And path 'greeting'
And retry until responseStatus == 200 && response.id > 3
When method get