重复使用特征文件并重试直到
Reuse of feature files with retry until
空手道取得了惊人的成功。处理在 GET 上使用 'retry until' 超时的端到端测试,以等待响应正文中的特定参数值。当被测系统中的数据处理完成时,预计该参数会将状态从 A 更改为 B。由于对每个 API 路线一个 .feature
的模型进行了标准化,因此有兴趣了解模式。然而,这只有在我们可以参数化 retry until
项时才有可能。否则这将意味着编写多个功能来支持不同的重试组合。
---从评论中重用retry until
的例子---
要维护一个 get_notification_ref.feature
而不是每个 until
组合一个,请在调用中提供外部 until
参数,供 retry
在.feature.
依赖于在 .feature 文件中指定 until 参数的实现。结束每个重试组合的 GET 通知功能文件:
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 通知功能文件:
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()
和朋友。否则我认为你最好坚持 retry until
.
空手道取得了惊人的成功。处理在 GET 上使用 'retry until' 超时的端到端测试,以等待响应正文中的特定参数值。当被测系统中的数据处理完成时,预计该参数会将状态从 A 更改为 B。由于对每个 API 路线一个 .feature
的模型进行了标准化,因此有兴趣了解模式。然而,这只有在我们可以参数化 retry until
项时才有可能。否则这将意味着编写多个功能来支持不同的重试组合。
---从评论中重用retry until
的例子---
要维护一个 get_notification_ref.feature
而不是每个 until
组合一个,请在调用中提供外部 until
参数,供 retry
在.feature.
依赖于在 .feature 文件中指定 until 参数的实现。结束每个重试组合的 GET 通知功能文件:
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 通知功能文件:
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()
和朋友。否则我认为你最好坚持 retry until
.