Test a python function in Robot Framework 3

家住魔仙堡 提交于 2020-01-25 08:07:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!