Search code examples
apiautomationweb-api-testingkarate

Java programs are being run in the background itself even though i called the functions in the scenario outline in karate- cucumber


I needed to provide a delay between the two http calls, so i have created a java program and invoked the script between the two http calls in the scenario outline, But the java program is being executed in the background. Could some help in this.


Solution

  • I strongly discourage you from depending on Java code like this - because you will not be able to get the benefits of Karate's unique approach.

    Here's how you can use Java seamlessly from within Karate itself:

    * def sleep = function(millis){ java.lang.Thread.sleep(millis) }
    * print 'sleeping...'
    * call sleep 5000
    * print 'resumed'
    

    So once you have the function defined in say the Background, you can re-use it easily, that too with different values.

    It also sounds to me that you might be better off using polling, so do look at this also as a reference: polling.feature