Test Case failure handling/options

Hey folks,
Is there a quick way to write a code that handles test case failure and can take another actionn when a test case fails?

So I know I can use “CONTINUE_ON_FAILURE” on every step… but looking for a Test Case solution.

Something in this method:
If this test case fails
{call on test case 2}

or something like
if this testcase fails
{delete the data created}

import com.kms.katalon.core.exception.StepFailedException
try {
    //Something in this method
} catch (StepFailedException ex) {
    //call on test case 2
} finally {
    //delete the data created

how would this try-catch block know if the test case failed, not just a test step? let’s say the test failed at any given steps… once the test case fails (at any step), I need the test to do something.
I basically needs to know the result of the test case fail… is there a way to get that?

i was thinking something along this line:
def status = test case?
If status of test case == ‘Fail’
// then do this
//do this

does that make sense?

Have you tried what I suggested?

May be not.

If you want to ask further, please try what you were suggested to do. Otherwise I can not continue.

I suppose you don’t understand the basic of Java Programing language: Exception, try { … } catch { … } .

Unless you understand what Exception is, how try {} catch {} works, you would not be able to reach to a solution. You should buy a good Java book, such as Core Java I, and read the first few chapters.

1 Like

No, you can not.

When a Katalon Test Case failed, almost always it will NOT gently return any result. It will just throw an StepFailedException and disappear.

The closest you can get to what you want is to use something like the following…

First, let’s look at how a typical test case is presented:

// Imports

// Step 1

// Step 2
// Step n

To gain some control over all steps AND “take another action when a test case fails”, you can give Katalon a single entry point into your own class. Technically, this is a class within a class, an inner class, since your test case itself lives inside a run() method of a class you cannot ordinarily see.

In the following, you can place your test steps inside the constructor for the new inner class:

// Imports

public class Test {

  Test() {

    // Step 1

    // Step 2
    // Step n

try {
  new Test()
} catch(Exception e) {

You can code passThisTest() and failThisTest() to do anything you want.

This makes no sence.
If this case fails, it fails.

Perhaps you may need to re-phrase?
Like in if this step fails do that, otherwise do something else ?