# Local variables between called test cases

**URL:** <https://forum.katalon.com/t/local-variables-between-called-test-cases/13298>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [September 19, 2018, 8:44am UTC](https://forum.katalon.com/t/local-variables-between-called-test-cases/13298 "2018-09-19T08:44:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Said\_A](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@Said\_A](https://forum.katalon.com/u/Said_A)\
**Post date:** [September 19, 2018, 8:44am UTC](https://forum.katalon.com/t/local-variables-between-called-test-cases/13298/1 "2018-09-19T08:44:27Z")

</div>

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 🙂 The variable numberOf DisplayedItems is not known in test step 2.

In test step 1:

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

```

In test step 2:

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

```

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!  
Cheers,  
Said

---

<div class="post-metadata">

**Author:** ![Zarashima](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/zarashima/32/928_2.png) [@Zarashima](https://forum.katalon.com/u/Zarashima)\
**Post date:** [September 19, 2018, 9:10am UTC](https://forum.katalon.com/t/local-variables-between-called-test-cases/13298/2 "2018-09-19T09:10:25Z")

</div>

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:

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

```

2. Test Case 2:

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

```

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [September 19, 2018, 9:15am UTC](https://forum.katalon.com/t/local-variables-between-called-test-cases/13298/3 "2018-09-19T09:15:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Said\_A](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@Said\_A](https://forum.katalon.com/u/Said_A)\
**Post date:** [September 19, 2018, 10:14am UTC](https://forum.katalon.com/t/local-variables-between-called-test-cases/13298/4 "2018-09-19T10:14:26Z")

</div>

@[Vinh Nguyen](http://forum.katalon.com/profile/33/Vinh%20Nguyen) - Awesome - this worked!  
Thank you!!

---

<div class="post-metadata">

**Author:** ![Hiral](https://avatars.discourse-cdn.com/v4/letter/h/ea5d25/32.png) [@Hiral](https://forum.katalon.com/u/Hiral)\
**Post date:** [January 31, 2019, 10:54pm UTC](https://forum.katalon.com/t/local-variables-between-called-test-cases/13298/5 "2019-01-31T22:54:58Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [February 1, 2019, 1:29am UTC](https://forum.katalon.com/t/local-variables-between-called-test-cases/13298/6 "2019-02-01T01:29:29Z")

</div>

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

> [@Import/Export function for Test Case variables](http://forum.katalon.com/t/import-export-function-for-test-case-variables/13416/3):
>
> Marek, I think that a GlobalVariable of type java.util.Map would be useful for you. I have made a project “[KatalonDiscussion9854](https://github.com/kazurayam/KatalonDiscussion9854)” to demonstrate my proposal. You can download the zip file from [Releases](https://github.com/kazurayam/KatalonDiscussion9854/releases) page. I would copy & paste the README here. --------------------------- How to run the demo start your Katalon Studio, open this project please note that a Profile default defines a GlobalVariable named MEMORY of type java.util.Map. select Test Suites/TS0 and run it Processing GlobalVari…

---

<div class="post-metadata">

**Author:** ![Hiral](https://avatars.discourse-cdn.com/v4/letter/h/ea5d25/32.png) [@Hiral](https://forum.katalon.com/u/Hiral)\
**Post date:** [February 1, 2019, 3:02pm UTC](https://forum.katalon.com/t/local-variables-between-called-test-cases/13298/7 "2019-02-01T15:02:42Z")

</div>

Thank you very much.

This is exactly what I was looking for.
