可以使用以下代码合并多个 BeautifulReport 测试报告:

import re
from BeautifulReport import BeautifulReport

# 读取多个测试报告
report1 = BeautifulReport('report1.html')
report2 = BeautifulReport('report2.html')
report3 = BeautifulReport('report3.html')

# 合并'testResult'里面的内容
result = ''
for report in [report1, report2, report3]:
    with open(report.report_file, 'r', encoding='utf-8') as f:
        content = f.read()
        match = re.search(r'<tbody id="testResult">(.+?)</tbody>', content, re.DOTALL)
        if match:
            result += match.group(1)

# 生成合并后的测试报告
with open('merged_report.html', 'w', encoding='utf-8') as f:
    f.write('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Merged Report</title></head><body><table><tbody id="testResult">%s</tbody></table></body></html>' % result)

这段代码读取多个测试报告,然后使用正则表达式找到每个测试报告中的<tbody id='testResult'>标签里面的内容,并将其合并到一个字符串result中。最后,将合并后的内容写入一个新的HTML文件中,形成一个新的测试报告。


原文地址: https://www.cveoy.top/t/topic/jvgu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录