1

Is there any way in karate to re-run only failed scenarios for UI test automation (or even in API as well) automatically, in same execution. I am using gradle as a build tool. This is the requirement at my side if any test get failed it should retry once again.

Also is the any way if we can skip stop() after every scenario of feature. and it could be called only after feature. so that single driver instance will work for all scenarios written in one feature file.

Please suggest.

Saurabh Garg
  • 135
  • 6

1 Answers1

4

This is not supported currently. It may be there in the next version but no guarantees. Some people consider re-tries to be bad testing practice, look it up.

But here is a possible workaround. If you can move your “flaky flow” into a feature (which should be the case already) you can call it via a “wrapper feature” and a JS function. Which can be enhanced to easily take arguments for the feature to call and number of re-tries. Here we make use of JS try-catch blocks.

* def fun =
"""
function() {
  for (var i = 0; i < 3; i++) {
    try {
      karate.call('flaky.feature');
      karate.log('*** call success !')
      return;
    } catch (e) {
      karate.log('try failed:', i, e);
    }
  }
  karate.fail('test failed after retries: ' + i); // karate.fail('message') is only in 0.9.6 onwards, you can also [throw 'message']
}
"""
* fun()

We will not support re-using a driver across multiple Scenario-s unless it is a called feature. See the comments here: callSingle for login in karate-config.js does not work as expected for Karate UI tests

Remember, Karate is open-source. Please consider contributing code if these are such high-priority features for you.

EDIT - also see: https://stackoverflow.com/a/66773839/143475

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