# How to pass a variable from one testcase to another

**URL:** <https://forum.robotframework.org/t/how-to-pass-a-variable-from-one-testcase-to-another/5966>\
**Category:** Robot Framework\
**Created:** [19 July 2023 14:01 UTC](https://forum.robotframework.org/t/how-to-pass-a-variable-from-one-testcase-to-another/5966 "2023-07-19T14:01:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samsanati2000](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/samsanati2000/32/4108_2.png) [@samsanati2000](https://forum.robotframework.org/u/samsanati2000)\
**Post date:** [19 July 2023 14:01 UTC](https://forum.robotframework.org/t/how-to-pass-a-variable-from-one-testcase-to-another/5966/1 "2023-07-19T14:01:26Z")

</div>

Hi community!  
I am trying to pass a variable from testcase 1 to testcase 2 using set global variable  
but it is not working  
this is how I do it  
in test case one,I fetch my first variable which is my sales orde id  
${orderID} Get Text //div[@name=‘TabHeaderGeneral\_SalesTable\_SalesId’]  
that works fine!  
Then I pass this variable to my Global variable using  
${Global} Set Global Variable ${orderID}  
so I have now created a global variable with the value ${orderID}

in test case 2  
I am trying to call ${Global} and it is not working

Input Text (any xapth) ${Global}  
error says ${Global} not found

---

<div class="post-metadata">

**Author:** ![JaPyR](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/japyr/32/756_2.png) [@JaPyR](https://forum.robotframework.org/u/JaPyR)\
**Post date:** [19 July 2023 14:15 UTC](https://forum.robotframework.org/t/how-to-pass-a-variable-from-one-testcase-to-another/5966/2 "2023-07-19T14:15:51Z")

</div>

`Set Global Variable` works differently. Syntax is the following:

```plaintext
Set Global Variable name value

```

So in your case it should be:

```plaintext
Set Global Variable ${ORDER_ID} ${orderID}

```

and later

```plaintext
Input Text xpath=... ${ORDER_ID}

```

_Side-note: You should think twice before making one tests dependent on another._

---

<div class="post-metadata">

**Author:** ![samsanati2000](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/samsanati2000/32/4108_2.png) [@samsanati2000](https://forum.robotframework.org/u/samsanati2000)\
**Post date:** [19 July 2023 17:47 UTC](https://forum.robotframework.org/t/how-to-pass-a-variable-from-one-testcase-to-another/5966/3 "2023-07-19T17:47:57Z")

</div>

Hi Aleh Borysiewicz,

Thank for your comment!  
unfortunately that did not work neither

---

<div class="post-metadata">

**Author:** ![JaPyR](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/japyr/32/756_2.png) [@JaPyR](https://forum.robotframework.org/u/JaPyR)\
**Post date:** [19 July 2023 21:50 UTC](https://forum.robotframework.org/t/how-to-pass-a-variable-from-one-testcase-to-another/5966/4 "2023-07-19T21:50:56Z")

</div>

Without more details we are not able to help.

```plaintext
***Test Cases***
Test Case 1
    Set Global Variable ${ORDER_ID} 123

Test Case 2
    Log To Console ${ORDER_ID}

```

Output:

```console
==============================================================================
Test Case 1 | PASS |
------------------------------------------------------------------------------
Test Case 2 123
Test Case 2 | PASS |
------------------------------------------------------------------------------
DemoGlobals | PASS |
2 tests, 2 passed, 0 failed
==============================================================================

```

---

<div class="post-metadata">

**Author:** ![samsanati2000](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/samsanati2000/32/4108_2.png) [@samsanati2000](https://forum.robotframework.org/u/samsanati2000)\
**Post date:** [20 July 2023 13:39 UTC](https://forum.robotframework.org/t/how-to-pass-a-variable-from-one-testcase-to-another/5966/7 "2023-07-20T13:39:27Z")

</div>

I found out ,what my mistake was  
I was running every test case seperately instead of running the suite

Thanks very much for your help and support
