# Is there any way to skip TearDown Test Case for single test in test suite

**URL:** <https://forum.katalon.com/t/is-there-any-way-to-skip-teardown-test-case-for-single-test-in-test-suite/108421>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [November 27, 2023, 3:43am UTC](https://forum.katalon.com/t/is-there-any-way-to-skip-teardown-test-case-for-single-test-in-test-suite/108421 "2023-11-27T03:43:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shruti1](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/shruti1/32/24300_2.png) [@shruti1](https://forum.katalon.com/u/shruti1)\
**Post date:** [November 27, 2023, 3:43am UTC](https://forum.katalon.com/t/is-there-any-way-to-skip-teardown-test-case-for-single-test-in-test-suite/108421/1 "2023-11-27T03:43:06Z")

</div>

Hello,  
I have a TearDown Test Case to refresh after every test case.  
It is working fine however foe the last test case "logout " it fails (that is obvious as app is not present after logout).  
Now I want that TearDown test case not to run for logout test case, is there any way to skip this for one test case?

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/4/0/40388ea43883e623e4af50955da7c85c9321a548.png)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [November 27, 2023, 4:20am UTC](https://forum.katalon.com/t/is-there-any-way-to-skip-teardown-test-case-for-single-test-in-test-suite/108421/2 "2023-11-27T04:20:25Z")

</div>

Use a Test Case listener instead – you’ll have access to the Test Case id.

 

```auto
/**
	 * 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()
	}

```

 

> **[Test Fixtures and Test Listeners (Test Hooks) in Katalon Studio | Katalon Docs](https://docs.katalon.com/docs/katalon-studio/create-test-cases/test-fixtures-and-test-listeners-test-hooks-in-katalon-studio#test-listeners-test-hooks)**
>
> To extend your current testing flow, the test fixtures (@setUp/@tearDown methods) and test listeners might be useful for prerequisite and clean-up configurations for all the tests.

---

<div class="post-metadata">

**Author:** ![mwarren04011990](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mwarren04011990/32/26024_2.png) [@mwarren04011990](https://forum.katalon.com/u/mwarren04011990)\
**Post date:** [November 27, 2023, 5:54am UTC](https://forum.katalon.com/t/is-there-any-way-to-skip-teardown-test-case-for-single-test-in-test-suite/108421/3 "2023-11-27T05:54:45Z")

</div>

## Several questions

This invites several questions:

- how many test cases are in your test suite?
- why is `Logout` one of the test cases in the test suite?
- what are you trying to accomplish by refreshing the browser **after** the test case is done?

It also seems like none of these test cases are runnable on their own…

## To answer YOUR specific question

It is not the question that you asked, but it is one that is obvious from reading your screenshots, and @Russ_Thomas suggested it: **use a Test Listener**. To that, I will suggest that what you’re tryna do, refresh the browser window after each Test Case, is a YAGNI (You Ain’t Gonna Need It).

### How to use Test Listener

In your specific case, I would advise you set up and close the `WebDriver` before and after each test case, respectively…

#### Step 1: [Create Custom Keyword](https://docs.katalon.com/docs/katalon-studio/keywords/custom-keywords/introduction-to-custom-keywords-in-katalon-studio) for WebDriver Utils

I yoinked this from my project, and took out the `SetUpDriver()` instance. May it guide you…

```auto
package com.xxx.utils

import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions

import com.kms.katalon.core.webui.driver.DriverFactory

import internal.GlobalVariable

public final class SMDWebDriverUtils {
	private static WebDriver driver;

	public static void SetUpDriver() {
		/** 
		 * TODO: set up this.driver, in accordance to your use case. 
		 * In our real project, we have two Global Variables it depends on: 
		 * - pathToKatalon
		 * - pathToUserDataDir
		**/

		DriverFactory.changeWebDriver(this.driver);
	}

	public static void CloseDriver() {
		if (this.driver != null)
			this.driver.quit()
	}

	public static void DoWebAction(Closure onAction) {
		this.SetUpDriver();

		onAction();

		this.CloseDriver();
	}
}

```

#### Step 2: [Create Test Listener](https://docs.katalon.com/docs/katalon-studio/create-test-cases/test-fixtures-and-test-listeners-test-hooks-in-katalon-studio#create-new-test-listeners)

Your Test Listener should look something like this:

```auto
import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.context.TestCaseContext

import com.xxx.utils.SMDWebDriverUtils

class NewTestListener { 
	/*** Executes before every test case starts.
	 * @param testCaseContext related information of the executed test case.
	 */
	@BeforeTestCase
	def sampleBeforeTestCase(TestCaseContext testCaseContext) {
		SMDWebDriverUtils.SetUpDriver();
	}

	@AfterTestCase
	def sampleAfterTestCase(TestCaseContext testCaseContext) {
		SMDWebDriverUtils.CloseDriver();
	}
}

```

There! Now you don’t have to worry about refreshing your window after test case completion…or even opening the browser window for that matter…because **you’re starting anew with each test case**!

### If you MUST do web action after test case completion…

Notice that I have given you, for free, a method in `SMDWebDriverUtils` called `DoWebAction`. In your `tearDownTestCase()`, simply use it like this:

```auto
SMDWebDriverUtils.DoWebAction { 
	// TODO: test-suite-specific teardown logic, involving the browser being open, goes here...
}

```

The browser window will open right back up, perform the actions you spell out in the callback (they’re called Closures in Groovy), and close the browser for you, all between the test cases!

Obviously, I would suggest this for reasons _other than_ needing to refresh a browser window…

### If you MUST do something AFTER a specific test case is used…

…My suggestion to you would be to do it **in the test case itself** , like this:

```auto
import com.kms.katalon.core.annotation.TearDown

// ...your test case logic...

@TearDown
void close() { 
	// TODO: perform your test-case teardown here...
}

```

You could get the name of the test case you’re tearing down, but **only if the last step it touches isn’t running some child test case** , with this keyword:

```auto
package com.xxx.utils

import com.kms.katalon.core.configuration.RunConfiguration

public final class SMDTestCaseUtils {
	
	public static String CurrentTestCaseKey = "current_testcase";
	
	public static final String GetTestCaseName() {
		return RunConfiguration.getExecutionProperties().get(this.CurrentTestCaseKey);
	}
}

```

If your test case doesn’t contain any child test cases, `SMDTestCaseUtils.GetTestCaseName()` will return the name of the test case you are tearing down, even in the `tearDownTestCase()` method.

Else, it will return the name of the child-most test case, if calling it is the last step in your test case. A Test Listener will get around that problem.
