Ask a Question

Groovy script to re-run failed tests

Lucian
Community Hero

Groovy script to re-run failed tests

As @Olga_T suggested here is a script which re-runs some failed tests. The script is put in the TearDown Script section at the project level.

 

def testSuiteResults = context.getTestRunner().getResults()
def testCaseResults
def runCount = 0
def testPassed = true

// Iterate through each test case in the project
testSuiteResults.each {
	it.getResults().each {
		// PASSED test case
		if ( it.getStatus().toString().equals("PASS") ) {
			log.info "The test case '" + it.getTestCase().getName() + "' has passed!"
		// FAILED test case
		} else {
			testPassed = false
			log.info "The test case '" + it.getTestCase().getName() + "' has failed!"
			// Rerunning the failed test case...
			while ((runCount < 2) && (testPassed == false)) {
				log.info "Rerunning the test one more time..."
// Ugly stuff. Sorry mom! if (it.getTestCase().run(new com.eviware.soapui.support.types.StringToObjectMap(), false).getStatus().toString().equals("PASS")) { testPassed = true log.info "The test has eventually passed!" } else { log.info "No luck... :(" } runCount++ } } } }


If my answer helped please click on the 'Accept as Solution' button.
6 REPLIES 6
Olga_T
SmartBear Alumni (Retired)

Wow, that was a really quick reply Smiley Happy

Well done, @Lucian! Thanks for sharing


Olga Terentieva
SmartBear Assistant Community Manager

Lucian
Community Hero

Well thanks! Nevertheless in order for this to be really helpful a solution would need to be found for https://community.smartbear.com/t5/SoapUI-Pro/ReExecution-Status-is-not-getting-Updated-from-test-su...

 

For now the execution status just stays as FAIL.



If my answer helped please click on the 'Accept as Solution' button.

Hi Lucian,

 

Your script works fine with my sample project (attached)! I'm not sure I can replicate the situation when "the execution status just stays as FAIL". Am I missing smth?

 

BTW, I'd correct the script so that it could rerun each TestCase until it passes, but not more than N times.

 

Clarifications are in the screenshot below:

2018-07-25_1524.png

 

Natalie
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

hey, sorry for the delayed response. well... even in your printscreen the TestCase 1 appears as red. So it doesn't matter that it eventually passed - it will be failed in the reports.

This is not very handy. If I would have an automated Jenkins build that build would not be green in the described situation.

I looked for a way to 'forget' the previous failed run of a particular test case but I didn't manage to find a solution...

I'm on the road now. Will give more clarifications later if needed.


If my answer helped please click on the 'Accept as Solution' button.
Pochamen
Occasional Visitor

Hi,

 

Did you manage to get a solution to jenkins automated builds? rerunning failing tests would get a green in my jenkins pipeline 🙂

 

Thanks in advance

Sorry @Pochamen ,

 

Nothing new under the sun.



If my answer helped please click on the 'Accept as Solution' button.
cancel
Showing results for 
Search instead for 
Did you mean: