0

I have a scenario to conditional wait for every 5 secs for max 1 min. And I have implemented it via polling using java.lang.Thread.sleep(), which is blocking the Threads and failing in my multithread project. How can I use something like karate.pause() in my normal karate feature functions? Note: I can't use "retry until" in my case.

This is the method I use for polling with Thread.sleep(),

* def checkForEventCompletion =
      """
      function(arg) {
          var poolTime = 5;
          var counter = 1;
          // should pool for every 5 seconds until it exceeds your input wait time
          while (true) {
              if( (counter*poolTime) > arg.maxWaitTime){
                  karate.log('Status Not yet Updated');
                  return EventStatus;
              }
          //Code to Fetch EventStatus
          karate.log('Current Status->',EventStatus);
              if (EventStatus == 'COMPLETED') {
                  karate.log('Status Verified, --Exiting--');
                  return true;
              }
              // pool every 5 seconds
              java.lang.Thread.sleep(poolTime*1000);
              counter++;
          }
      }

When I try to use karate.pause(), it fails with "invokeMember (pause) on com.intuit.karate.core.ScenarioBridge@4acb7ecc failed due to: Unknown identifier: pause".

1 Answers1

0

Most likely because you are using an old version of Karate and pause() is only in 1.1.0.

And I think you have confused a lot of things, pause() is only for performance-testing using Gatling: https://github.com/intuit/karate/issues/1622

If you are looking for testing async flows, please refer this: https://twitter.com/KarateDSL/status/1417023536082812935

The above example gives you an way to "wait" or poll for something. An alternate way is this: https://stackoverflow.com/a/55823180/143475

Else - your question does not make sense, so please provide more info after following this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

And you can find an example of someone doing this here: https://github.com/intuit/karate/issues/1681

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248