Reputation: 337
We have already automated scenarios using python scripts(.py
). We would like to execute these scripts in Robot Framework. Is there any option to execute Python script in RF.
Could any one please suggest me here.
Upvotes: 1
Views: 39733
Reputation: 300
Lets assume you have a demo test.py file in the same folder as your test.robot file. Your test.robot file should look like this:
*** Settings ***
Library Process
*** Test Cases ***
Python Program Testing
${result} = Run Process python ${CURDIR}/test.py
Log To Console ${result.stdout}
where is your test.py file might be:
def main():
print("Hello World!")
if __name__ == "__main__":
main()
if you run robot test.robot command it should produce the following results:
==============================================================================
Exec Python File
==============================================================================
Python Program Testing .Hello World!
Python Program Testing | PASS |
------------------------------------------------------------------------------
Exec Python File | PASS |
1 test, 1 passed, 0 failed
Upvotes: 0
Reputation: 1
If you want to use your class in RobotFramework you can do it by using Library keyword, for example :
*** Settings ***
Library your_file.LaunchApp detransitPath=whatever AS app
*** Keywords ***
Keyword 1
app.launchApp
But to do so, you might need to add ROBOT_LIBRARY_SCOPE = "GLOBAL"
in your class :
class LaunchApp:
ROBOT_LIBRARY_SCOPE = "GLOBAL"
def __init__(self,detransitPath):
self.detransitPath = detransitPath
Upvotes: 0
Reputation: 385800
You can use the run_process keyword from the process library. It returns an object that has the status code, stdout and stderr.
For example, this runs the script /tmp/helloworld.py:
# example.robot
*** Settings ***
| Library | Process
*** Test Cases ***
| Example of running a python script
| | ${result}= | run process | python | /tmp/helloworld.py
| | Should be equal as integers | ${result.rc} | 0
| | Should be equal as strings | ${result.stdout} | hello, world
Upvotes: 10