Can we return a value from a callTestCase?

Scenario: I have a test case1 which will create a form. In this i have one field as form name and i am generating random name and saving.

I have one more test case2 where i am calling the above test case1. But i want to access the form name which is entered in above test case1.

Can someone please help?

2 Likes

Yes, you can. https://docs.katalon.com/display/KD/[Common]+Call+Test+Case tells you that WebUI.callTestCase() returns any value of called test case if any.

I will give you a running example.
Here is a test case named “caller”:

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
def message = WebUI.callTestCase(findTestCase('callee'), ['name': 'Cynderella'])
WebUI.comment(message)

Another test case named “callee”:

def value = "Hello, ${name}"
return value

When you run the “caller”, you will see the following output in the Logview

08-23-2018 06:35:51 AM - [INFO]   - Hello, Cynderella
5 Likes

Thank you for the answer.

I have one doubt.
Suppose in Caller Testcase i have

import org.apache.commons.lang.RandomStringUtils as RandomStringUtils
def formName = ‘Create_Form_’ + RandomStringUtils.randomNumeric(5)

I want to use formName variable in other testcase “Callee”.

How to use it? Please help

in Caller you would have:

import org.apache.commons.lang.RandomStringUtils as RandomStringUtils
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
def formName = 'Create_Form_' + RandomStringUtils.randomNumeric(5)
WebUI.callTestCase(findTestCase('callee'), ['formName': formName])

You can pass a map of parameters to the Callee testcase as the 2nd argument to the WebUI.callTestCase()

in Callee you would have:

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
WebUI.comment("I have got " + formName)

In Previous post you used return statement now you are not using.
Do we need to use return statement or not required?

Do we need to use return statement or not required?

Not required.

It is up to you.

If you do not want to return value from Callee to Caller, you do not need a return statement in the Callee.

1 Like

Thanks a lot. Your answer helped me a lot