Testcase dependent on other test cases in Test Suite

I have some test cases which are dependent on other test cases in Test Suite.

Use Case:

TC-1
TC-2 (depends on TC 1)
TC-3 (depends on TC 2)
TC-4 (depends on TC 3)

If TC-1 fails … TC-2,TC-3 and TC-4 shouldn’t execute.

I don’t want to use Call test case.

Test Cases return a result so it’s a shame you don’t want to use call. I guess you don’t want to have multiple cases inside another case?

Your other option is to set a GlobalVariable which you can examine before you execute the body of a test case. You will need to ensure the GV is set so you can run the TCs manually outside of a suite (if that matters to you).

Hi @focis.automation

Can you share with us why you don’t want to use Call Test Case. It seems like a solution to the problem you are stating, or there are some more context ?

Regards !

I will do my best to explain you.

  1. Well some background about this use case… I am working in logistics domain.

  2. We do scenario/ workflow based testing, and each testcase is around 600 steps.

  3. So we have logically brokedown one scenario into 19 sub scenario based on the functionality.
    And finally we used to call all these sub scenario in the one test case named ‘Execution’.

  1. On the other hand, Count of TC in test report is important for me.

  2. I have around 10 scenario’s now - with around 19 sub scenario each i.e 10x19=190 TC.

  3. If I use call test case …the count will be only 10 TC in test report. So I wanted to call all the 190 TC individually in test suite.

Hi Russ, I am unable to follow. Could please simplify with an example.

Thanks.

You could make a switch which executes a certain test case in some scenario.

Hi @focis.automation

Katalon Studio implements the concept of Test Listener which is essentially a block of code that gets executed before and after every test case. Using this mechanism as a workaround, what @Russ_Thomas means is that you can use something like this. ( I haven’t tested it yet, but it should give you an idea )

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import internal.GlobalVariable as GlobalVariable

import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.annotation.BeforeTestSuite
import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.AfterTestSuite
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.context.TestSuiteContext

class NewTestListener {
	String[] dependentTestCases = new String[19]{"List of your dependent test cases' Ids"};
	
	@BeforeTestCase
	def sampleBeforeTestCase(TestCaseContext testCaseContext){
		if(dependentTestCases.contains(testCaseContext.getTestCaseId()){
			if(GlobalVariable.SHOULD_NOT_RUN == true){
				// Do not run this test case 
				testCaseContext.skipThisTestCase()
			}
		}
	}

	@AfterTestCase
	def sampleAfterTestCase(TestCaseContext testCaseContext) {
		if(testCaseContext.getTestCaseId().equals("Your independent test case's Id")){
			if(testCaseContext.getTestCaseStatus().equals("FAILED")){
				GlobalVariable.SHOULD_NOT_RUN = true;
			}
		}		
	}
}

Hi @ThanhTo

How do you get GlobalVariable.SHOULD_NOT_RUN in testcase. Pls give me the syntax.

Thanks.

Hi @focis.automation

You need to declare a global variable name SHOULD_NOT_RUN in Profile Execution first. Then in your test cases you simply use:

GlobalVariable.SHOULD_NOT_RUN

Regards !

Hi @ThanhTo

Should I use this Global variable in every Testcase ?.

Also I am getting the below error … Could you advise.

Hi @focis.automation

The global variable is used in your Test Listener - which will be run before and after every test case execution. It is in Test Listener that you can skip a test case depending on some conditions, and the global variable will be set to indicate that those dependent test cases should be run or not. This is achieved by setting the global variable SHOULD_NOT_RUN to true when the test case which others depend on has failed ( in afterTestcase function in TestListener ).

The error message indicates that something is wrong with your Test Listener and not your Test Cases. Could you provide a screenshot of your test listener ?

Regards !

Hi @ThanhTo,

I have simply used the code given by you. just added the ) which was missing in if(dependentTestCases.contains(testCaseContext.getTestCaseId()))

dependentTestCases is an array and it doesn’t have the method contains.

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import internal.GlobalVariable as GlobalVariable

import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.annotation.BeforeTestSuite
import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.AfterTestSuite
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.context.TestSuiteContext

class NewTestListener {
String [] dependentTestCases = new String[19]{“List of your dependent test cases’ Ids”};

@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext){
if(dependentTestCases.contains(testCaseContext.getTestCaseId())){
if(GlobalVariable.SHOULD_NOT_RUN == true){
// Do not run this test case
testCaseContext.skipThisTestCase()
}
}
}

@AfterTestCase
def sampleAfterTestCase(TestCaseContext testCaseContext) {
if(testCaseContext.getTestCaseId().equals(“Your independent test case’s Id”)){
if(testCaseContext.getTestCaseStatus().equals(“FAILED”)){
GlobalVariable.SHOULD_NOT_RUN = true;
}
}
}
}

Hi @focis.automation

My bad. Method contains only exists on List.

Instead of:

if( dependentTestCases.contains(testCaseContext.getTestCaseId())){

Use:

if(Arrays.asList(dependentTestCases).contains(testCaseContext.getTestCaseId())){

Hi @ThanhTo,

I have modified the code as below: But the skipped test cases are considered as passed test case.

am I doing something wrong.

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import internal.GlobalVariable as GlobalVariable

import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.annotation.BeforeTestSuite
import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.AfterTestSuite
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.context.TestSuiteContext

class Working {

@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext){

  if(testCaseContext.getTestCaseId().contains("Test Cases")){


  	if(GlobalVariable.SHOULD_NOT_RUN == true){
  		// Do not run this test case
  		testCaseContext.skipThisTestCase()

  	}
  }

}

@AfterTestCase
def sampleAfterTestCase(TestCaseContext testCaseContext) {

  if(testCaseContext.getTestCaseId().contains("Test Cases")){


  	if(testCaseContext.getTestCaseStatus() == ('FAILED')){

  		GlobalVariable.SHOULD_NOT_RUN = true;

  		
  	}
  }

}
}

Hi @focis.automation

Please see KeywordUtil.markFailed(String message) method.

https://api-docs.katalon.com/com/kms/katalon/core/util/KeywordUtil.html

Regards !

1 Like