[TIP] (How To) Select test case(s) to not run in particular environment

Here’s a tip on how to write a little piece of code to skip your test case in your test suite.

From the Test Listeners, under @BeforeTestCase, add this little snippet and, when you run the suite, it will skip that test.

    @BeforeTestCase
    def sampleBeforeTestCase(TestCaseContext testCaseContext) {
    			testCaseContext.skipThisTestCase()
    		}

If you have Global Profiles set up with your environment urls as the profile, you can also adjust it to determine the url and skip a particular test if it’s in a particular environment.

@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
	if (GlobalVariable.url == "https://example.com") {
		if ((testCaseContext.getTestCaseId()) == "Test Cases/NameOfTestCase") 
		{	testCaseContext.skipThisTestCase()
			println 'Closing this test in Production env'}
		}

This will run the tests as PASSED in the reporting as I do not believe there is a way to ‘Mark as Skipped’ at this time.

See thread: It is possible to skip test in runtime?

2 Likes

Agreed. I think it is possible but it’s anything but straightforward (I think @kazurayam posted something about this a while ago). The code involved was digging deep into the Katalon suite and test case on-ramp and, like I intimated, not for the faint hearted.

What we need is something official at the suite level, something like:

/**
* Return true, run the test case, false, do not
*/
@SuiteNextTestCase
boolean nextTestCase(TestCaseContext tcContext) {
  if(_some-condition_)
    return false
  return true
}

The above would run at the suite level before @BeforeTestCase. The idea being, PASSED/FAILED/ERROR whatever-the-hell doesn’t even come into it. It’s like the TC was never there in the first place.

The ability to skip a test(s) for an environment, or in my case, browser, really should be something you can set through the UI, rather than write code to achieve it IMO.

Then have a UI panel that you can view to see what tests you have marked as skipped. I would stick this in the feature requests section, if I could find it! :slight_smile: