# How to assign global variable to another variable in another robot file

**URL:** <https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083>\
**Category:** Robot Framework\
**Created:** [12 January 2022 16:04 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083 "2022-01-12T16:04:30Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![grarun11](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@grarun11](https://forum.robotframework.org/u/grarun11)\
**Post date:** [12 January 2022 16:04 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/1 "2022-01-12T16:04:30Z")

</div>

1

I have assigned global variable as ${googlesite} = [http://google.com](http://google.com/) and I want to use this variable in another robot file under variable section as

robot1.robot

${googlesite} = [http://google.com](http://google.com/)

\*\*\* keywords \*\*\*

set suite variable ${googlesite}

robot2.robot

\*\*\* Variables \*\*\*

${googlelogin} = ${googlesite}/login.html

\*\*\* Keywords \*\*\*  
log to console ${googlesite}-- Its printing as [[http://google.com](http://google.com)]

log to console ${googlelogin}-- printing only ./login.html

(not appending ${googlesite} from variables section)

---

<div class="post-metadata">

**Author:** ![Wolfe1](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/wolfe1/32/3386_2.png) [@Wolfe1](https://forum.robotframework.org/u/Wolfe1)\
**Post date:** [12 January 2022 19:18 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/2 "2022-01-12T19:18:26Z")

</div>

Probably best to use a resource or a variable file in this case: [Robot Framework User Guide](http://robotframework.org/robotframework/2.8.7/RobotFrameworkUserGuide.html#resource-and-variable-files)

Both your tests would import the resource file and be able to use the variables/methods within. This assumes the variable will remain the same throughout your tests.

---

<div class="post-metadata">

**Author:** ![grarun11](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@grarun11](https://forum.robotframework.org/u/grarun11)\
**Post date:** [12 January 2022 19:56 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/3 "2022-01-12T19:56:53Z")

</div>

I tried as resource import in robot2 still not working.

---

<div class="post-metadata">

**Author:** ![Wolfe1](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/wolfe1/32/3386_2.png) [@Wolfe1](https://forum.robotframework.org/u/Wolfe1)\
**Post date:** [13 January 2022 13:08 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/4 "2022-01-13T13:08:07Z")

</div>

All files are in the same directory for this example:

globalVariables.resource

```
***Variables***
${googlesite}= https://google.com

```

robot2.robot

```
***Settings***
Resource globalVariables.resource 

***Keywords***
log to console ${googlesite}
```

---

<div class="post-metadata">

**Author:** ![grarun11](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@grarun11](https://forum.robotframework.org/u/grarun11)\
**Post date:** [13 January 2022 13:49 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/5 "2022-01-13T13:49:06Z")

</div>

Thanks Brandon.

This is what I am looking for …

In robot2.robot  
\*\*\* Settings \*\*\*  
Resource globalVariables.resource

\*\*\* Variables \*\*\*  
${Login} ${googlesite}/login.html  
${logout} ${googlesite}/logout.html

\*\*\* Keywords \*\*\*  
log to console ${Login}  
log to console ${Logout}

Should display as [https://google.com/login.html](https://google.com/login.html)  
[https://google.com/logout.html](https://google.com/logout.html)

I kept resource files under resource folder and robot files in different folder

---

<div class="post-metadata">

**Author:** ![Wolfe1](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/wolfe1/32/3386_2.png) [@Wolfe1](https://forum.robotframework.org/u/Wolfe1)\
**Post date:** [13 January 2022 14:22 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/6 "2022-01-13T14:22:07Z")

</div>

In that case depending on your file structure you will need to use a relative path for the resource import:

> <https://stackoverflow.com/questions/44717988/how-to-specify-relative-path-in-robot-framework-using-selenium>

> <https://stackoverflow.com/questions/33137570/robot-framework-using-relative-paths-to-run-tests-from-different-directory-var>

Unless I am misunderstanding and you are saying you have everything working now?

---

<div class="post-metadata">

**Author:** ![grarun11](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@grarun11](https://forum.robotframework.org/u/grarun11)\
**Post date:** [13 January 2022 14:59 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/7 "2022-01-13T14:59:48Z")

</div>

Currently I am using all global variables under keyword since its not working under variables. Pls see below code

globalVariables.resource

\*\*\* Variables \*\*\*  
${googlesite}= [https://google.com](https://google.com)

In robot2.robot  
\*\*\* Settings \*\*\*  
Resource globalVariables.resource

\*\*\* Keyword \*\*\*  
Set urls  
Set Global Variable ${Login} ${googlesite}/login.html  
Set Global Variable ${logout} ${googlesite}/logout.html

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [13 January 2022 22:07 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/8 "2022-01-13T22:07:32Z")

</div>

It works as expected.  
You where however not using correct keywords syntax in your posts…  
(Maybe just a mistake here…)

[Robot Live Code Playground](https://robotframework.org/code/?codeProject=N4IgdghgtgpiBcIDCBXAzgFwPZRAGhABMY0BjAJwEsAHDSrMBEfEAM0oBsSEBtUdrgDlocRABUSGAMopKGGADpyWAEZYMLUg3lgNiAFSGABFJgY6YAOZojh-QB0wAJRJYU5UjCPejAaxgAngDuWOSEaEqu7p6OjnZGEphGSBBoJLaGjokYjj5GADJYlkZQASaUxGggAL54-JwwwrBM-sGh4ZFobh5wBFq6MLpM8abmlFY2do4uXdFeeQBuEFQQKlwR5FE9sWDxAGrLlKvrGQ5gACTAhZbj1XlGl5ZYRetyMNUA9BxF4woAFhgoBxHJdvk8UBg7j5Hs9LK95J8wW4MP9AcCwHFjABpQIhMKTTJga4lMpSCokXI+YliLDJBhdLh5MR-Sg2ME2DB-LwYEJGJYrNYkeCU7zU2lIelYRnQq4-MDVEUFIoJcWS6XeUFFZEKxi1epCERMflHQUbLaeTTaQZ6ED7Q7HdJTC7AJ4vEhvaoAXnuAIw1DQ8A+HyCIYUrrhii0UEcNTqbAaTVEIAACgFOQwcW18QpqAFLQMhohY-rGobEKn02ADgL1jm830rYXmNUALoEYhUBYwQjJ5QAKxgpD0GHIKHeQA)

---

<div class="post-metadata">

**Author:** ![grarun11](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@grarun11](https://forum.robotframework.org/u/grarun11)\
**Post date:** [13 January 2022 22:46 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/10 "2022-01-13T22:46:53Z")

</div>

May be I didn’t exact scenario. Please check here I updated the code.

[https://robotframework.org/code/?codeProject=N4IgdghgtgpiBcIDCBXAzgFwPZRAGhABMY0BjAJwEsAHDSrMBEfEAM0oBsSEBtUdrgDlocRAGsYATwDuWcoTQA6ciSwpypOAVIMMMMBiYAqEwAIAyjAx0wAczSmTRgDpgASqvWbTPnwDcIKggAIy4lFTQ1DRhXVydTADVAyhCwxxNXABJgABksW0owAF9fH2z1DiKAeg58wsUACwwoDizgWts1DBLfcvJKmvyuxubWsDizAGkpWXkHJ1c821MoSQtKYjRXUqXTABUsUyQGSK5SvYbKBw6HDAaYUwxZUwCg0JJ4bd9dg6OTrDOvVydWKXx8P0OxzApweQI6XSKrhARTw-E4MGEsCYrxS73CnmiLB0Bn0hkQ8SSbzSCzA2TQlD0PQA4lh8lw2hVEeNufFpjI5Ap0i4wJYMKZ6XowaYAJIAMVMdIZMB6PgAvKrTAByFlsmCaqWlPqVUqixLJVKw0q+JoYahoeBVKqdXWKHRQKUAURy5g9MvlQIlytK6q1AE0IA1WfqwFbDcBObGLFYzVTLT4bXaHVVJBHWa6cJ7BAARKWmpm1YIQDgp3GAsrx-pFZEAXQIxCofhghAACuQsAArGCkMkYcgoZVAA](https://robotframework.org/code/?codeProject=N4IgdghgtgpiBcIDCBXAzgFwPZRAGhABMY0BjAJwEsAHDSrMBEfEAM0oBsSEBtUdrgDlocRAGsYATwDuWcoTQA6ciSwpypOAVIMMMMBiYAqEwAIAyjAx0wAczSmTRgDpgASqvWbTPnwDcIKggAIy4lFTQ1DRhXVydTADVAyhCwxxNXABJgABksW0owAF9fH2z1DiKAeg58wsUACwwoDizgWts1DBLfcvJKmvyuxubWsDizAGkpWXkHJ1c821MoSQtKYjRXUqXTABUsUyQGSK5SvYbKBw6HDAaYUwxZUwCg0JJ4bd9dg6OTrDOvVydWKXx8P0OxzApweQI6XSKrhARTw-E4MGEsCYrxS73CnmiLB0Bn0hkQ8SSbzSCzA2TQlD0PQA4lh8lw2hVEeNufFpjI5Ap0i4wJYMKZ6XowaYAJIAMVMdIZMB6PgAvKrTAByFlsmCaqWlPqVUqixLJVKw0q+JoYahoeBVKqdXWKHRQKUAURy5g9MvlQIlytK6q1AE0IA1WfqwFbDcBObGLFYzVTLT4bXaHVVJBHWa6cJ7BAARKWmpm1YIQDgp3GAsrx-pFZEAXQIxCofhghAACuQsAArGCkMkYcgoZVAA)

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [13 January 2022 22:53 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/11 "2022-01-13T22:53:03Z")

</div>

Still it works, when you fixed all your syntax errors.

[Try It out HERE](https://robotframework.org/code/?codeProject=N4IgdghgtgpiBcIDCBXAzgFwPZRAGhABMY0BjAJwEsAHDSrMBEfEAM0oBsSEBtUdrgDlocRABUSGAMopKGGADpyWAEZYMLUg3lgNiAFSGABFJgY6YAOZojh-QB0wAJRJYU5UjCPejANwhUECpcaEqu7p6OjnZGEphGSBBoJLaGjnEYCUleAIyOPiYQAJ5GABIwHBxYRgDqWOQchAUA4lhYllz5PgAy7bHVSAxoWFwFACTA7hwAvlFgBVLFZRVVtfWNBQCaEAAWbV3evZb9CUMjXj4TU9Mg03j8nDDCsEwA1jBFAO71hKHk4R44AQtLoYLomLd7mxHs9RCB-IFgiQwsMIkCQCCdHoQDEANIfb7kX6pBxgRYlcqVap1BqEA5GHgAQXIlhQsF0aAAuuNgGg5DBZvMfABJABiBQA5BM+fJphKjABeBVGCWtdpcCX0nnXBZmIwANQClCCowKBR25moaHgAHobZY2h1FFooPSAKLdKRuoxiyXS-lyxXKiXbPZYTVCs3eK4NaZRkx6w2I00+C0YK22m1FXZtBQu92CAAi9NMmWaVRUEA4BqNJou0cmschDyEIiYAAUihg9mB8V8fqFqEVNNowdjm9DWy9EJ3uwwk8akYPh8DR+DELdOQRiFRfDBCO3lAArGCkPQYcgoAVAA)

And also if you work with global variables.

---

<div class="post-metadata">

**Author:** ![grarun11](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@grarun11](https://forum.robotframework.org/u/grarun11)\
**Post date:** [13 January 2022 23:02 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/12 "2022-01-13T23:02:21Z")

</div>

If you append under variables its working. Pls check keywords.resource file

```python
***Settings***
Resource variables.resource

***Variables***
${Login} ${url}/login.html
${logout} ${url}/logout.html

***Keywords***
Log my Sides
    Log To Console This logs the two variables:
    Log To Console ${Login}
    Log To Console ${logout}

```

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [13 January 2022 23:07 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/13 "2022-01-13T23:07:21Z")

</div>

could you please try to create a complete example of what you try to accomplish?

So if i understand you correctly, you try to set a variable with a keyword.  
The `${url}` variable…

And then you want to use that variable in another variable in the variable section?

And you get the error, that this variable `${url}` is not set, when you call “`Log my Sides`” keyword?

---

<div class="post-metadata">

**Author:** ![grarun11](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@grarun11](https://forum.robotframework.org/u/grarun11)\
**Post date:** [13 January 2022 23:12 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/14 "2022-01-13T23:12:22Z")

</div>

Yes correct.

**So if i understand you correctly, you try to set a variable with a keyword.**  
**The `${url}` variable…**

When I run I am not getting ${url} part only displaying /login.html

---

<div class="post-metadata">

**Author:** ![René](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ren%C3%A9/32/7_2.png) [@René](https://forum.robotframework.org/u/Ren%C3%A9)\
**Post date:** [13 January 2022 23:22 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/15 "2022-01-13T23:22:50Z")

</div>

OK.

The problem is, that if you import that resource file with your keyword, that keyword is not yet executed…  
So the created variables just have not set variables in there.

1. You have to call the actual keyword, that calculates google or yahoo…
2. Now the variable `${url}` is globally set, now you can use it.
3. But this means, you have to resolve it now.
4. The variables section has already tried to read it way before that time! so no values there.

You can accomplish that by using the variable as string with a backslash escaped and the replace it with its value after you called the set keyword.

https://robotframework.org/code/?codeProject=N4IgdghgtgpiBcIDCBXAzgFwPZRAGhABMY0BjAJwEsAHDSrMBEfEAM0oBsSEBtUdrgDlocRABUSGAMopKGGADpyWAEZYMLUg3lgNiAFSGABFJgY6YAOZojh-QB0wAJRJYU5UjCPfvANwhUECpcaEqu7p6OjnZGAGoBlEEhtoaOACTAADJYlpRgAL4+3vb2Ge4c+QD0HDl5CgAWGFAc6cA1lm4YhT4lZeQV1TmdDU0tYNHGEphGSBBoJCn6i47ZlkZQAJ4mlMRojkXzGEZocjD7PqtG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CimSkI6MWaKeeABaLpfLAE0IPUgzW022SWGtyYzM3Pa3vB2uz3KhtV0HBzhR4IACI4pv+moqCAcA9ouvAMOmgC6BGIKhfBgQgAAVlAAKxgUg9AwcgUBgfIgA)

Click the run button.

And by the way, you do not need to set `${url}` at the variables section if you run that keyword.  
In your situation before it was just that the variable `${url}` is never set by your code, so adding that to the ` ***Variables*** ` did just cause an error less.  
But when calling that setter thing, everything is fine.

---

<div class="post-metadata">

**Author:** ![grarun11](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@grarun11](https://forum.robotframework.org/u/grarun11)\
**Post date:** [13 January 2022 23:33 UTC](https://forum.robotframework.org/t/how-to-assign-global-variable-to-another-variable-in-another-robot-file/3083/16 "2022-01-13T23:33:27Z")

</div>

Thanks Rene. This one works.

Can you try variables section in under keyword resource file instead of using in same file.
