How to stop the execution of TestCase and Testsuite and TestSuitCollection using script


#1

I need script code to stop execution of Test Case and Test suite and Test Suit Collection on specific events


#2

I have a similar situation, I’m looking for a clean way to stop the execution of a Test Suite if 1 of the test cases fails. Currently, if a test case fails, the Test Suite will continue to execute the remaining test cases. I personally do not mind the how the current flow works, this is more of a request by our testing team.

I looked in to the setup and tear down and I can get things to fail all the way through from there, but then it will just show a bunch of stop signs.

Is there a hidden variable set anywhere that I can read for errors and failures, if I can read that, then I might be easier to stop the test suite from continuing the the setup and tear down.


#3

Found a good workaorund using this builtin keyword to concatenate test cases in 1 test case and that can become the body of the test suite. Doing so any test cases that fail with the “body” test case, will stop running. You can then still do some “tear down” by adding close browser on another test case.

WebUI.callTestCase(findTestCase('1'), [:], FailureHandling.STOP_ON_FAILURE)
WebUI.callTestCase(findTestCase('2'), [:], FailureHandling.STOP_ON_FAILURE)
WebUI.callTestCase(findTestCase('3'), [:], FailureHandling.STOP_ON_FAILURE)

#4

**System.exit(1) **


#5

I have a similar situation where i need to stop the execution of a Test Suite if 1 of the test cases fails. Instead of the workaround above, do we have any other solution ?


#6

Sunil Kumar A said:

I have a similar situation where i need to stop the execution of a Test Suite if 1 of the test cases fails. Instead of the workaround above, do we have any other solution ?

So far the ‘Call Test Case’ is the only simple solution I have found. You can create a new test case, then drag-n-drop other test cases to it in Manual mode. Then take that test case and either run it standalone or add it to the test suite. It will give you the result you are looking for. The setup is actually not bad and you can still disable and enable test cases within that script.


#7

Todd Bruss said:

Sunil Kumar A said:

I have a similar situation where i need to stop the execution of a Test Suite if 1 of the test cases fails. Instead of the workaround above, do we have any other solution ?

So far the ‘Call Test Case’ is the only simple solution I have found. You can create a new test case, then drag-n-drop other test cases to it in Manual mode. Then take that test case and either run it standalone or add it to the test suite. It will give you the result you are looking for. The setup is actually not bad and you can still disable and enable test cases within that script.

The problem with call test case approach is … variables from the called test case are not exposed for data binding when called in a suite. Only its default variable values will be used. That is the reason i am looking for a different approach.


#8

I tried with this listener inside my suit:

import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory

    @TearDownTestCase(skipped = true) // Please change skipped to be false to activate this method.
    def tearDownTestCase(TestCaseContext testCaseContext) {
    	// Put your code here.
    	if(testCaseContext.getTestCaseStatus()=="FAILED"){
    		FailureHandling.STOP_ON_FAILURE
    	}
    }

But throws me the following error:
Cannot invoke method getTestCaseStatus() on null object

Anyone could solve this problem in another way?