1、文件robot\conf\settings.py 默认重试三次
在'RunEmptySuite' : ('runemptysuite', False), 后增加'Retry' : ('retry',3),
2、文件robot\model\itemlist.py visit函数用来进行执行对应的testcase
1)增加import time
2)修改visit 函数
将for item in self._items:
item.visit(visitor)
修改为
for item in self._items:
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}']
time.sleep(3)
else:
break
else:
item.visit(visitor)
具体参考图片
3、文件robot\run.py 取来处理测试报告
1)import 增加from xml.dom import minidom
2)Options中增加retry对应的属性 -Q --retry retry Set the retry times if test failed.
3)main函数增加重试机制导致报告问题的修改
在LOGGER.info("Tests execution ended. Statistics:\n%s"% result.suite.stat_message) 后面增加self._make(settings.output)
4)增加_make函数去除重试导致的多余的测试用例。逻辑大概是如果三次都出错,保留第一个错误的信息,如果存在成功,把老的失败都删除。
def _make(self, outxml):
LOGGER.info("IN _make")
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.items():
LOGGER.info(len(el))
if el[-1] == el[0]:
continue
else:
last_status = list(set(el[-1].getElementsByTagName("status")).intersection(set(el[-1].childNodes)))[0]
if last_status.getAttribute('status') == "PASS":
for i in el[0:-1]:
textElement = i.nextSibling
suite.removeChild(i)
suite.removeChild(textElement)
else:
for i in el[1:]:
textElement = i.nextSibling
suite.removeChild(i)
suite.removeChild(textElement)
savefile = open(outxml, 'w', encoding='UTF-8')
xmldoc.writexml(savefile, encoding='UTF-8')
savefile.close()