Robot Framework重点
2018-09-10 本文已影响123人
WeiFong
自动化项目的目录结构
目录结构最佳以数据环境层次为主
常用自动化项目的目录结构
+─task
│ cfg.py
│
├─pylib # python资源库
│ __init__.py
│
├─rflib # robot资源库
│ rc.robot
│
└─tc # 测试套件目录
└─WEB界面测试
│ __init__.robot
│
└─管理员操作
│ __init__.robot
│
├─老师管理
└─课程管理
常用
- should be true 使用python表达式--检查点(断言)
should be true '${nowdate}'[0:5]=='2018年'
${val1}= evaluate hello[0:3]
# val1 = hel
- Run Eywords
Run Eywords key1 AND key2
执行多个关键字,多个关键字之间使用AND连接起来
初始化清除
套件
# 套件开始执行前的初始动作
Suite Setup DelKeyword
# 套件全部执行完成后的执行动作
Suite Teardown DelKeyword
用例
# 用例开始执行前的执行动作(写在用例内首行)
[Setup] DelKeyword
# 用例结束后的执行动作(写在用例内最后一行)
[Teardown] DelKeyword
执行测试用例,生成报告名以别名显示
robot --pythonpath . --name 回归测试 tc
打开LOG DEBUG 开关,用于定位错误代码
robot --pythonpath . --loglevel DEBUG --name 回归测试 tc
根据 名称 选择测试用例
我们可以通过--test --suite 来指定执行哪些用例或者套件,而且还支持用通配符的方式
--test Example # 执行名为excample的用例
--test mytest --test yourtest # 执行名为mytest和yourtest的用例
--test example* # 执行名字以example开头的用例
--suite mysuite # 执行名为mysuite的套件
指定日志输出目录
robot --pythonpath . -d OutputDirectory -o output.xml -l log.html -r report.html --suite Testsuite tc
-d OutputDirectory 输出到目录
-o output.xml 数据内容
-l log.html 日志
-r report.html 测试报告
在执行目录后,其它参数前
参数文件
如果有的时候,参数太长,我们通常可以使用参数文件,我们可以把所有的参数都放在参数文件中(argfilename),比如:
--pythonpath .
--name 回归测试
--test *tc00001
--test *tc00002
tc
命令就只需要:robot -A argfilename
使用python编写类给robot作为关键字使用时,特别注意
ROBOT_LIBRARY_SCOPE= 'GLOBAL' # 使用python类做为robot关键字时,类中要加入这个静态属性,robot导入时只会产生一个实例
标签
*** Settings ***
Force Tags web测试 # 当前套件都具备该标签(web测试)
Default Tags notag # 套件缺省标签
*** Test Cases ***
用例10001
[Tags] 正确用户名 正确密码 10001 # 当前用例标签
套件目录不支持Default Tags
使用标签
# 执行包含 标签'foo'的标签用例
--include foo
# 执行不包含标签'foo'的用例
--exclude foo
# 执行同时包含标签'one','web test'的用例
--include oneAND"web test"
# 执行包含标签'one'或'two'的用例
--include oneOR"two"
# 执行包含标签'one'但不包含'two'的用例
--include oneNOTtwo
设置用例等级(缺省-关键用例)
我可以通过命令参数--critical(-c) 和 --noncritical (-n) 后面加tag名称来指定测试用例是否为关键测试用例