# How to use the Global Variable

**URL:** <https://forum.katalon.com/t/how-to-use-the-global-variable/83913>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [February 2, 2023, 3:45am UTC](https://forum.katalon.com/t/how-to-use-the-global-variable/83913 "2023-02-02T03:45:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pttlinh231](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/pttlinh231/32/22419_2.png) [@pttlinh231](https://forum.katalon.com/u/pttlinh231)\
**Post date:** [February 2, 2023, 3:45am UTC](https://forum.katalon.com/t/how-to-use-the-global-variable/83913/1 "2023-02-02T03:45:06Z")

</div>

1. 

I want the test listener to use a global variable to execute a specific test case or test suite.  
I make global variable of type null and in the test listener i save the TestCaseContext object into the global variables. But i don’t know how to cast the global variable to the appropriate types explicitly.

1. When I use the global variable in the test listener and then switch the execution profile, does the global variable execute according to the active profile?

Pls help me

---

<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 2, 2023, 3:51am UTC](https://forum.katalon.com/t/how-to-use-the-global-variable/83913/2 "2023-02-02T03:51:07Z")

</div>

Please show your code and the error log you got.

---

<div class="post-metadata">

**Author:** ![pttlinh231](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/pttlinh231/32/22419_2.png) [@pttlinh231](https://forum.katalon.com/u/pttlinh231)\
**Post date:** [February 2, 2023, 4:17am UTC](https://forum.katalon.com/t/how-to-use-the-global-variable/83913/3 "2023-02-02T04:17:31Z")

</div>

It still execute the test case, but not execute specific test case that I want to  
In test listeners

```auto
@BeforeTestCase
	def sampleBeforeTestCase(TestCaseContext testCaseContext) {
		GlobalVariable.TEST_CASE_CONTEXT = testCaseContext.getTestCaseId()

```

In test case

```auto
testName = GlobalVariable.TEST_CASE_CONTEXT

```

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/6/f/6f3d775a548d874c34f6624bd020f8c43834ee7f.png)

---

<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 2, 2023, 5:18am UTC](https://forum.katalon.com/t/how-to-use-the-global-variable/83913/4 "2023-02-02T05:18:55Z")

</div>

What did you expect to see?

What did you actually see?

Please show the error message if you have got any

---

<div class="post-metadata">

**Author:** ![pttlinh231](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/pttlinh231/32/22419_2.png) [@pttlinh231](https://forum.katalon.com/u/pttlinh231)\
**Post date:** [February 2, 2023, 7:01am UTC](https://forum.katalon.com/t/how-to-use-the-global-variable/83913/5 "2023-02-02T07:01:29Z")

</div>

it does not have any error  
I just want to use global variables to perform a specific test case

---

<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 2, 2023, 9:14am UTC](https://forum.katalon.com/t/how-to-use-the-global-variable/83913/6 "2023-02-02T09:14:53Z")

</div>

I do not see what you want.

* * *

> [@pttlinh231](#):
>
> I just want to use global variables to perform a specific test case

You just want to learn how to use global variables?

Then, Katalon Studio provides some built-in sample projects. For example:

[https://docs.katalon.com/docs/get-started/sample-projects/webui/sample-webui-tests-project-healthcare-sample-in-katalon-studio](https://docs.katalon.com/docs/get-started/sample-projects/webui/sample-webui-tests-project-healthcare-sample-in-katalon-studio)

This project uses GlobalVariables. Why not you try this on your machine and read the code to learn how to use GlobalVariables?

---

<div class="post-metadata">

**Author:** ![pttlinh231](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/pttlinh231/32/22419_2.png) [@pttlinh231](https://forum.katalon.com/u/pttlinh231)\
**Post date:** [February 3, 2023, 2:00am UTC](https://forum.katalon.com/t/how-to-use-the-global-variable/83913/7 "2023-02-03T02:00:12Z")

</div>

Thank a lot
