Running two test cases simultaneously - Ping Pong Test Case

well … here a proof of concept.
First, I made two testcases, ‘TC ping’ and ‘TC pong’. Both of them have a public variable, ‘count’, of type number with initial value 0 (use the Variables tab to define them). See attached pic:

ping_pong

Next, for fun, let’s make a custom ‘test’ package with two keywords, ping and pong, which only prints the received count value <<< you can put your scripts there:

package test

import com.kms.katalon.core.annotation.Keyword

public class pp {
	@Keyword
	def ping(count){
		println("ping! ${count}")
	}
	
	@Keyword
	def pong(count){
		println("pong! ${count}")
	}
}

Now, the tescases looks as follows:

  • in ping we check if we reached the iteration limit, increase the count, do the ping and call the pong testcase. we bind the count variable to save the actual value.
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

if (count < 5) {
	count ++
	CustomKeywords.'test.pp.ping'(count)
	WebUI.callTestCase(findTestCase('TC pong'), ["count":count])
} else {
	println('done!')
}
  • in pong, we have to make sure that the case is called by the first one, so we check the count to not be zero, do the pong and call back the ping testcase. we bind again the count variable to pass back the actual value.
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

if (count != 0) {
	CustomKeywords.'test.pp.pong'(count)
	WebUI.callTestCase(findTestCase('TC ping'), ["count":count])
} else {
	println('dont start the loop from this testcase!')
}

and we start the loop by running ‘TC ping’ (attempting to start the loop with 'TC pong" will just end quickly)
The Log View will be funny, since each case will appear under the previous one, as a tree. I wonder how will look for 100 iterations :slight_smile:

Here is the console output:

2019-09-04 11:35:22.116 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:22.119 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/TC ping
2019-09-04 11:35:22.402 INFO  c.k.katalon.core.main.TestCaseExecutor   - (Default) count = 0
2019-09-04 11:35:22.593 DEBUG testcase.TC ping                         - 1: if (count < 5)
2019-09-04 11:35:22.595 DEBUG testcase.TC ping                         - 1: (count++)
2019-09-04 11:35:22.597 DEBUG testcase.TC ping                         - 2: test.pp.ping(count)
ping! 1
2019-09-04 11:35:22.626 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - test.pp.ping is PASSED
2019-09-04 11:35:22.627 DEBUG testcase.TC ping                         - 3: callTestCase(findTestCase("TC pong"), ["count":count])
2019-09-04 11:35:22.767 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:22.767 INFO  c.k.katalon.core.main.TestCaseExecutor   - CALL Test Cases/TC pong
2019-09-04 11:35:22.773 INFO  c.k.katalon.core.main.TestCaseExecutor   - count = 1
2019-09-04 11:35:22.831 DEBUG testcase.TC pong                         - 1: if (count != 0)
2019-09-04 11:35:22.832 DEBUG testcase.TC pong                         - 1: test.pp.pong(count)
pong! 1
2019-09-04 11:35:22.833 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - test.pp.pong is PASSED
2019-09-04 11:35:22.833 DEBUG testcase.TC pong                         - 2: callTestCase(findTestCase("TC ping"), ["count":count])
2019-09-04 11:35:22.899 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:22.899 INFO  c.k.katalon.core.main.TestCaseExecutor   - CALL Test Cases/TC ping
2019-09-04 11:35:22.904 INFO  c.k.katalon.core.main.TestCaseExecutor   - count = 1
2019-09-04 11:35:22.905 DEBUG testcase.TC ping                         - 1: if (count < 5)
2019-09-04 11:35:22.906 DEBUG testcase.TC ping                         - 1: (count++)
2019-09-04 11:35:22.907 DEBUG testcase.TC ping                         - 2: test.pp.ping(count)
ping! 2
2019-09-04 11:35:22.908 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - test.pp.ping is PASSED
2019-09-04 11:35:22.909 DEBUG testcase.TC ping                         - 3: callTestCase(findTestCase("TC pong"), ["count":count])
2019-09-04 11:35:22.969 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:22.969 INFO  c.k.katalon.core.main.TestCaseExecutor   - CALL Test Cases/TC pong
2019-09-04 11:35:22.973 INFO  c.k.katalon.core.main.TestCaseExecutor   - count = 2
2019-09-04 11:35:22.976 DEBUG testcase.TC pong                         - 1: if (count != 0)
2019-09-04 11:35:22.976 DEBUG testcase.TC pong                         - 1: test.pp.pong(count)
pong! 2
2019-09-04 11:35:22.977 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - test.pp.pong is PASSED
2019-09-04 11:35:22.978 DEBUG testcase.TC pong                         - 2: callTestCase(findTestCase("TC ping"), ["count":count])
2019-09-04 11:35:23.038 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.038 INFO  c.k.katalon.core.main.TestCaseExecutor   - CALL Test Cases/TC ping
2019-09-04 11:35:23.045 INFO  c.k.katalon.core.main.TestCaseExecutor   - count = 2
2019-09-04 11:35:23.046 DEBUG testcase.TC ping                         - 1: if (count < 5)
2019-09-04 11:35:23.047 DEBUG testcase.TC ping                         - 1: (count++)
2019-09-04 11:35:23.048 DEBUG testcase.TC ping                         - 2: test.pp.ping(count)
ping! 3
2019-09-04 11:35:23.049 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - test.pp.ping is PASSED
2019-09-04 11:35:23.050 DEBUG testcase.TC ping                         - 3: callTestCase(findTestCase("TC pong"), ["count":count])
2019-09-04 11:35:23.110 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.110 INFO  c.k.katalon.core.main.TestCaseExecutor   - CALL Test Cases/TC pong
2019-09-04 11:35:23.114 INFO  c.k.katalon.core.main.TestCaseExecutor   - count = 3
2019-09-04 11:35:23.115 DEBUG testcase.TC pong                         - 1: if (count != 0)
2019-09-04 11:35:23.116 DEBUG testcase.TC pong                         - 1: test.pp.pong(count)
pong! 3
2019-09-04 11:35:23.116 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - test.pp.pong is PASSED
2019-09-04 11:35:23.116 DEBUG testcase.TC pong                         - 2: callTestCase(findTestCase("TC ping"), ["count":count])
2019-09-04 11:35:23.172 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.172 INFO  c.k.katalon.core.main.TestCaseExecutor   - CALL Test Cases/TC ping
2019-09-04 11:35:23.175 INFO  c.k.katalon.core.main.TestCaseExecutor   - count = 3
2019-09-04 11:35:23.177 DEBUG testcase.TC ping                         - 1: if (count < 5)
2019-09-04 11:35:23.177 DEBUG testcase.TC ping                         - 1: (count++)
2019-09-04 11:35:23.178 DEBUG testcase.TC ping                         - 2: test.pp.ping(count)
ping! 4
2019-09-04 11:35:23.178 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - test.pp.ping is PASSED
2019-09-04 11:35:23.179 DEBUG testcase.TC ping                         - 3: callTestCase(findTestCase("TC pong"), ["count":count])
2019-09-04 11:35:23.236 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.236 INFO  c.k.katalon.core.main.TestCaseExecutor   - CALL Test Cases/TC pong
2019-09-04 11:35:23.240 INFO  c.k.katalon.core.main.TestCaseExecutor   - count = 4
2019-09-04 11:35:23.242 DEBUG testcase.TC pong                         - 1: if (count != 0)
2019-09-04 11:35:23.243 DEBUG testcase.TC pong                         - 1: test.pp.pong(count)
pong! 4
2019-09-04 11:35:23.244 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - test.pp.pong is PASSED
2019-09-04 11:35:23.244 DEBUG testcase.TC pong                         - 2: callTestCase(findTestCase("TC ping"), ["count":count])
2019-09-04 11:35:23.302 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.302 INFO  c.k.katalon.core.main.TestCaseExecutor   - CALL Test Cases/TC ping
2019-09-04 11:35:23.306 INFO  c.k.katalon.core.main.TestCaseExecutor   - count = 4
2019-09-04 11:35:23.307 DEBUG testcase.TC ping                         - 1: if (count < 5)
2019-09-04 11:35:23.307 DEBUG testcase.TC ping                         - 1: (count++)
2019-09-04 11:35:23.307 DEBUG testcase.TC ping                         - 2: test.pp.ping(count)
ping! 5
2019-09-04 11:35:23.308 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - test.pp.ping is PASSED
2019-09-04 11:35:23.308 DEBUG testcase.TC ping                         - 3: callTestCase(findTestCase("TC pong"), ["count":count])
2019-09-04 11:35:23.365 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.365 INFO  c.k.katalon.core.main.TestCaseExecutor   - CALL Test Cases/TC pong
2019-09-04 11:35:23.368 INFO  c.k.katalon.core.main.TestCaseExecutor   - count = 5
2019-09-04 11:35:23.369 DEBUG testcase.TC pong                         - 1: if (count != 0)
2019-09-04 11:35:23.370 DEBUG testcase.TC pong                         - 1: test.pp.pong(count)
pong! 5
2019-09-04 11:35:23.370 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - test.pp.pong is PASSED
2019-09-04 11:35:23.371 DEBUG testcase.TC pong                         - 2: callTestCase(findTestCase("TC ping"), ["count":count])
2019-09-04 11:35:23.427 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.427 INFO  c.k.katalon.core.main.TestCaseExecutor   - CALL Test Cases/TC ping
2019-09-04 11:35:23.431 INFO  c.k.katalon.core.main.TestCaseExecutor   - count = 5
2019-09-04 11:35:23.432 DEBUG testcase.TC ping                         - 1: if (count < 5)
2019-09-04 11:35:23.432 DEBUG testcase.TC ping                         - 2: else
2019-09-04 11:35:23.432 DEBUG testcase.TC ping                         - 1: println("done!")
done!
2019-09-04 11:35:23.435 INFO  c.k.katalon.core.main.TestCaseExecutor   - END CALL Test Cases/TC ping
2019-09-04 11:35:23.435 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.441 INFO  c.k.katalon.core.main.TestCaseExecutor   - END CALL Test Cases/TC pong
2019-09-04 11:35:23.441 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.442 INFO  c.k.katalon.core.main.TestCaseExecutor   - END CALL Test Cases/TC ping
2019-09-04 11:35:23.442 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.443 INFO  c.k.katalon.core.main.TestCaseExecutor   - END CALL Test Cases/TC pong
2019-09-04 11:35:23.443 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.444 INFO  c.k.katalon.core.main.TestCaseExecutor   - END CALL Test Cases/TC ping
2019-09-04 11:35:23.444 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.445 INFO  c.k.katalon.core.main.TestCaseExecutor   - END CALL Test Cases/TC pong
2019-09-04 11:35:23.445 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.446 INFO  c.k.katalon.core.main.TestCaseExecutor   - END CALL Test Cases/TC ping
2019-09-04 11:35:23.446 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.447 INFO  c.k.katalon.core.main.TestCaseExecutor   - END CALL Test Cases/TC pong
2019-09-04 11:35:23.447 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.448 INFO  c.k.katalon.core.main.TestCaseExecutor   - END CALL Test Cases/TC ping
2019-09-04 11:35:23.448 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.449 INFO  c.k.katalon.core.main.TestCaseExecutor   - END CALL Test Cases/TC pong
2019-09-04 11:35:23.449 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-09-04 11:35:23.450 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/TC ping

Of-course, you can do the ping-pong other ways, e.g from a single testcase and making the keywords to call each-other, to avoid the nested log view result … or other solution i don’t have in mind right now.
Hope it helped. Have fun!

Warning! this method is most probably resource hungry, since each iteration will add again the objects in memory. Use it with caution!

4 Likes