Forum Discussion

ZDGN's avatar
ZDGN
Contributor
4 years ago

Update proposal for rerun failed TestCases

Hi all,

 

Recently found this very usefull page: https://support.smartbear.com/readyapi/docs/samples/index.html with some awesome projects.

The "Rerun failed test steps sample" one was really interesting for my case, but...

 

Here is the original Tear Down groovy script:

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 ) {  
	log.info testCaseResult.getStatus().toString()	
	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
}

 

Something was feeling strange to me: why using a boolean for changing TestSuite status as it is already failed.

And also noticed that testCaseResult status was different using SoapUI or ReadyAPI.

Here is my updated scritp:

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"))
for ( testCaseResult in runner.results ) {
    /*
    * Dans SoapUI les statuts sont FINISHED ou FAILED
    * Dans ReadyAPI, les statuts sont PASS ou FAIL
    */
    if ( testCaseResult.getStatus().toString() == 'FAIL' || testCaseResult.getStatus().toString() == 'FAILED' ) {
        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;
            }
        }
    }
}

 

Just let me know if it helps or if you have any suggestions.

 

Have a nice day folks.

 

David.

No RepliesBe the first to reply