robotframework built-in tools简介

Robotframework built in tools简介

Robot内置的工具为:Run、Rebot、libdoc、testdoc、tidy
可用使用这样的方式查看其使用方式python -m robot.run –help,
也可以Python35-32\Lib\site-packages\robot中直接看源码了解其内部实现过程。
还可以在https://robotframework-userguide-cn.readthedocs.io/zh_CN/latest/查看。
下面结合实际工作中使用的比较多的进行介绍。

1、robot执行用例

用法:python -m robot.run [options] data_sources
选项:
-F --extension value 解析指定后缀名的文件,多个后缀用:分割
Examples: --extension robot, -F robot:txt

给最高等级的用例集命名、文档描述和元数据
-N --name name
-D --doc documentation
-M --metadata name:value
Example: --metadata version:1.2

-G --settag tag * 给所有运行的用例加上指定的tag

-t --test name * 按用例名称指定用例执行,不区分大小写和空格(下同)
Examples: 用例名称Test91433 : 打电话
–test Test91433*执行
-s --suite name 按用例集名称指定用例集执行
Examples: --suite SMS, --suite SMS.T业务,–suite SMS.T业务. 短消息, --suite SMS. AT

-i --include tag * 选择指定tag的用例执行,可以用AND 、OR、NOT组合
Examples: --include foo --include bar*
–include fooANDbar*
-e --exclude tag * 不跑指定tag的用例
-R --rerunfailed output 重跑之前失败的用例
Examples: -R E:\log\20200628_130201\output.xml

-S --rerunfailedsuites output重跑之前失败的用例集

-c --critical tag * 指定tag的用例是关键的
-n --noncritical tag * 指定tag的用例是不关键的
-v --variable name:value 传参数值
Examples:
-v “FTP_PATH:ftp://vsftp:vsftp@192.168.74…178:21/package//TEST”
–variable str:Hello => ${str} = Hello
-v hi:Hi_World -E space:_ => ${hi} = Hi World
-v x: -v y:42 => ${x} = ``, ${y} = 42

-V --variablefile path * 存放参数的文件
Examples: --variablefile path/vars.yaml
–variablefile environment.py:testing

-d --outputdir dir 输出文件的存放路径
Examples: --outputdir “E:\log\20200628_130201”

-o --output file 指定输出文件,默认为output.xml
-l --log file HTML log file 默认为log.html
Examples: --log mylog.html, -l NONE
-r --report file HTML report file 默认为 report.html
-x --xunit file xUnit compatible result file.
–xunitskipnoncritical Mark non-critical tests on xUnit output as skipped.
-b --debugfile file 执行时的日志,默认是没有的
Examples: --debugfile debug.log

-T --timestampoutputs 输出文件加时间戳
Examples: -T -o output.xml -r report.html -l none
creates files like output-20070503-154410.xml and
report-20070503-154410.html.
–splitlog 分割日志
–logtitle title 给test log起个标题. 默认标题是
<Name Of The Suite> Test Log.
–reporttitle title 给测试报告起个标题. 默认标题是
<Name Of The Suite> Test Report.
–reportbackground colors 报告的背景颜色
Either all_passed:critical_passed:failed or
passed:failed. Both color names and codes work.
Examples: --reportbackground green:yellow:red
–reportbackground #00E:#E00
-L --loglevel level 日志等级. Available levels: TRACE,
DEBUG, INFO (default), WARN, NONE (no logging). Use
syntax LOGLEVEL:DEFAULT to define the default
visible log level in log files.
Examples: --loglevel DEBUG
–loglevel DEBUG:INFO
–suitestatlevel level 用例集层数等级,默认都显示
Example: --suitestatlevel 3
报告统计
–tagstatinclude tag * --tagstatexclude tag *
–tagstatcombine tags:name *
Examples: --tagstatcombine requirement-*
–tagstatcombine tag1ANDtag2:My_name
–tagdoc pattern:doc *
Examples: --tagdoc mytag:My_documentation
–tagdoc regression:Seehttp://info.html
–tagdoc owner-:Original_author
–tagstatlink pattern🔗title *
Examples: --tagstatlink mytag:http://my.domain:Link
-tagstatlink bug-
:http://tracker/id=%1:Bug_Tracker
–removekeywords all|passed|for|wuks|name:|tag: *
去除输出报告中关键字数据.
–listener class * 设置监听类
Examples: --listener MyListenerClass
–listener path/to/Listener.py:arg1:arg2
–warnonskippedfiles 跳过的测试数据会在报告和日志中产生warn
–nostatusrc 错误值返回0
–runemptysuite 空的用例集也执行
–dryrun 不用到关键字执行,为了确认测试数据
-X --exitonfailure 关键用例失败就停止
–exitonerror 用例失败就停止
–skipteardownonexit 测试过早结束时跳过teardown
–randomize all|suites|tests|none 测试用例次序随机
Examples: --randomize all
–randomize tests:1234
–prerunmodifier class * 执行前程序化修改用例集结构
–prerebotmodifier class * 生成报告前程序化修改结果模型
–console type 控制台报告类型
verbose: report every suite and test (default)
dotted: only show . for passed test, f for
failed non-critical tests, and F for
failed critical tests
quiet: no output except for errors and warnings
none: no output whatsoever
-. --dotted Shortcut for --console dotted.
–quiet Shortcut for --console quiet.
-W --consolewidth chars 显示控制台输出宽度,默认是 78.
-C --consolecolors auto|on|ansi|off 显示控制台输出颜色
auto: use colors when output not redirected (default)
on: always use colors
ansi: like on but use ANSI colors also on Windows
off: disable colors altogether
Note that colors do not work with Jython on Windows.
-K --consolemarkers auto|on|off 显示控制台输出颜色标记
-P --pythonpath path * 额外的Python库路径
Examples:
–pythonpath libs/
–pythonpath /opt/testlibs:mylibs.zip:yourlibs
-E star:STAR -P lib/STAR.jar -P mylib.jar
-E --escape what:with * 控制台有问题时退出字符
Examples:
–escape space:
--metadata X:Value_with_spaces
-E space:SP -E quot:Q -v var:QhelloSPworldQ
-A --argumentfile path * 更多的注释文件
Example file:
| --include regression
| --name Regression Tests
| # This is a comment line
| my_tests.robot
| path/to/test/directory/
Examples:
–argumentfile argfile.txt --argumentfile STDIN
-h -? --help 使用指导
–version 版本信息.

常用示例:
E:\testProject>
Python –m robot –suite SMS –-include smoke –-outputdir E:\log\3.5 –-debugfile debug.log E:\testProject

E:\testProject>
Python –m robot -R E:\log\20200628_130201\output.xml –outputdir E:\log\3.5\20201130 –-debugfile debug.log E:\testProject

E:\testProject>
Python –m robot --test Test91433* -T –outputdir E:\log\test –-debugfile debug.log E:\testProject

2、Rebot生成报告

用法: rebot [options] robot_outputs
选项:
选项很多与robot的类似,不再赘述。重点介绍下面几个
-R --merge 合成报告
Example: rebot --merge orig.xml rerun.xml
-d --outputdir dir 输出文件的存放路径
-o --output file 指定输出文件,默认为output.xml

常用示例:
合成xml文件并生成报告
rebot -o F:\testProject\ReportALL\output.xml -d F:\testProject\ReportALL -R F:\testProhect\ReportALL\output.xml F:\testProject\Report\output.xml
xml生成报告
rebot F:\testProject\Report\output.xml

补充说明:
由于Python崩溃、计算机异常关机等因素造成Output.xml不完整的处理方法如下。
首先用文本编辑工具(如Notepad++)打开一个完整的Output.xml文件,了解其中的文件结构,一般如下图所示。按层级高低往下分是xml、robot、suite、test,suite里面可以多个suite层级,另外还有statistics、errors与最高等级suite同级。

不完整的output.xml文件会类似下图,到323931行就截止了,后面就没有了,所以我们就需要通过文本编辑工具左边的点击最左边的+、-符号,找到最后一条测试用例,把这个test全部删掉(图中就是323414行到323931行),再补齐表尾的内容就可(图中是323986行到324067行,或者只补充合适次数的和),文件就会变得完整,就可以使用rebot生成报告了。

3、libdoc生成子项文档

用法:python -m robot.libdoc [options] library output_file
选项较少,感兴趣可以python –m robot.libdoc –help查看
常用示例:
C:\Users\h22>python -m robot.libdoc “C:\Program Files (x86)\Python35-32\Lib\site-packages\MyLibrary\FunctionItem\PhoneBook.py” C:\Users\h22\Desktop\777\PhoneBook.html

4、testdoc生成用例文档

把测试用例转成html文档,输入可以是文件或路径
用法:python -m robot.testdoc [options] data_sources output_file
选项很多与robot的类似,不再赘述
常用示例:
python -m robot.testdoc my_test.html testdoc.html
C:\Users\h22726>python -m robot.testdoc E:\temp自动化\testProject\SMS\Case\D业务 C:\Users\h22\Desktop\777\a.html

5、tidy测试数据整理工具

用于整理和转换测试数据文件的工具
用法:python -m robot.tidy [options] inputfile
python -m robot.tidy [options] inputfile [outputfile]
python -m robot.tidy --inplace [options] inputfile [more input files]
python -m robot.tidy --recursive [options] directory

选项:
-i --inplace 指定文件修改后会被覆盖,可以多个文件
Examples:
python -m robot.tidy --inplace tests.html
python -m robot.tidy --inplace --format txt *.html
-r --recursive 递归处理指定目录
-f --format txt|html|tsv|robot 输出文件格式
-p --usepipes 文本格式中使用(|)作为单元分割符
-s --spacecount number 文本格式中单元间隔的空格数
-l --lineseparator native|windows|unix 行分隔符,分别为 windows: CRLF、unix: LF
-h -? --help 帮助

常用示例:
C:\Users\h22\Desktop\777>python -m robot.tidy --usepipes --inplace DIE.txt

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值