Joa*_*lho 3 python robotframework
机器人框架吐出输出XML,然后用于构建HTML报告(带rebot),重新运行失败等.
我需要解析此文件以生成其他报告,特别是,我需要解析测试用例的文档以获取正则表达式,获取测试用例结果然后构建报告(这是为了与遗留系统集成).
Robot Framework是否提供了轻松解析输出XML文件的功能,或者我们只使用标准的XML解析库?
好的,找到3个可行的回复:
DbBot和查询创建的数据库.xml.etree.ElementTree非常简单.visit_test方法中执行您需要的操作.最后选择3作为Robot Framework的一部分,如果XML文件的格式发生变化,则不太可能破坏(或更容易修复).
我遇到了与您类似的问题,对我来说,使用Robot Framework的Listener接口是最方便的解决方案。
准备好写入输出文件时,将调用Listener版本3 API中的output_file方法。该方法的参数是输出XML文件的绝对路径,而这是创建任何类型的新报告所必需的。
例:
import os
"""Listener that parses the output XML when it is ready and creates a unique log."""
ROBOT_LISTENER_API_VERSION = 3
def output_file(path):
# parse xml with etree or lxml
log_dir = os.path.split(path)[0]
print('Extra log: %s' % (log_dir + '\\extra.log'))
Run Code Online (Sandbox Code Playgroud)
测试执行的控制台日志:
D:\robot_framework>robot --listener my_listener.py my_test.robot
==============================================================================
My Test
==============================================================================
Some Test | PASS |
------------------------------------------------------------------------------
My Test | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Extra log: D:\robot_framework\extra.log
Output: D:\robot_framework\output.xml
Log: D:\robot_framework\log.html
Report: D:\robot_framework\report.html
Run Code Online (Sandbox Code Playgroud)
默认输出中列出了其他日志文件。