How to use the GlobalVariable value (which was set in the test case) in multiple test cases

Firstly, I add a string GlobalVariable with null value
I set the value of GlobalVariable in Test case 1

GlobalVariable.ehr_member_DOB = WebUI.getText(findTestObject('Object Repository/lbl.DOB Add Encounter'))

Then in test case 2, when I use the GlobalVariable, it is empty.
How can I save the value of the GlobalVariable in one test case and then use it in another test case
Thanks in advance.

Do you have a Test Suite that binds your 2 Test Cases inside?

This code will update the GlobalVariable.ehr_member_DOB in memory. The value will be shared by multiple Test Cases in a Test Suite scope.

But the Execution Profile file is NOT updated. Therefore each indivisual runt of your Test Cases will read the null value of the GlobalVariable.

Yes, I do create a test suite, including the 2 test cases mentioned

Then, I guess,

 ... = WebUI.getText(findTestObject('Object Repository/lbl.DOB Add Encounter'))

returned null. You should check if it by

String text = WebUI.getText(findTestObject('Object Repository/lbl.DOB Add Encounter'))
assert text != null
GlobalVariable.ehr_member_DOB = text

It has any way to save the value that I want to set in test case 1 and use it in test case 2.

hmm, I don’t get that

Sharing the value in a Test Suite scope, which you are trying to do now, is the right way.

Can you let me know more specifically?

You know it already.

But unfortunately your code is not working well.

I have no more idea why.

1 Like

Hi @linh.pham, read this post; Global Variables and Execution Profile | Katalon Docs

Good luck :sunglasses: