Perform step(s) if test case fails

Hi all,

Is there a way to have Katalon Studio perform specific steps/keywords if the test case fails?
To clarify - I don’t mean failure handling which can be performed on specific steps, what I need is like a catch-all step that will be performed if the test case itself fails.

Thanks!

Maybe that will help you: How to extract the test status (Pass/Fail) of a test_case/test_suite into a variable
Combine that with SetUp/TearDown TS methods.

Hello,

this may be a solution - create another test case and call the original one in try-catch block

try {
	WebUI.callTestCase(findTestCase('Misc/FailedTC'), [:], FailureHandling.STOP_ON_FAILURE)
} catch (StepFailedException ex) {
	println "Test case has failed"
    // handle failure here
}

please use the below code :slight_smile:

//this is at Test steps level in test case

@TearDownIfFailed

public void Teardown(){
if(testCaseContext.getTestCaseStatus()== 'Failed'){

System.out.println("Test case is failed")
KeywordUtil.markPassed("Test case is failed")
WebUI.closeBrowser
}
}




//Create Listener for test case opr test suite

class TestBase {
	/**
	 * Executes before every test case starts.
	 * @param testCaseContext related information of the executed test case.
	 */
	@BeforeTestCase
	def sampleBeforeTestCase(TestCaseContext testCaseContext) {
		println testCaseContext.getTestCaseId()
		println testCaseContext.getTestCaseVariables()
	}

	/**
	 * Executes after every test case ends.
	 * @param testCaseContext related information of the executed test case.
	 */
	@AfterTestCase
	def sampleAfterTestCase(TestCaseContext testCaseContext) {
		println testCaseContext.getTestCaseId()
		println testCaseContext.getTestCaseStatus()
		
	}

	/**
	 * Executes before every test suite starts.
	 * @param testSuiteContext: related information of the executed test suite.
	 */
	@BeforeTestSuite
	def sampleBeforeTestSuite(TestSuiteContext testSuiteContext) {
		println testSuiteContext.getTestSuiteId()
	}

	/**
	 * Executes after every test suite ends.
	 * @param testSuiteContext: related information of the executed test suite.
	 */
	@AfterTestSuite
	def sampleAfterTestSuite(TestSuiteContext testSuiteContext) {
		println testSuiteContext.getTestSuiteId()
	}
}

Thanks to everyone for the help!
TearDownIfFailed is what I needed in my case.

1 Like