Sourabh Chapali
Sourabh Chapali

Reputation: 391

How to add a static wait in between a step within a scenario?

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

Upvotes: 2

Views: 16239

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

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

Upvotes: 8

Related Questions