重试功能文件,直到重试

时间:2019-11-27 09:26:11

标签: karate intuit

空手道取得了惊人的成功。进行在GET上使用“重试直到”超时的端到端测试,以等待响应正文中的特定参数值。随着被测系统中数据处理的完成,预计该参数会将状态从A更改为B。由于对每个API路由一个.feature的模型进行了标准化,因此有兴趣了解模式。但是,只有在我们可以参数化retry until项的情况下才有可能。否则,这将意味着编写多个功能来支持不同的重试组合。

---重用评论中的retry until的示例---

要维护单个get_notification_ref.feature而不是每个until组合一个,请在调用中提供外部until参数,供retry使用.feature中的参数

实现依赖于在.feature文件中指定直到参数。最后得到每个重试组合的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 Notification功能文件:

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)

1 个答案:

答案 0 :(得分:1)

我想说retry until就足够了。由于您可以调整默认时间和间隔,因此即使在需要时也可以进行不同的设置,即特定的HTTP调用:https://github.com/intuit/karate#retry-until

除非您确实真正有办法让外部流程回电-在这种情况下,您可以查看karate.signal()和朋友。否则,我认为您最好坚持使用retry until