Get TestCaseContext TestSuiteContext from test script

Hello gals,guys
does someone know how to access/get TestCaseContext TestSuiteContext from test script or custom keyword?
i know how to get them in test Listeners, however i would like to get them directly in testCase (custom Keyword)
thank you for any hint.

1 Like

Make 2 Global Variables of type Null, and in the test listerner save the TestSuiteContext object and the TestCaseContext object into the global variables.

class TestListener {

    @BeforeTestSuite
	def beforeTestSuite(TestSuiteContext testSuiteContext) {
		GlobalVariable.TEST_SUITE_CONTEXT = testSuiteContext
	}
	
	@BeforeTestCase
	def beforeTestCase(TestCaseContext testCaseContext) {
		GlobalVariable.TEST_CASE_CONTEXT = testCaseContext
	}
}

Declaring the global variable as type of Null is important. This means in fact the global variable object is declared as an instance of java.lang.Object into which you can set any type of objects.

And in you test case, you need to cast the global variable to the appropriate types explicitly.

println "TestSuiteContext is ${(TestSuiteContext)GlobalVariable.TEST_SUITE_CONTEXT}"
3 Likes

didn’t know that … thanx lot