Karate - How to use sleep for scenarios?

Viewed 1211

I have scenario when i need to use sleep. But when I run this function I get ERROR. It working previously, but I didn't run this test long time ago and when I run this test again I get this error. This is one of my scenarios:

  Scenario: test sleep
    * def sleep = function(pause){ java.lang.Thread.sleep(pause*1000) }
    * url 'http://someURL:8080/api/v1/'

    Given path 'endpoint/' + 470538
    When method get
    Then status 200

    * call sleep(20)

Sleep function looks like working, but in the end of test I get test fail:

not a callable feature or js function: [type: NULL, value: null]

Could you help me please to resolve this issue?

1 Answers

There's no need for the call, please read the docs:

Scenario:
* def sleep = function(pause){ java.lang.Thread.sleep(pause*1000) }
* print 'before'
* sleep(5)
* print 'after'

That said - yes, call would work, but like this:

Scenario:
* def sleep = function(pause){ java.lang.Thread.sleep(pause*1000) }
* print 'before'
* call sleep 5
* print 'after'
Related