使用自动化脚本进行测试,经常受环境影响等各方面导致本能成功的脚本失败,下面介绍了RFS框架下,失败重跑的方法:

通过改写RobotFramework源代码增加–retry选项,实现test级别的失败用例自动再执行:失败用例会重跑N次,直至成功or 耗尽重试次数,生成的日志和报告文件中只会体现最后一次执行的结果。

修改代码如下:

一、修改文件 C:\Python27\Lib\site-packages\robot\run.py

   1)在USAGE变量里添加下面红色内容。

  Options
  =======
   -X --retry retry   Set the retry times if test failed.
   -N --name name Set the name of the top level test suite. Underscores
   in the name are converted to spaces. Default name is
   created from the name of the executed data source.

2)增加导入模块

reload(sys)
sys.setdefaultencoding('UTF-8')
from xml.dom import minidom

3)RobotFramework类增加make方法

def make(self,outxml):
xmldoc = minidom.parse(outxml)
suiteElementList = xmldoc.getElementsByTagName('suite')
mySuite = []
for suiteElement in suiteElementList:
if suiteElement.childNodes is not None:
for element in suiteElement.childNodes:
if element.nodeName == 'test':
mySuite.append(suiteElement)
break
for suite in mySuite:
testElements = {}
for element in suite.childNodes:
if element.nodeName == 'test':
name = element.getAttribute('name')
if testElements.get(name) == None:
testElements.update({name:[element]})
else:
testElements.get(name).append(element)
for n,el in testElements.iteritems():
for i in el[0:-1]:
textElement = i.nextSibling
suite.removeChild(i)
suite.removeChild(textElement)
savefile = open(outxml,'w')
root = xmldoc.documentElement
root.writexml(savefile)
savefile.close()


4)RobotFramework类的main方法,加入红色内容 self._make(settings.output)

二、robot/conf/settings.py
修改_cli_opts字典,增加 ‘Retry’:(‘retry’,3)


三、robot/model/itemlist.py
修改visit方法如下

def visit(self, visitor):
for item in self:
if self.__module__ == 'robot.model.testcase' and hasattr(visitor,"_context"):
testStatus = ''
for i in range(0,int(visitor._settings._opts['Retry'])):
if testStatus != 'PASS':
if item.name in visitor._executed_tests:
visitor._executed_tests.pop(item.name)
item.visit(visitor)
testStatus = visitor._context.variables['${PREV_TEST_STATUS}']
else:
break
else:
item.visit(visitor)


四、robotide\contrib\testrunner\usages.py
  修改USAGE字符串,增加 -X –retry retry         Set the retry times if test failed.

现在完成了所有配置,可以运行一下试试了。次数的配置在settings.py下retry后修改即可。

转载:http://www.cnblogs.com/baihuitestsoftware/articles/5923411.html

Robot Framework-失败用例自动重跑的更多相关文章

  1. 【转载】扩展Robot Framework,实现失败用例自动再执行(失败重跑)

    使用自动化脚本进行测试,经常受环境影响等各方面导致本能成功的脚本失败,下面介绍了RFS框架下,失败重跑的方法: 通过改写RobotFramework源代码增加--retry选项,实现test级别的失败 ...

  2. 如何解决testng执行用例失败自动重跑问题

    注: 以下内容引自 http://blog.csdn.net/MenofGod/article/details/72846649 看过几个相关问题的帖子,内容类似,不过这篇解决问题的步骤和代码比较清晰 ...

  3. 【框架】Testng用例失败自动重跑(五)

    arrow是testng的一个扩展插件,参考arrow的源代码 1.新建一个工程,结果如图: 2.RetryListener.java的代码 package com.netease.qa.testng ...

  4. robot framework学习笔记之六—自动变量

    自动变量被RF框架创建和修改,在测试执行过程中值可能会变化;另外,某些自动变量在执行过程中并非总是可用.修改自动变量,并不能对变量的初始值产生影响.但可以用某些内建关键字来修改某些自动变量的值. 变量 ...

  5. TestNG失败用例自动截图

    参考:https://blog.csdn.net/wangxin1982314/article/details/50247245 1. 首先写一个截屏方法 public class ScreenSho ...

  6. testNG-失败用例重跑机制

    下面简单介绍下testNG的失败重跑的实现方法: 1.首先编写一个类,实现IRetryAnalyzer类,重写其中的retry方法. public class TestNGRetry implemen ...

  7. TestNG测试用例重跑详解及实践优化

    测试用例运行稳定性是自动化质量的一个重要指标,在运行中需要尽可能的剔除非bug造成的测试用例执行失败,对于失败用例进行重跑是常用策略之一.一种重跑策略是所有用例运行结束后对失败用例重跑,另一种重跑策略 ...

  8. TestNg失败重跑—解决使用 dataProvider 参数化用例次数冲突问题

    问题背景 在使用 testng 执行 UI 自动化用例时,由于 UI自动化的不稳定性,我们在测试的时候,往往会加上失败重跑机制.在不使用 @DataProvider 提供用例参数化时,是不会有什么问题 ...

  9. testng增加失败重跑机制

    注: 以下内容引自 http://www.yeetrack.com/?p=1015 testng增加失败重跑机制 Posted on 2014 年 10 月 31 日 使用Testng框架搭建自动测试 ...

随机推荐

  1. monkey test——学习资料

    出处: http://www.testwo.com/blog/6107 http://www.testwo.com/blog/6146 http://www.testwo.com/blog/6188 ...

  2. MessagePack Jackson 数据大小

    我们在使用 MessagePack 对 List 对象数据进行序列化的时候,发现序列化以后的二进制数组数据偏大的情况. 请注意,不是所有的 List 对象都会出现这种情况,这个根据你 List 对象中 ...

  3. Codevs 4373 窗口(线段树 单调队列 st表)

    4373 窗口 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题目描述 Description 给你一个长度为N的数组,一个长为K的滑动的窗体从最左移至最右端,你只 ...

  4. codevs 2977 二叉堆练习1x

    时间限制: 10 s 空间限制: 32000 KB 题目等级 : 白银 Silver       题目描述 Description 已知一个二叉树,判断它是否为二叉堆(小根堆) 输入描述 Input ...

  5. Keras学习笔记一:修改数据读入方式为本地图片读入

    第一种方法: Keras官方给的图片去噪示例要自动下载mnist数据集并处理,不能修改和加入自己的数据集. from keras.datasets import mnist (x_train, _), ...

  6. 【CSS】三栏/两栏宽高自适应布局大全

    页面布局 注意方案多样性.各自原理.各自优缺点.如果不定高呢.兼容性如何 三栏自适应布局,左右两侧300px,中间宽度自适应 (1) 给出5种方案 方案一: float (左右浮动,中间不用给宽,设置 ...

  7. org.apache.ibatis.binding.BindingException: Parameter 'xxx' not found.

    1. 情景重现 1.1 Mapper 代码 public interface DeviceFileInfoVOMapper { List<QueryFileDTO> selectVideo ...

  8. shell脚本--监控java进程存活脚本

    #!/bin/bash base_dir=/opt war_processor="tomcat" jar_processor="manager-server.jar pl ...

  9. 通过ID获取元素

    网页由标签将信息组织起来,而标签的id属性值是唯一的,就像是每人有一个身份证号一样,只要通过身份证号就可以找到相对应的人.那么在网页中,我们通过id先找到标签,然后进行操作. 语法: document ...

  10. mysql常用操作与日志

    在linux上的mysql命令 mysql -e "mysql内部命令" #可在外部显示myslq内的输出,-e可跟多条命令用;隔开 在mysql内的mysql命令 system ...