gpt4 book ai didi

python - 想从我的机器人框架输出文件中过滤掉失败消息

转载 作者:行者123 更新时间:2023-12-05 07:54:52 24 4
gpt4 key购买 nike

我想从在 Robot Framework 中执行我的测试用例后生成的输出文件中过滤失败消息。我尝试过像 from robot.api import ExecutionResult 这样的模块,但它只给我通过和失败的测试用例的数量。

我也尝试过其他机器人框架 Libtraries,例如 import robot.errors 来过滤掉所有错误消息,但没有成功。下面是我的代码块:`

#!/usr/bin/python
from robot.api import ExecutionResult
import robot.errors
from robot.result.visitor import ResultVisitor
xmlpath = "<output.xml PATH>"
result = ExecutionResult(xmlpath)
result.configure(stat_config={'suite_stat_level': 2,
'tag_stat_combine': 'tagANDanother'})
stats = result.statistics
print stats.total.critical.failed
print stats.total.critical.passed
print stats.total.critical.passed + stats.total.critical.failed

class FailureCollector(ResultVisitor):
def __init__(self):
self.failures = []

def visit_test(self, test):
if not test.passed:
self.failures += [test]

failure_collector = FailureCollector()
result.visit(failure_collector)
print failure_collector.failures
#the above print gives me all failed testcases as a list Eg: ['test1:My example Testcase1','test2:My example Testcase2' ]`

完成这项工作的任何示例都将非常有帮助。

最佳答案

我已经尝试了很多通过使用 Robot Framework API 来获得我预期的输出,但没有找到合适的解决方案。最后,我通过使用 import xml.etree.ElementTree as ET 模块得到了我的解决方案。通过使用 xml.etree.ElementTree 模块,我正在解析我的机器人 result.xml 文件并完成我的工作。`

import xml.etree.ElementTree as ET
import re

tree = ET.parse('<output.xml file Path>')
root = tree.getroot()
testplans = <Testplans as a list>

i = 0
err_dict = {}
for testplan in testplans:
full_err_list = []
err_list = []
for suite_level_1 in root:
try:
if suite_level_1.tag == "suite":
for suite_level_2 in suite_level_1:
if suite_level_2.tag == "suite" and suite_level_2.attrib['name'] == testplan:
for suite_level_3 in suite_level_2:
if suite_level_3.tag == "suite":
for test in suite_level_3:
if test.tag == "test":
for kw_level_5 in test:
if kw_level_5.tag == "kw" and kw_level_5.attrib['name'] == '<specific keyword under which you expect your result(error or Success message >':
for msg in kw_level_5:
if msg.tag == 'msg':
err_str = msg.text
#print err_str
mat = re.match(r'\$\{FinalResult\}\s=\s(.*)',err_str)
if mat and mat.group(1) != 'Succeeded.':
i=i+1
#print mat.group(1), i
err = mat.group(1)
full_err_list.append(err)
if err not in err_list:
err_list.append(err)
except:
print "Errors found"
break
err_dict[testplan] = err_list
print "\n########## "+testplan+" ##########\n"
print "Total no of failures", len(full_err_list)
for err_name in err_list:
print err_name, "===>>", full_err_list.count(err_name)
##The above will print the error name and its count in specific testPlan`

关于python - 想从我的机器人框架输出文件中过滤掉失败消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30859069/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com