*** Test Cases ***
Testing Variable
| | {myTestUserame}= | Set Global Variable | {myTestName}
| | {result}= | run process | python | {TESTPATH} | -v | {myTestName}
| | Log to console | hello, world. {myTestName}
I need to pass the value to the “myTestUsername” variable in the testrun.py from the common_variables.py file. How can I do that?
This code | | ${result}= | run process | python | ${TESTPATH} | -v | ${myTestName} fails to execute.
This line of code | | Log to console | hello, world. ${myTestName} works fine and prints the value of the variable from common_variables.py in the PyCharm’s terminal.
I am very new to robotframework and any help from this community is highly appreciated.
back-up a bit and ask yourself “Why am I doing this?” You can pass variables on the robot command line using the -V, you can specify variables in a *yaml, so why are you attempting to retrieve a variable from python?
On a different problem, I am trying to a similar test in robotframework which is calling a python file using Process. It fails to call the python process on Windows machine whereas it works fine on Mac.
If I run the test.py independently it works.
The 2nd line in the test case also works, which prints the “Hello World” text in console.
Content in my Robotfile is like this:
*** Settings ***
Documentation Sample Test
Library Process
*** Test Cases ***
Test
| | {result}= | run process | python | test.py
| | {result}= | log to console | Hello World
Any suggestion on why it fails on Windows will immensely help me. Thank you!
with Process Library, I have found it important to give the full path of the process being executed.
Why are you setting result twice?
You have what I think are 2 RF statements on one line, using the old-fashioned vertical separator (or “pipe”) syntax. Why are you coding that way?
Your “log to console” works fine and then you are setting result to that?
${result}= Run Process /usr/local/bin/myapp ${service_address} some_literal_argument stdout=stdout.txt stderr=stderr.txt
Log Many ${result}
Should Be Equal As Integers ${result.rc} 0 msg=Failed with rc ${result.rc}
Should Be Empty ${result.stderr}
Should Contain ${result.stdout} Something
See the stdout and stderr parameters at the end of Run Process?
They can help you diagnose problem. Jani Mikkonen mentions the cwd (set your current working directory) parameter, which would also be a good thing to understand. I am executing tests on Mac and Linux, however, not Windows and so I can easily envision platform-related idiosyncrasies with Windows command PATH.
To me, the big realization was that the execution environment of my RF Run Process is NOT as simple as popping one of my own shells; i.e. you cannot make assumptions about the execution environment, env variables - they won’t be there the way you want them to be.