Local variables between called test cases

Hi there,

I have an issue with local variables, that they are unknown in the same test case, when i declare it in one “Called test case” and try to use it in another . Let me explain my problem in detail:

I have a testcase which includes multiple test steps. I used the “Call test case” functionality to call all my test steps. I declare and set a local variable (e.g. numberOfDisplayedItems) in test step a and then try to verify the value of the variable “numberOfDisplayedItems” in test step 2.

Unfortunatly I was not successful :slight_smile: The variable numberOf DisplayedItems is not known in test step 2.

In test step 1:

numberOfDisplayedItems = WebUI.getText(findTestObject('Bestellmaske/number_of_items'))

In test step 2:

 WebUI.verifyElementPresent(findTestObject('Bestelluebersicht/number_items', [('numberOfItems') : numberOfDisplayedItems ]), 0, 

I don’t want to use Global variables, because i don’t need this information outside the current test case.

Thanks alot for your help!

You need to ‘return’ a variable you want from one test case, and then you can use it in different test cases, e.g:

1. Test Case 1:

numberOfDisplayedItems = WebUI.getText(findTestObject('Bestellmaske/number_of_items'))return numberOfDisplayedItems

2. Test Case 2:

numberofDisplayedItems = WebUI.callTestCase(findTestCase('TestCase1'))WebUI.verifyElementPresent(findTestObject('Bestelluebersicht/number_items', [('numberOfItems') : numberOfDisplayedItems ]), 0, 

The other possible approach is to store your variable to a permanent memory - to a file.

The advantage of this approach is that you can reuse the variable in multiple tests and you don’t need to call first test again and again. You can also store multiple variables and read them as you want.

Finally, at the end of your test suite, just delete the file to clean a mess.

@Vinh Nguyen - Awesome - this worked!
Thank you!!


I have similar issue where I am storing variable into one case but I like to use that variable into multiple test case.
Can anyone please help me to achieve that?

Thanks in advance

The following post explains how to use GlobalVariables to pass values around test cases in a test suite run:

Thank you very much.

This is exactly what I was looking for.