Using Test Listener can you skip test cases within test suite based on test case variable value?

I have several large test suites and some of the tests cannot be run against our production environment due to permissions and allowed testing scenarios.

I see in the Test Listener where I can skip tests using:

		if (GlobalVariable.env == '4-PROD') {
			if ((testCaseContext.getTestCaseId()) == 'This test should not be run in Prod!')
			{	testCaseContext.skipThisTestCase()
				println 'Skipping this test in ' + GlobalVariable.env + ' env'}

This works fine for this one test. As a backup solution to what I am really looking for can I add multiple TestCaseIds somehow to the above code, without having to copy the condition over and over?

What I am actually hoping to find an answer to is if I set a test case variable of say ‘runInProd’ and set the value to ‘no’ in these tests can I then check for that value and skip the test?

When I tried this I am seeing that the sampleBeforeTestCase is pulling the value:
testCaseContext.getTestCaseVariables(): [runInProd:no]

I just do not know how to format the condition to check this value. I tried unsuccessfully many variations of: (I was pretty sure it would not be this easy)

			if (runInProd == 'no')
			{	testCaseContext.skipThisTestCase()
				println 'Skipping this test in ' + GlobalVariable.env + ' env'}

This would let me just add this variable to the test cases without having to add in the TestCaseIds individually to Test Listener.

I have spent hours trying to find a solution and usually do not post in here, but this is driving me crazy.

Thank you!


I think you can leverage BeforeTestCase method: Skip test cases in Katalon Studio | Katalon Docs

Let me show you an idea. I made a TestListener as follows:

import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.context.TestCaseContext

class TL1 {
	private List<String> toSkip = [
		"Test Cases/TC1" , 
		"Test Cases/TC99"
	def sampleBeforeTestCase(TestCaseContext testCaseContext) {
		String tcId = testCaseContext.getTestCaseId()
		if (toSkip.contains(tcId)) {
			println "${tcId} was skipped"
		} else {
			println "${tcId} ran"

You can add more entries in the toSkip variable easily.