【问题标题】:Troubleshooting Retry With Multiple Conditions多条件重试疑难解答
【发布时间】:2021-09-21 19:08:28
【问题描述】:

我目前有以下重试语句:

* 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

即使第一个条件通过,第二个条件失败,报告显示soap操作失败,所以我仍然无法判断哪个条件失败:

[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

【问题讨论】:

    标签: karate retry-logic retrywhen


    【解决方案1】:

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

    * 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-06
      • 2014-08-29
      • 2011-10-27
      相关资源
      最近更新 更多