2

I used following option

* def sleep =
      """
      function(seconds){
        for(i = 0; i <= seconds; i++)
        {
          java.lang.Thread.sleep(1*1000);
          karate.log(i);
        }
      }
      """
* call sleep 10

But I want to understand if there is a better in-built way to do the same. Also want to know if static wait can be added

  • In between scenario
  • In between steps of a scenario
  • In between feature files
  • etc.
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Sourabh Chapali
  • 361
  • 2
  • 7
  • 18

1 Answers1

7

I think what you are doing is fine. Search for "sleep" in the readme you will find this:

* def sleep = function(millis){ java.lang.Thread.sleep(millis) }
* sleep(1000)

The answer to the second part of your question is hooks: https://github.com/intuit/karate#hooks

I would NEVER do this, but as an example if you do * java.lang.Thread.sleep(1000) in the Background - it will sleep before each `Scenario.

EDIT - please look at the RuntimeHook for advanced use-cases: https://stackoverflow.com/a/59080128/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248