Can we have multiple Test LIsteners

I want to use a specific Test Listener for a specific Test suite , Can we have multiple listeners associated with specific Test suites ?

Hi Shruti,

You can have multiple Test Listeners for a specific Test Suite if you add a condition to let Test Listeners only listen to that Test Suite. Katalon Studio has already provided this function, example:

	@BeforeTestSuite
def sampleBeforeTestSuite(TestSuiteContext testSuiteContext) {
if (testSuiteContext.getTestSuiteId()=="Test Suites/TS_RegressionTest")
		{
//Do something related to TS_RegressionTest
		}
	}

Vinh Nguyen said:

Hi Shruti,

You can have multiple Test Listeners for a specific Test Suite if you add a condition to let Test Listeners only listen to that Test Suite. Katalon Studio has already provided this function, example:

	@BeforeTestSuite

def sampleBeforeTestSuite(TestSuiteContext testSuiteContext) {
if (testSuiteContext.getTestSuiteId()==ā€œTest Suites/TS_RegressionTestā€)
{
//Do something related to TS_RegressionTest
}
}


  
  
  
  
  
  
  

  

Thanks Vinh, Do I need to call ā€˜sampleBeforeTestSuiteā€™ from my TestSuite, how it recognizes the particular test suite?

This condition : "if (testSuiteContext.getTestSuiteId()==ā€œTest Suites/TS_RegressionTestā€) will tell you which particular test suite (TS_RegressionTest in my case) it is going to listen to, just change it to your Test Suite.

ok Thanks Vinh for your inputs.

By the way, you can also use Setup/ Teardown for Test Suite as well due to the facts that these methods are tied to only specific Test Suites and will only execute these methods just in case.

Hello.

What is the difference between using code in SetUp/TearDown and using code in BeforeTest/AfterTest methods in a Test Listener?

I mean, the behavior of code in SetUp/TearDown will be the same in BeforeTest/AfterTest methods?

@diogo.soares

Please see the following docs for the life cycle of listeners. The difference is when the listeners are invoked

Oh, of course :man_facepalming: sorry to ask.

The SetUp/TearDown methods are used for test suite itself and the Listener can be used for all test suites.

The workflow in the document is a great help!

Thanks and sorry again for asking :slightly_smiling_face:

1 Like