karate - 多条件重试疑难解答
问题描述
我目前有以下重试语句:
* retry until karate.xmlPath(response, '//ResultCount') == 1 && karate.xmlPath(response, '//Code') == 0
如果重试失败,则打印此消息:'too many retry attempts: 10'
我们面临的问题是:我们无法判断重试条件的哪一部分失败了。有没有人有什么建议?任何帮助表示赞赏!
我尝试过的几件事:
- 我无法为 ResultCount 和 Code 添加打印语句,因为如果重试失败,它将不会打印,这是有道理的,因为它在肥皂动作中失败了
- 我尝试将 && 分成两个不同的行,但这没有帮助,见下文:
* retry until karate.xmlPath(response, '//ResultCount') == 1
* retry until && karate.xmlPath(response, '//Code') == 0
即使第一个条件通过而第二个条件失败,但报告显示肥皂操作失败,所以我仍然无法判断哪个条件失败:
[passed] >> * retry until karate.xmlPath(response, '//ResultCount') >= 1
[passed] >> * retry until karate.xmlPath(response, '//Code') == 0 [it actually failed here]
[failed] >> * soap action 'http://mywebservice' too many retry attempts: 5
解决方案
我的建议是定义一个函数 - 然后使用它,因此它有助于分解和调试。此外,我正在展示另一种可能更强大的方式来获取响应。例如:
* def isValid =
"""
function() {
var resp = karate.get('response');
karate.log('testing response:', resp);
return karate.xmlPath(resp, '//ResultCount') == 1;
}
"""
# some code
* retry until isValid()
另请参阅此答案以获取更多想法:https ://stackoverflow.com/a/55823180/143475
推荐阅读
- android - 无法使用 pip 安装 PyAudio。无法通过 Web 安装 PyAudio 文件。Kindle/Fire OS 解决方法?
- core-data - 如何在核心数据中求和
- javascript - 如何直接从单击将数据传递给组件,或者在没有代理对象的情况下单击处理程序?
- javascript - 如果数组索引值小于 3,则隐藏按钮
- ms-access - 尽管有链接 MS-Access,但仍难以处理订单/订单详细信息子表单
- visual-studio - 在 IoT Edge 解决方案中指定 Deployment.template.json
- java - 使用提供而不是构造函数注入的视图模型的匕首多重绑定
- flutter - BottomNavigatonBar 的 onTap(index) 方法上的 SetState() 不会重建小部件树
- python - 如何避免 Python 中的语义错误?
- python - 如何通过多处理有效地迭代分割的图像?