如何在一定间隔内轮询请求并确定通过或失败

时间:2019-02-06 10:06:33

标签: cucumber karate

我的API请求如下:

* def reqCreate =  read('classpath:integration/create-request.json')

* def resCreate = read('classpath:integration/create-response.json')

* def personId = 12



 Given path '/person/' + personId
        And header Authorization = 'Bearer ' + accessToken
        When method get
        Then status 200
        Then match response == resCreate

我需要每隔5秒检查一次响应,直到一分钟为止。在任何一分钟或直到一分钟的任何时刻,如果响应断言为true,则最终结果为true,否则应在指定的持续时间后返回false。

1 个答案:

答案 0 :(得分:2)

在文档https://github.com/intuit/karate#retry-until

中对此有清楚的解释。
* configure retry = { count: 12, interval: 5000 }
Given url demoBaseUrl
And path 'greeting'
And retry until response.id > 3
When method get
Then status 200

在您的情况下:

Given path '/person/' + personId
And configure retry = { count: 12, interval: 5000 }
And header Authorization = 'Bearer ' + accessToken
And retry until response == resCreate
When method get
Then status 200

请不要忘记将您之前的问题标记为已回答,您还有很多未解决的问题。