How can I check if running Test Suite or Test Suite Collection at Runtime

Because I’ve been asked to add failed test case IDs to the body of the Report email template, I’ve written a separate @AfterTestSuite method in a Listener that will build a mock of the email template as I want.

Currently, I’d like to know if there’s a way to determine, at runtime (likely in a @BeforeTestSuite method), if a single TestSuite is being run or is it a TestSuiteCollection? This will help me to determine the kind of information that I’m generating in the Report email.

Your question is closely related to the following issue:

which was dated at Aug 2019, has no progress yet.

Your original question was

How can I check if running Test Suite or Test Suite Collection at Runtime

I don’t think you can do it.

That’s my fear.
I do think the feature request posted would alleviate this issue as well.

In the meantime, I can search to see if there’s another way of injecting the list of failed test cases into the email templates directly. I’ve tried with a Global Variable that is updated by the listener, but it seems like the Templates are created during the build process in some way and don’t update properly throughout the run

Katalon’s feature of sending Email is not customizable at runtime. It is designed dumm.

You would want to create a new set of code that genates email text and send it to SMTP server for yourself. Sending an email from Java/Groovy is not really difficult. See

You will find a chance to send a email in a TestListener’s @AfterTestSuite-annoted method.

Email might not be the best way to publish the test-result information. Writing the information to DB, publishing it as a text into Slack, or any other method you can try.

That’s the approach I’m working with now.

In my TestListener, I currently have a method (rather long admittedly) that builds the email and body (copied from the Templates in \settings\internal\com.kms.katalon.execution.properties)

The issue I’m facing now is simply trying to determine when to send the TestSuite email or the TestSuiteCollection email

Quick Update:
I think I did discover a method to find a TestSuite vs TestSuiteCollection.

If the Collection is currently being run, then the Reports folder also creates a folder for the Collection itself.

Example:
“TestSuiteNumber1”
“TestSuiteNumber2”
“TestSuiteCollection” = “TestSuiteNumber1” + “TestSuiteNumber2”

Running TestSuiteNumber1, the Report folder contains just “TestSuiteNumber1”
Running TestSuiteCollection, the Report folder contains “TestSuiteNumber1”, “TestSuiteNumber2”, AND “TestSuiteCollection”

My Solution:
Therefore, I have in my TestListener something like this:

private isCollection = false
private checkedCollection = false
	
@BeforeTestSuite
def createTempCollectionFile() {
	if(!checkedCollection) {
		Path latestSubFolder = null
		def parentDir = RunConfiguration.getProjectDir() + "/Reports"
		Path parentPath = new File(parentDir).toPath()
		FileTime latestModTime = FileTime.fromMillis(1)
		Files.walk(parentPath, 2)
			.filter { Files.isDirectory(it) }
			.forEach {
				FileTime modTime = Files.getLastModifiedTime(it)
				if (modTime.compareTo(latestModTime) > 0) {
					latestModTime = modTime
					println("LatestModTime: " + latestModTime.toString())
					latestSubFolder = it
					println("LatestSubFolder: " + latestSubFolder.toAbsolutePath().toString())
				}
			}
			if(latestSubFolder != null) {
				Files.walk(latestSubFolder, 1)
				.filter { Files.isDirectory(it) }
				.forEach { Path path ->
					println(path.getFileName().toString())
					if(path.getFileName().toString().contains("SmokeTestSuiteCollection")) {
						isCollection = true
					}
				}
			}
			checkedCollection = true
		}

This first IF statement is so that I can find the reporting folder that we’re currently writing to and pushing down two folders

From there, I do another check to see if there’s a child folder named after my TestSuiteCollection. If so, then I hold a boolean isCollection = true