Groovy script to re-run failed tests
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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++ } } } }
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wow, that was a really quick reply
Well done, @Lucian! Thanks for sharing
Olga Terentieva
SmartBear Assistant Community Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
Customer Care Team
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry @Pochamen ,
Nothing new under the sun.
