空手道获得了惊人的成功。在GET上使用“重试直到”超时的端到端测试,以等待响应正文中的特定参数值。随着被测系统中数据处理的完成,预计该参数会将状态从A更改为B。由于已将每个API路由的模型标准化为.feature
,因此有兴趣学习模式。但是,只有在我们可以参数化retry until
项的情况下才有可能。否则,这将意味着编写多个功能来支持不同的重试组合。
---重用注释中的retry until
的示例---
要维护单个get_notification_ref.feature
而不是每个until
组合一个,请在调用中提供外部until
参数,这些功能可由[feature中的retry
使用。
实现依赖于在.feature文件中指定直到参数。最后得到每个重试组合的GET Notification功能文件:
Scenario: Get notification & wait for status
* call read('classpath:NotifyV1/get_notification_ref_wait_status.feature')
.
.
Scenario: Get notification & wait for status indicator colour
* def expectedColour = 'GREEN'
* call read('classpath:NotifyV1/get_notification_ref_wait_colour.feature')
get_notification_ref_wait_status.feature
Scenario: Get notification and wait on response status = 200
Given path 'notification', notificationTypeReference
And retry until responseStatus == 200
When method get
* def notificationResponse = $
get_notification_ref_wait_colour.feature
Scenario: Get notification and wait on response status = 200 and colour
Given path 'notification', notificationTypeReference
And retry until responseStatus == 200 && response.statusColour == expectedColour
When method get
* def notificationResponse = $
以上内容的实现,可以处理参数化重试,直到看起来像这样-注意现在只有一个GET Notification功能文件:
Scenario: Get notification & wait for status 200
* call read('classpath:NotifyV1/get_notification_ref.feature')
.
.
Scenario: Get notification & wait for status 200 and indicator colour
* def UntilTerm = function(response){ return karate.match(response, '{statusColour: "GREEN"}').pass }
* call read('classpath:NotifyV1/get_notification_ref.feature')
get_notification_ref.feature
Scenario: Get notification
* def untilTerm = karate.get('UntilTerm') ? UntilTerm : function(response){ return true }
* def untilStatus = karate.get('UntilStatus') ? UntilStatus : 200
Given path 'notification', notificationTypeReference
And retry until responseStatus == untilStatus && untilTerm(response)
When method get
* def notificationResponse = $
* karate.set('UntilTerm',null)
* karate.set('UntilStatus',null)
我想说retry until
可能就足够了。由于您可以调整默认时间和间隔,因此即使在需要的时候也可以进行不同的设置,即特定的HTTP调用:https://github.com/intuit/karate#retry-until
除非您确实真正有办法让外部流程回电-在这种情况下,您可以查看karate.signal()
和朋友。否则,我认为您最好还是坚持[C0]。