空手道 - 如何延迟所有场景?

时间:2017-10-31 06:32:30

标签: unit-testing karate

我有10个场景,所有这些场景在执行后台后都必须有1分钟的延迟。我在后台调用延迟功能。问题是所有场景都需要背景,我必须等待10分钟 有没有办法在所有场景中调用我的等待函数? 这是我的背景和我的一个场景:

  Background:
    * call read('classpath:cleanup.feature')
    * def login = call read('classpath:init/init.user.feature')
    * def sleep =
      """
      function(seconds){
        for(i = 0; i <= seconds; i++)
        {
          java.lang.Thread.sleep(1*1000);
          karate.log(i);
        }
      }
      """
    * call sleep 60

  Scenario: Correct
#    Step one: requesting a verification code
    Given url karate.get('urlBase') +  "account/resendMobileActivationVerificationCode"
    And request {"mobile": #(defaultMobile)}
    And header X-Authorization = login.token
    And header NESBA-Authorization = login.nesba
    When method post
    Then status 200
    And match response ==
  """
{
   "status":0,
   "message":"#(status0persianMessage)",
   "result": true
}
  """

1 个答案:

答案 0 :(得分:2)

使用callonce

* callonce sleep 60