1

I have a use case, if the feature file that is currently running has failures in it then at the end of all scenarios, it should trigger another feature. Similar to AfterFeature hook

* configure afterFeature = function(){ karate.call('after-feature.feature'); }

but the only difference here is, it should only trigger when the feature has failure scenarios and not when all scenario is success.

Is there a way I can handle this in Karate ? The only reason I cannot put this in afterFeature is because the feature does a DB call for cleanup and it takes considerably longer time which is why I want to trigger this feature file only when there is failure

1 Answers1

1

You can use karate.scenario which has a failed property.

For those looking for documentation on this, there isn't much: https://github.com/karatelabs/karate/wiki/1.0-upgrade-guide#karateinfo-deprecated

Here is a simple feature you can try:

Feature:

Background:
* configure afterFeature = function(){ if (karate.scenario.failed) karate.log('*** failed') }

Scenario:
* assert 1 == 2

That said, here is my recommendation for "clean-up", don't do it "after the fact": https://stackoverflow.com/a/60944060/143475

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