Is it possible to fail test case at Test Listener level


#1

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


#2

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


#3

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!