Mejmo
Mejmo

Reputation: 2593

How to set delay between scenarios in karate?

I need to put delay between scenarios otherwise API is throwing response code of exceeding the limit (queries per second). Is it somehow possible to set some delay between scenarios? I would not like to put any javascript delay there, as there is no such thing because of single threading anyways. Is it?

Upvotes: 1

Views: 3499

Answers (1)

Peter
Peter

Reputation: 5164

Karate supports Java and JavaScript and since JavaScript doesn't have something like a sleep method, the only thing you can do is to load the Thread java type into JS and call sleep on that type.

This example configures a JS function to be called after every scenario:

Feature: A test to show how to wait between each scenario

  Background: Configure the wait function
    * configure afterScenario =
        """
      function() {
        // load java type into js engine
        var Thread = Java.type('java.lang.Thread');
        Thread.sleep(5000); // sleep for 5 Seconds
      }
      """

  Scenario: First Scenario
    * print 1

  Scenario: Second Scenario
    * print 2

Upvotes: 1

Related Questions