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
  • 38,279
  • 56
  • 171
  • 280
Sourabh Chapali
  • 351
  • 6
  • 18

1 Answers1

6

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
  • 47,282
  • 14
  • 68
  • 196