How to skip rest of the steps within same test execution when a condition is met


I am looking for some solution for the problem mentioned in title. I know, to skip a test case, Test Listners are available but I am afraid it will not fulfill what I am trying to achieve here. My scenrio is

I want to check if

  • Same record is already there then do not add it again (will be doing this part in SetUp method of same test case)
  • If no record found then add new record (new record will be added in main test case)


TC-A has SetUp method where all this logic will be implemented.
In SetUp method of TC-A, check if record exists → Skip execution of rest of the test case which includes (Setup+TC-A)

Test Listners are designed to work at start or end of the test case not in between of the test execution. Tha’s why it will not serve the purpose what I am looking for.

In summary, I want some logic which can help me to stop rest of the test execution if a condition is met in SetUp section of that particluar test.???

I hope I made it clear what I am looking for?


I’m not sure if it makes up for what you want, but I use a fictitious string that can’t be found on the page and then end the test, like:

import com.kms.katalon.core.model.FailureHandling as FailureHandling

if (!hasFound) {
	// stop right here
	WebUI.verifyTextPresent("Martin is King!", false, FailureHandling.STOP_ON_FAILURE)

“Martin” was a very funny gent that worked at my last employment.

Or, just throw an exception, maybe like:

import com.kms.katalon.core.exception.StepErrorException as StepErrorException

if (!hasFound) {
    // KA-BOOM
	throw new StepErrorException("Did not find ... !");

In my case, I want to find something on the page, in your case it seems you don’t want to find something, so you will have to change the way I check the condition of being found or not.

Can you not just enclose the whole test in a ‘if’ statement, so it won’t run if the record is already there? If you are checking for the record in a separate step, you can have that return true or false depending whether the record already exists.

A Katalon Test Case is an instance of Groovy script, in which you can declare any Method inside. The following Test Case declares power(int n) method that returns an integer value.

// TC-A
println 'Hello'

int power(int n) {
    return 2**n

println "2^6==${power(6)}"


2023-06-06 10:08:56.608 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2023-06-06 10:08:56.612 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/TC-A
2023-06-06 10:08:57.554 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/TC-A

So you can add any methods in the body of TC-A. For example, your TC-A can be something like:

// your TC-A
boolean setUp(String id) {
    // do somethig on the id
   if (the record is already there) {
       return true
    }  else {
       return false

boolean isAlreadyThere = setUp(id)
if (isAlreadyThere) {
    // do not add it again
} else {
    // add new record

Thank you all for your suggestions. I finally decide to implement this scneario in a way (though not much happy) as suggested by @AmyKirk. Why not much ahppy because

The test case(s) strucure is

TC-A (Setup)

  • open form to add record (call a seperate test case to do this task).


  • fill data to add new record in opened window.
  • verify record successfully added

This is the way I am using to add records on different pages. Now, to accomplish what I need through If/Else, I have to use it in setup and in main test case section.

In TC-A setup

  • if same record exists, do not open form to add new record
  • if no same record found, open form to add new record.
  • Set a global parameter with true/false based on the above conditon.

Now the part which I don’t like is,

I can’t stop this test case while executing setup section if the condition is true. So I have to add another if/else in TC-A main section to skip the steps of adding values for new recrod based on the global variable value.

But looks like I have to do this in that particular way.