Rerun Failed Test Cases

Applies to ReadyAPI 3.57, last modified on December 20, 2024

You can use Groovy scripts to check for failed test cases and rerun them.

Where to use

Example

Groovy

import com.eviware.soapui.model.testsuite.TestRunner.Status

//Rerun failed test cases X amount of times based off the number set in the RerunCount test suite property
def reRunCount = Integer.parseInt(testSuite.getPropertyValue("RerunCount"))
def failTestSuite = false
for ( testCaseResult in runner.results ) {
  if ( testCaseResult.getStatus().toString() == 'FAIL' ){
    def tRun
    for (i = 0; i < reRunCount; i++) {
      tRun = testCaseResult.testCase.run(null, false) //Need to have "true" as the second argument
      log.info("Run..." + testCaseResult.getTestCase().name)
      
      if(tRun.getStatus().toString() == "PASS"){
        runner.status = Status.FINISHED //Change test suite status to PASS
        break;
      }
    }
    
    if(tRun.getStatus().toString() == "FAILED")
    {
      failTestSuite = true //If a test case is still failed after reruns, set the flag to fail the test suite and exit the loop
    }
  }
}

if(failTestSuite)
{
  runner.status = Status.FAILED //Change the test suite status to failed if the flag is set to fail the test suite
}

See Also

Groovy Scripting Samples
Scripting

Highlight search results