问题
How can I test a python function in Robot Framework 3. The code I want to test is:
def message(msg):
print ('your message is ' + msg)
return True
The robot test:
*** Settings ***
Library Lib
*** Test Cases ***
Case1
message "hello"
回答1:
If you have a file with python functions in it, you need to reference the filename with suffix in the robot test (assuming your file is named Lib.py
).
Example:
*** Settings ***
Library Lib.py
回答2:
You need to follow the below steps to get the function called from within robotframework,
Step 1: Create a python file with the function as follows C:\Users\kgurupra\pyfirst.py
def message(msg):
print ('your message is ' + msg)
return True
Step2: Make sure your .py file in the PYTHONPATH - THIS IS VERY IMPORTANT STEP
Step3: Create your robotfile as mentioned below,
*** Settings ***
Library String
Library Collections
Library Selenium2Library
**Library pyfirst.py**
*** Variables ***
${robotVar} = FooBarBaz
${MY_DATA_TABLE_VALUES_TEMP} {"foo": "this is foo", "bar": "this is bar"}
*** Test Cases ***
Case1
message "hello"
Step4: You should see the output as mentioned below,
(rf1) C:\Users\kgurupra>robot rbpy.robot
==============================================================================
Rbpy
==============================================================================
Case1 | PASS |
------------------------------------------------------------------------------
Rbpy | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\Users\kgurupra\output.xml
Log: C:\Users\kgurupra\log.html
Report: C:\Users\kgurupra\report.html
回答3:
def message(msg): return ('your message is ' + msg) case1=message("hello")
来源:https://stackoverflow.com/questions/47918971/test-a-python-function-in-robot-framework-3