在 Robot Framework 3 中测试 Python 函数 [英] Test a python function in Robot Framework 3
本文介绍了在 Robot Framework 3 中测试 Python 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Robot Framework 3中测试python函数.我要测试的代码是:
def 消息(味精):打印('你的消息是' + msg)返回真
机器人测试:
*** 设置 ***图书馆*** 测试用例 ***情况1留言你好"
解决方案
您需要按照以下步骤从robotframework中获取调用的函数,
第一步:创建一个python文件,函数如下C:\Users\kgurupra\pyfirst.py
def 消息(味精):打印('你的消息是' + msg)返回真
第 2 步:确保您的 .py 文件位于 PYTHONPATH 中 - 这是非常重要的步骤
第 3 步:如下所述创建您的机器人文件,
*** 设置 ***库字符串图书馆馆藏图书馆 Selenium2Library**库pyfirst.py***** 变量 ***${robotVar} = FooBarBaz${MY_DATA_TABLE_VALUES_TEMP} {"foo": "this is foo", "bar": "this is bar"}*** 测试用例 ***情况1留言你好"
Step4:您应该会看到如下所示的输出,
<预><代码>(rf1) C:\Users\kgurupra>robot rbpy.robot==============================================================================比比==============================================================================案例1 |通行证 |-------------------------------------------------------------------------------价格 |通行证 |1 个关键测试,1 个通过,0 个失败总共 1 次测试,1 次通过,0 次失败==============================================================================输出:C:\Users\kgurupra\output.xml日志:C:\Users\kgurupra\log.html报告:C:\Users\kgurupra\report.htmlHow 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"
解决方案
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
这篇关于在 Robot Framework 3 中测试 Python 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文