RobotFramework 框架自动化执行策略

自动化测试的执行策略

绝大多数集成/系统测试框架都支持失败重运行的执行策略,从实现上来讲,大概分为2类:

  1. 就地重运行失败测试用例
  2. 执行完后,重新运行所有失败的测试用例

比如TestNG框架支持上述两种执行策略,pytest框架通过rerunfailures插件支持第1种执行策略。RF的rerunfailed参数支持第2种执行策略

RF的rerunfailed执行策略

RF的rerunfailed可以从第一次跑过的结果中,筛选出失败的用例重新执行,结合rebot的--merge功能,可以重新输出output.xml,在Jenkins上展示出最后的测试结果。

\> pybot
-R --rerunfailed output Select failed tests from an earlier output file to be re-executed. Equivalent to selecting same tests individually using --test option.

\> rebot
-R --merge When combining results, merge outputs together instead of putting them under a new top level suite. Example: rebot --merge orig.xml rerun.xml

与Jenkins结合使用(windows)

  1. Jenkins中添加构建步骤:Execute Windows batch command
  2. rfrerun mysuite.robot

与Jenkins结合使用(Linux)

Linux下shell脚本rfrerun

#!/bin/bash
rm -f output/output.xml
rm -f output/rerun.xml
rm -f output/first_run_log.html
rm -f output/second_run_log.html

echo
echo "#######################################"
echo "# First Run                                #"
echo "#######################################"
echo
pybot --outputdir output $@

#  Stop the script here if all the tests were OK
if [ $? -eq 0 ]; then
    exit 0  
fi

# backup the first log file
cp output/log.html  output/first_run_log.html

echo
echo "#######################################"
echo "# Rerun  Failed Tests      #"
echo "#######################################"
echo
pybot --outputdir output --nostatusrc --rerunfailed output/output.xml --output rerun.xml $@

# backup the second log file
cp output/log.html  output/second_run_log.html

echo
echo "########################"
echo "# Merge output files #"
echo "########################"
echo
rebot --nostatusrc --outputdir output --output output.xml --merge output/output.xml  output/rerun.xml
# Robot Framework generates a new output.xml

使用方式:

  1. Jenkins中添加构建步骤:Execute Linux shell command
  2. rfrerun mysuite.robot

执行结果

在log日志中,第一次失败的用例会显示2条message

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值