ehsan shirzadi
ehsan shirzadi

Reputation: 4859

Karate - How to delay all scenarios?

I have a 10 scenarios, all of them must have 1 min delay after executing background. I call my delay function in background. The problem is that all scenarios call background, and I have to wait 10 minutes.
Is there a way to call my wait function one for all scenarios?
This is my background and one of my scenarios:

  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
}
  """

Upvotes: 5

Views: 12570

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Use callonce:

* callonce sleep 60

Upvotes: 7

Related Questions