1.在关键字和参数之间必须有两个空格区分
2.每个testcases必须有2个字符的缩进
*** Test Cases ***
Test Robot Framework Logging #用例名称
Log "Test Logging" #关键字Log,参数Test Logging
3.变量的类型
(1)标量变量:${scalar},使用标量变量时,测试数据的值被分配的值所代替
(2)列表变量:@{LIST},列表变量的值是可以分配多个值给它
*** Test Cases ***
Test My Logging
My Logging "Test My Logging 1" "Test My Logging 2"
*** Keywords ***
My Logging
[Arguments] @{arg}
Log Many @{arg}
My Logging
[Arguments] ${msg} ${level}
Log ${msg} ${level}
4.robot内置模块
(1)Log
(2)Log Many
5.关键字可以单独写一个文件,在robot文件中引入就可以
*** Setting ***
Resource resource-1.txt
关键字文件命名为resource-1.txt
*** Keywords ***
My Logging
[Arguments] ${msg1} ${msg2}
Log Many ${msg1} ${msg2} ${msg1}
ZhangLu
[Arguments] @{arg}
Log Many @{arg}
***********************************************************************************************************
自己定义关键字,自定义的关键字需要用python代码来实现。在rf中,需要自定义python库
1.robot
*** Settings ***
Library test.py
***Test Cases ***
Test Print Info
sayhello zz
sayhello mark
sayhello yy
2.python代码
def sayhello(msg):
print("hello world!"+msg)
********************************************************************************************
pybot不支持问题
pip安装robot framework成功后,pybot执行.robot文件,一直报错,‘pybot’ 不是内部或外部命令,也不是可运行的程序
(1)环境变量设置中添加python的路径,还未解决继续步骤2
(2)在python的Scripts目录下加一个pybot.bat 文件 内容为
@Echo off
python -m robot.run %*
再次执行即可解决
******************************************************************************************************
DEMO
t_01.robot文件的内容如下:
*** Settings ***
Documentation THIS A TEST DEMO
Library p_print.py
Default Tags v0.1.1
*** Test Cases ***
Test Robot Framework Logging #用例名称
Log "Test Logging++++" #关键字Log,参数Test Logging
Test Print Info
sayhello zz
sayhello mark
sayhello yy
Test My Logging
My Logging "Test My Logging 1" "Test My Logging 2" "Test My Logging 3"
My Logging2 "Test My Logging " INFO
*** Keywords ***
My Logging
[Arguments] @{arg}
Log Many @{arg}
My Logging2
[Arguments] ${msg} ${level}
Log ${msg} ${level}
My Log To Console
[Arguments] ${msg}
Log To Console ${msg}
p.print文件内容如下:
def sayhello(msg):
print("hello world!"+msg)
程序运行结果如下:
PS D:\robotProject\gap-robot> robot -P . -d log/t_01 robot_script/testsuite/t_01.robot
==============================================================================
T 01 :: THIS A TEST DEMO
==============================================================================
Test Robot Framework Logging | PASS |
------------------------------------------------------------------------------
Test Print Info | PASS |
------------------------------------------------------------------------------
Test My Logging | PASS |
------------------------------------------------------------------------------
T 01 :: THIS A TEST DEMO | PASS |
3 tests, 3 passed, 0 failed
==============================================================================
Output: D:\robotProject\gap-robot\log\t_01\output.xml
Log: D:\robotProject\gap-robot\log\t_01\log.html
Report: D:\robotProject\gap-robot\log\t_01\report.html