Is it possible to fail test case at Test Listener level

Hi Team,

We are trying to get data from datasource and assign to Gobal map variable. This is going to be required for each and every test case, so we moved this code to Test Listeners and its inside @BeforeTestCase annotation.

STOPONFAILURE is not working at Test Listener level. is it expected behaviour?

@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
String strTestCaseName = testCaseContext.getTestCaseId()
println strTestCaseName
println testCaseContext.getTestCaseVariables()

	String[] tempTestCaseNameSplitArray = strTestCaseName.split("/") 
	strTestCaseName = tempTestCaseNameSplitArray[tempTestCaseNameSplitArray.length-1]
	println "TestCase Name After split : " + strTestCaseName
	int TestCaseRowNumber = CustomKeywords.'company.WebServices.TestDataAvailableStatus'(GlobalVariable.DataSourceName, strTestCaseName)
	println "TestcaseRowNumberFromListener: " + TestCaseRowNumber
	WS.verifyNotEqual(TestCaseRowNumber, 0,FailureHandling.STOP_ON_FAILURE)
	
	GlobalVariable.DataSourceName = CustomKeywords.'moneygram.WebServices.GetDataSourceValues'(GlobalVariable.DataSourceName, TestCaseRowNumber)
}

Regards
Udaya

From a listener, it’s not easy. For some background, see

Thanks Russ, I will assign to a flag and pass to Global variable, using that flag will take decision at test case level.

Thanks for input!

1 Like