5

Retry mechanism in karate testing framework How to retry tests on failure in karate testing framework like Junit and TestNG. something like public class Retry implements IRetryAnalyzer {

private int count = 0;
private static int maxTry = 3;

@Override
public boolean retry(ITestResult iTestResult) {
    if (!iTestResult.isSuccess()) {                      //Check if test not succeed
        if (count < maxTry) {                            //Check if maxtry count is reached
            count++;                                     //Increase the maxTry count by 1
            iTestResult.setStatus(ITestResult.FAILURE);  //Mark test as failed
            return true;                                 //Tells TestNG to re-run the test
        } else {
            iTestResult.setStatus(ITestResult.FAILURE);  //If maxCount reached,test marked as failed
        }
    } else {
        iTestResult.setStatus(ITestResult.SUCCESS);      //If test passes, TestNG marks it as passed
    }
    return false;
}

}

Rahul R
  • 125
  • 3
  • 7

2 Answers2

1

It works for me on version 0.9.5.RC5 . But, maybe this is one of the before-mentioned "workarounds"?

All you do is something like this, which defaults to 3 attempts:

* retry until responseStatus == 404
When method get

enter image description here

djangofan
  • 28,471
  • 61
  • 196
  • 289
  • 1
    `retry until` is not a "workaround" it is a legitimate feature introduced in v0.9.0 :P https://github.com/intuit/karate/releases/tag/v0.9.0 – Peter Thomas Dec 27 '19 at 18:08
  • I said "workaround" due to your previous comment where you linked to a page showing the 'retry' example and in your comment you said it was 'one of the workarounds' on that polling example page. – djangofan Dec 27 '19 at 19:26
  • that comment is almost 2 years old. not a "workaround" any more. pardon me for setting the record straight :) – Peter Thomas Dec 28 '19 at 01:50
0

As of now this is an open feature request: https://github.com/intuit/karate/issues/247

But there are multiple work arounds. You may get some ideas if you look at the polling example: https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/polling/polling.feature

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