Reputation: 47
I set global variable in one code in robot framework. This code contains several test cases and I know how to share the global variable between test cases.
Set Global Variable ${Helen} ${value1}
But in my case, I have several codes like: code1 containing several test cases which call some code2 from another code which contains library.
How can I use global variable set in code1 into code2 ?
Should i put the path of code1 in code2 in Ressource sections?
Thank you
Upvotes: 1
Views: 2443
Reputation: 386342
How can I use global variable set in code1 into code2 ?
You shouldn't have to do anything out of the ordinary. Once you set a global variable with set global variable
it will be visible in all tests that run after it's been set.
Here's a quick example:
example1.robot
*** Test Cases ***
Example 1
set global variable ${message} Hello, world!
example2.robot
*** Test cases ***
Example 2
should be equal ${message} Hello, world!
Running the test
When you run the above with robot example1.robot example2.robot
, both tests will pass even though the global variable was set in the first file and referenced in the second file.
Upvotes: 1
Reputation: 6981
If you're new to Robot Framework then I'd advise to visit the Robot Framework Site section on Documentation. In particular the Quick Start Guide, How to .. and Do's and Don'ts should be of interest. To give you an introduction into what Robot Framework is and general test concepts.
Additionally I would recommend reading the Robot Framework User Guide. It is not only a good reference guide, but reading it from start to finish will introduce the different topics in a gradual manner. For this specific topic of Keyword reusability I'd recommend reading the User Guide section on Resource Files
There are also many other resources out there that explain the same material from a different angle. Although these can be great learning resources, they do base their basic material on the User Guide.
Upvotes: -2
Reputation: 150
Use Resource in settings
file1.robot
*** Variables ***
${Helen} value1
*** Keywords ***
Keyword 1
...
file2.robot
*** Settings ***
Resource file1.robot
*** Test Cases ***
Test 1
Log ${Helen}
Keyword 1
Upvotes: 0