Retry based on AssertionStep status
- 5 years ago
I managed to solve this specific problem, the opened support request shall remain open because I still suspect a problem with the .run() function.
Instead of trying to emulate the testRunner from inside the groovy step we now "drop an anchor" before the retry-cycle, run into the script and check the checkpoint status. If the status is FAIL we tell the testRunner to go back to the anchor via testRunner.gotoStep() - if the status is PASS we just let the TestCase continue on. Here is how that looks:
The anchor contains the number of remaining retry attempts, which are subtracted with each iteration by the ftpRetry-Script.
And here is the adapted ftpRetry function from the example.
void ftpRetry(def testRunner, def context){ // variables to allow user to specify other names List<String> retryCheckpointNames = ['retryCheckpoint'] List<String> retryAnchorNames = ['retryAnchor'] int defaultRetryCount = 15 ( checkpointStep, checkpointIndex ) = findStepInTestCase(context, true, retryCheckpointNames) ( anchorStep, anchorIndex ) = findStepInTestCase(context, true, retryAnchorNames) if(checkpointStep.getAssertionStatus().toString() != 'PASS') { // checkpoint did not pass, get the anchor, set the testRunner to the index of the anchor and subtract a retry from the anchor, then let everything run until this script is called again int retries = anchorStep.getPropertyValue('retries').toInteger() if(retries-- > 0) { anchorStep.setPropertyValue('retries', retries.toString()) testRunner.gotoStep(anchorIndex + 1) } else { anchorStep.setPropertyValue('retries', defaultRetryCount.toString()) assert false : "Out of retries, checkpoint-assertion failed every time!" } } else { log.info("Checkpoint passed, resetting retries on anchor.") anchorStep.setPropertyValue('retries', defaultRetryCount.toString()) } }
Should have reconsidered my approach to the problem rather than trying to force the script to emulate the testRunner, oh well.