Getting current_testcase from RunConfiguration.getExecutionProperties() fails when a test case contains child test cases

I am on Katalon Studio v8.6.8, on a Windows 10 machine.

I have this parent test case, named Test Cases/Unit Tests/Child Test Cases and Test Case Name, that contains this child test case.

It is defined to be:

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.signaturemd.utils.SMDTestCaseUtils

WebUI.callTestCase(findTestCase('Test Cases/Unit Tests/Groovy truthiness'), [:])

assert SMDTestCaseUtils.GetTestCaseName() == 'Test Cases/Unit Tests/Child Test Cases and Test Case Name'

and that util method SMDTestCaseUtils.GetTestCaseName() is defined to be:

public final class SMDTestCaseUtils {
	public static String CurrentTestCaseKey = "current_testcase";
	
	public static final String GetTestCaseName() {
		return RunConfiguration.getExecutionProperties().get(this.CurrentTestCaseKey);
	}

	// ...all my other test case util methods...
}

The assertion fails, as the util method returns Test Cases/Unit Tests/Groovy truthiness instead of the name of the parent test case…

2 Likes

I ended up having to do the following:

public final class SMDTestCaseUtils {
	public static final String CurrentTestCaseKey = "current_testcase";
	public static final String ReportFolderKey = "reportFolder";
	
	public static final String GetTestCaseName() {
		final String reportFolderPath = RunConfiguration.getReportProperties()
			.get(this.ReportFolderKey)
			.toString()
			.replace("\\", '/'),
			currentTestCase = RunConfiguration.getExecutionProperties().get(this.CurrentTestCaseKey);
		
		if (reportFolderPath.contains(currentTestCase))
			return currentTestCase;
		
		final Matcher matcher = (reportFolderPath =~ /(?<testCaseName>Test Cases\/.*)\/[0-9]{8}_[0-9]{6}/);
		
		if (!matcher.find())
			throw new IllegalStateException("Either the report folder path DOESN'T contain a test case name, or the regex pattern for test case name is incorrect...");
			
		return matcher.group("testCaseName");
	}
}
1 Like