karate - 通过重试重用功能文件,直到
问题描述
在空手道方面取得了惊人的成功。处理在 GET 上使用“重试直到”超时的端到端测试,以等待响应正文中的特定参数值。随着被测系统中数据处理的完成,预计该参数的状态会从 A 变为 B。.feature
由于对每个 API 路由一个模型进行了标准化,因此有兴趣了解模式。然而,这只有在我们可以参数化这些retry until
术语时才有可能。否则,这将意味着编写多个功能来支持不同的重试组合。
retry until
---评论重用的例子---
get_notification_ref.feature
要为每个until
组合维护一个而不是一个,until
请在调用中提供可由retry
.feature 内部使用的外部参数。
依赖于在 .feature 文件中指定 until 参数的实现。最终得到每个重试组合的 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 通知功能文件:
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
。
推荐阅读
- javascript - Chrome 扩展 - 将 chrome.cookies.get 变成一个变量
- context-free-grammar - CFG 语言
- java - 无法在 Java 中将图形添加到 JPanel
- java - Java 并发实践”清单 7.15. 为 LogWriter 添加可靠的取消。”。loggerThread.interrupt() 的意义何在?
- python - 在列表中添加项目不起作用
- ios - 在 SwiftUI 中,为什么由于 ObserverObject 更改而更新 View 会使 Navigation 自动弹出?
- python - 网站通过单击按钮发送哈希字符串
- python-3.x - 添加未知列表长度的元素 - Python
- javascript - 翻译 JavaScript 公式
- c++ - 如何将变量内容常量用作 std::array 的大小?