1部脚、文件robot\conf\settings.py? 默認(rèn)重試三次
在'RunEmptySuite' : ('runemptysuite', False), 后增加'Retry' : ('retry',3),
2漆改、文件robot\model\itemlist.py? ?visit函數(shù)用來進(jìn)行執(zhí)行對應(yīng)的testcase
1)增加import time?
2)修改visit 函數(shù)
將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對應(yīng)的屬性?-Q --retry retry? ?Set the retry times if test failed.?
3)main函數(shù)增加重試機(jī)制導(dǎo)致報告問題的修改
在LOGGER.info("Tests execution ended. Statistics:\n%s"% result.suite.stat_message) 后面增加self._make(settings.output)
?4)增加_make函數(shù)去除重試導(dǎo)致的多余的測試用例关顷。邏輯大概是如果三次都出錯餐济,保留第一個錯誤的信息侨赡,如果存在成功嗦嗡,把老的失敗都刪除勋锤。
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()