首页 > 解决方案 > 多条件重试疑难解答

问题描述

我目前有以下重试语句:

* retry until karate.xmlPath(response, '//ResultCount') == 1 && karate.xmlPath(response, '//Code') == 0

如果重试失败,则打印此消息:'too many retry attempts: 10'

我们面临的问题是:我们无法判断重试条件的哪一部分失败了。有没有人有什么建议?任何帮助表示赞赏!

我尝试过的几件事:

* 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

标签: karateretry-logicretrywhen

解决方案


我的建议是定义一个函数 - 然后使用它,因此它有助于分解和调试。此外,我正在展示另一种可能更强大的方式来获取响应。例如:

* 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


推荐阅读