Ability to know the test case execution status programattically at Test suite level

When a test case execution fails, we need to execute some clean up scripts (It could be something that helps the next test case to start executing smoothly).
The best practice to keep this clean up script is at test case tear down method of suite as this will be common/generic to all the test cases present in the suite.
So its important to know the status of test case execution whether it passed or failed to determine what to do next.

Test case execution status can not be determined programatically at test suite level.
This is because the tear down method i.e @AfterTestCase method do not get to know the context of testcase. That method do not simply accept the TestCaseContext parameter.
Test case execution status can be determined at TestListener level.
But the TestListener is common to all different test suites in the project, so anything you keep there will be applicable to all test suites. we need test suite specific clean up scripts.

Suggestion:
Can we have a TearDownTestCase method available at Test Suite, where we can get the TestCaseContext info

@TearDownTestCase(skipped = false) // Please change skipped to be false to activate this method.
def tearDownTestCase(TestCaseContext testCaseContext) {
def testCaseStatus = testCaseContext.getTestCaseStatus();
if(testCaseStatus.equals(“FAILED”))
{
// do something
}
else
{
//do something else
}
}

Please see this link discussion for some additional info here

Thakns

1 Like

I’m not sure what you’re asking for is necessary. What you want to achieve can probably be done by focusing on the TC result in the TC itself.

Before I explain further, let me expound on the listeners both you and @kazurayam have been discussing (I was reading your thread with interest late last night in my timezone).

There is a discrepancy between how we’d like listeners to work and how they’re implemented in Katalon. I would like them to have full start/stop powers but unfortunately, they are not written that way. There’s a recent thread about that here somewhere - I think @ThanhTo was involved too, if you want to search for it.

Anyway, put listeners aside and let’s deal with what can be used. It seems to me what you need to do is:

perform cleanup at test case level

That seems to be your requirement. Nothing else, just that.

This can be achieved in a TC directly.

// A notional test case script

try {

  // Regular test case steps here

} catch(Exception e) {

  // call cleanup code with a fail message
  cleanup(e.message)
}

// call cleanup code without a fail message
cleanup()

You will of course need to manage throw statements throughout your test code. But this way, you have the control you’re asking for in a place where Katalon supports it.

The cleanup() method is just a method in a keyword class which you import into each TC statically.

class Cleanup() {

  static cleanup(String errmessage = "") {
    if(errmessage != "") {
      // handle the error message?
    } else {
      // handle no error message?
    }

    // Do general cleanup
  }
}

Now, if you still need the TC context, you have two choices:

  1. Pass the TC name in to the cleanup() method.

  2. Keep a reference to it and pass it in from the @BeforeTestCase method:
    This would involve extending the cleanup class with a static tcname getter/setter.

Let me know if this seems helpful.

1 Like

Thank you @Russ_Thomas for your suggestion.

If i go with this approach, I will have try, catch block in every test case and also as you said we have to specifically mention throw statement for a failed testcase

all these looks repetition and the code won’t look very nice here

1 Like