Search code examples
karateretry-logic

KarateFramework retry using in background


I'm trying to implement retry until the Scenario pass.

This code is working in the background or scenario :

* retry until response.status == 200

But my scenarios response codes are different like 200,204,404 I want to retry until the scenario pass not just a status code check. Because if I can't write in the background i must write this code to my every scenario.

Can i do that?


Solution

  • I don't recommend "reuse" for such a simple case. Please take some time and read this. Code duplication is OK. Really: https://stackoverflow.com/a/54126724/143475

    That said you can define a re-usable function and re-use it. Something like this:

    * def isStatusOk = function(x){ return x.status == 200 || x.status == 204 }
    

    And then you can do this:

    * retry until isStatusOk(response)
    

    And finally, please read this: https://twitter.com/KarateDSL/status/1364433453412851714