robotframework

How to run 2 or more tests from a test suite and use variable? Robot Framework


when I run two tests from a test suite with the command:

robot -d results --include Test1ORTest2 tests/testfile.robot

I have multipe test in the testfile and want to run only these two, what works good with the command, but the problem is that I want to use a variable form Test1 and use it in Test2.

In test1 I get the value and that works like I exepect.

${VAR}    get element attribute    xpath=locator     value

set global variable    ${VAR}

In test2 I want to use the defined variable from test1, but I'm not getting to value I expect.

input text      xpath=locator       ${VAR}

The input text is: ''

So I'm getting nothing... I tried a few options, but I don't get it right...

For example:

${VAR}    get element attribute    xpath=locator     value

${VAR_FOR_TEST2}  set global variable    ${VAR}
input text      xpath=locator      ${VAR_FOR_TEST2}

I tried different options as shown above, but I also tried searching online for answers and try to recreate those solutions, but I don't get it to work properly.


Solution

  • The second way you tried, does not work because Set Global Variable does not return a value. The first, looks OK, but you should escape the $.

    This is documentation, screen capture on RIDE: enter image description here

    As you can see there is a recommendation to escape the $. Your step would be:

    set global variable    \${VAR}    ${VAR}
    

    You could also try the new VAR syntax: enter image description here