How to import an existing test case into another test case

I have 2 test cases and I want to use one test case variable value in another test case. The variable is defined under variables tab but I am calculating that variable value during the script.

Now I want to use this calculated value in another test. Is it possible in Katalon?

You can use ‘return’ statement to return its value from one test case and then use it in another test case, e.g:

TC1:

def returnedValue = WebUI.getText(...)
return returnedValue

Main TC:

def textFromTC1 = WebUI.callTC(findTestCase('TC1'),[:]))
assert textFromTC1 == expectedText

Thanks a lot!

Hi Nguyen ,

can you share us the Manual view for the above said one . We are also faceing the same problem.
To return more than one value for calling test case to Main test case .

I am also facing same problem… I have test case 1, Test case2.

I wanted to use the outcome of a variable in test case 2. Return statement is not allowing more than one variable to return. How to use variable from one test case to other test case.

Nguyen/Bhawna Rani, Can you please share us Manual View.

You could using return Map to return several variables value
E.g:

**Test Case 1: **

Map Map_TC1 = [:]
Map_TC1.put('TC1_Var1','Cat')
Map_TC1.put('TC1_Var2','Dog')
return Map_TC1

**Test Case 2: **

Map TC_1_called = WebUI.callTestCase(findTestCase("TC_1"), [:])
println TC_1_called['TC1_Var1']
println TC_1_called['TC1_Var2']

TC1:

String u = WebUI.getAttribute(findTestObject(‘SignInPage/txt_username’), ‘placeholder’)

WebUI.setText(findTestObject(‘SignInPage/txt_username’), username)

String p = WebUI.getAttribute(findTestObject(‘SignInPage/txt_password’), ‘placeholder’)

CustomKeywords.‘com.fcm.utilities.ClearTextField.ClearText’(findTestObject(‘SignInPage/txt_password’))

WebUI.setText(findTestObject(‘SignInPage/txt_password’), password)

WebUI.click(findTestObject(‘SignInPage/btn_signinButton’))

Map Map_TC1 = [:]

Map_TC1.put(‘inlinetextofusername’,u)

Map_TC1.put(‘inlinetextofpassword’,p)

return Map_TC1;

**TC2: **

Map TC_1_called = WebUI.callTestCase(findTestCase(‘01_UserManagement/Login’), [(‘username’) : ‘Anna’, (‘password’) : ‘Analyst_2017’,(‘inlinetextofusername’):’’,(‘inlinetextofpassword’):’’], FailureHandling.STOP_ON_FAILURE)

println(TC_1_called[inlinetextofusername])

println(TC_1_called[inlinetextofpassword])

**Log: **

12-11-2017 04:31:40 PM - [START] - Start action : Statement - Map_TC1 = [:]

12-11-2017 04:31:40 PM - [END] - End action : Statement - Map_TC1 = [:]

12-11-2017 04:31:40 PM - [START] - Start action : Statement - Map_TC1.put(“inlinetextofusername”, u)

12-11-2017 04:31:40 PM - [END] - End action : Statement - Map_TC1.put(“inlinetextofusername”, u)

12-11-2017 04:31:40 PM - [START] - Start action : Statement - Map_TC1.put(“inlinetextofpassword”, p)

12-11-2017 04:31:40 PM - [END] - End action : Statement - Map_TC1.put(“inlinetextofpassword”, p)

12-11-2017 04:31:40 PM - [START] - Start action : Statement - return Map_TC1

12-11-2017 04:31:40 PM - [END] - End action : Statement - return Map_TC1

12-11-2017 04:31:40 PM - [ERROR] - Test Cases/01_UserManagement/Logout FAILED because (of) Variable ‘inlinetextofusername’ is not defined for test case.

12-11-2017 04:31:41 PM - [END] - End Test Case : Test Cases/01_UserManagement/Logout

can you please correct me the usage?

nhi> Thanks for the answer. Can you please let me know the usage by seeing script?

Any update from any one?

@“Chandrasekaran Ganapathy”: You are missing quotation marks in below scripts:

println(TC_1_called[inlinetextofusername])
println(TC_1_called[inlinetextofpassword])

They should be:

println(TC_1_called['inlinetextofusername'])
println(TC_1_called['inlinetextofpassword'])

Thanks for the reply… I got it working by passing that map values.

Map TC_1_called = WebUI.callTestCase(findTestCase(‘01_UserManagement/Login’), [(‘username’) : ‘Anna’, (‘password’) : ‘Analyst_2017’,(‘Map_TC1’):’’], FailureHandling.STOP_ON_FAILURE)

My question was: Is there any possibility to extend my test case to another test case like in Selenium we can extend a class to another class and all the variables and methods can be access because I don’t want to call the whole test and execute, I just want to have access to the variables to use their value in my current test case because I am calculating a value and pass them to variable.

One possibility is to combine these two test cases and make it one. With this option test case becomes too long and can’t be reused in other test cases.

make use of CustomeKeywords.

Thanks Mohammad

I have TC1 and LoginTC. LoginTC is called from TC1. During the call, i want to pass the Username and Password from TC1 to LoginTC.

Q1. Should i send those as a Map?
Q2. In LoginTC, how do i call these map entries ?

So i did something like
TC1:

WebUI.callTestCase(findTestCase(‘Login’),

[(‘Password’) : ‘X’, (‘Username’) : ‘A’],

FailureHandling.STOP\_ON\_FAILURE)  

LoginTC: _To access the map values _
WebUI.setText(findTestObject(‘input_LoginTextField’), Username )
WebUI.setText(findTestObject(‘input_PasswordTextField’), Password )

So, Is this the correct way (test case is working) or is there a better way?

Finally, I found answer here on how to use a particular variable from one test case in another test case without executing the whole test case.