How to use parameters between testcases

Hi,
I work complete with the backend. No GUI or browsers at all.
I searched a lot but did nt get my missing link

TestCase 1 should call TestCase 2 and send Parameter filename.
Testcase 2 should check the file and return a value

I tried a lot and I guess it would be the best to start from scratch.
Has anybody a simple example or some code snippets?

Thx Jochen Herrmann

Personally I would create a String Global Variable and initialize it with the “Parameter filename” in TC 1. Have TC 2 check the file (the value of the Global Variable) and fill the Global Variable in TC 2 (or create 2 Global Variable if you want). Do what you want with the Global Variable’s content in TC 1 to your hearts content. No parameter needed. Just include the import statement at the top of both TCs.

import internal.GlobalVariable as GlobalVariable

If the value that you want to return in not a String, then you will have to go with creating 2 Global Variables.

Maybe like

Here is a simple example of using a String Global Variable to carry the filename around your Test Cases. Sample within TC 1:

GlobalVariable.gFiles = "G:\\Katalon Test Cases\\Data Files\\TestId.xlsx"

WebUI.callTestCase(findTestCase('Miscellaneous/Position'), [], FailureHandling.OPTIONAL)
WebUI.waitForPageLoad(10)
WebUI.delay(2)

WebUI.comment('value is ' + GlobalVariable.gFiles.toString())

Within TC 2, you use the contents of GlobalVariable.gFiles.

def filename = GlobalVariable.gFiles.toString().split{"/")[4]

If you want to go with a String parameter.

Using a String parameter

In Test Case 1

def myVar = 'the beginning'
def myMsg = WebUI.callTestCase(findTestCase('Playground/Playful'), ['myKey': myVar], FailureHandling.OPTIONAL)

WebUI.comment('the contents of message is ' + myMsg.toString())

In Test Case 2, you would have: (Note: you would not have to return the same variable from TC 2 that you sent in from TC 1. I did basically so you could see what I was doing.)

myKey = "the end"

return (myKey)

Thank you.
GlobalVariable.g_filename = “g_C:\tmp\test\snf_groovy.xml” fails.
I guess I have to find the class GlobalVariable and define my parameter there.
Where is this class located?

Thank you, but I guess global Variable asr not really the way I would prefer.
I tried to pass p_filename

WebUI.callTestCase(findTestCase(‘SNF/SNF_00xx/SNF_94_Statement.Transaction.BillingValues.Net.Amount’), [(‘p_filename’) : ‘C:\tmp\test\snf_groovy.xml’],
FailureHandling.STOP_ON_FAILURE)


In Testcase SNF_94_Statement.Transaction.BillingValues.Net.Amount I defined a parameter

and I use this parameter like this:
image
(I wonder why p_filename is underlined)

but the debugging says that p_filename is “”

Solved it.
I just did the WebUI.callTestCase(findTestCase(… again and the parameter was passed.
Strange behaviour…I wonder what happend if this testcase is used in many place and you need to renew ALL calls…

Returning values works like this
— tescase 1 —
int value = WebUI.callTestCase(findTestCase(‘SNF/SNF_00xx/SNF_94_Statement.Transaction.BillingValues.Net.Amount’), [(‘p_filename’) : ‘C:\tmp\test\snf_groovy.xml’
, (‘p_two’) : ‘yyyy’], FailureHandling.STOP_ON_FAILURE)

println “${value}”
— testcase 2 ----
return 300

Global Variables are defined/created under Profile (bottom of the list of Test Explorer).

https://docs.katalon.com/katalon-studio/docs/execution-profile-v54.html

There is also a great post by Brandon_Hein about passing parameters between test cases: