Hi folks,
I find it is easy to go in circles with RF - something that seemed to work a while ago suddenly doesn't anymore and I have to revisit basic concepts. It is a bit difficult to keep in mind some basic principles so that they "stick"...
RF is very powerful, but the documentation examples tend to treat isolated aspects. To help our internal users get familiar more quickly, I am working on an internal "user guide" in which I am trying to put together a few more integrated examples, to show at once how many aspects are used together.
We have a need to share some global data across many hierarchical test suites. I am trying to make a simple example of use of Set Global Variable, but it is not working as I had hoped. I've used this approach successfully before, I believe, so I am confused as to what I'm doing wrong this time.
Part of this experiment was to explore the meaning of the sentence "If you need to share variables or keywords, you can put them into resource files that can be imported both by initialization and test case files." in the User Guide. I was interpreting "share" as to mean "make globally available" but that is not how it worked.
Here is the structure of my example:
shared/
common.robot
test_shrd_var2/
__init__robot
tests/
tests1.robot
tests2.robot
common.robot:
*** Variables ***
${counter} ${1}
*** Keywords ***
Increment Counter and Report Result
[Arguments] ${ctr}
${ctr} = Set Variable ${ctr + 1} # 'Set Variable ${ctr} + ${1}' didn't work
[Return] ${ctr}
__init__.robot:
*** Settings ***
Resource ../shared/common.robot
Suite Setup Tests Setup
*** Keywords ***
Tests Setup
Set Global Variable ${glb_ctr} ${counter}
tests1.robot / tests2.robot:
*** Settings ***
Resource ../../shared/common.robot
*** Test Cases ***
Increment Counter
${glb_ctr} = Increment Counter and Report Result ${glb_ctr}
The two .robot files are identical and the intent is to just have them run in a sequence and modify the simple global variable.
When I realized that just including "common.robot" in both .robot files in fact did not make the ${counter} variable available "globally" to both ("share"), I introduced the __init__.robot and tried to use the Set Global Variable in there to create a new ${glb_ctr} using the ${counter} from the common.robot shared file.
I would have expected the ${glb_ctr} variable to go from values 1 to 2 in tests1.robot and then from 2 to 3 in tests2.robot, but instead each just goes from 1 to 2. It seems that ${glb_ctr} is not really global?
Thanks in advance for any advice,
Chuck