robotframework - 如何使用 Robot Framework 获得每个测试结果一行?

标签 robotframework

我想从 Robot Framework 运行中获取测试用例结果,并将这些结果导入其他工具(ElasticSearch、ALM 工具等)。

为此,我希望能够为每个测试生成一个文本文件。这是一个用竖线分隔的示例:

testcase name | time run | duration | status

我还会添加其他字段,但这些是基本字段。任何帮助表示赞赏。我一直在看 robot.result http://robot-framework.readthedocs.io/en/3.0.2/autodoc/robot.result.html但还没有弄清楚。如果/当我这样做时,我会在这里发布答案。

谢谢,

最佳答案

output.xml 文件很容易用普通的 XML 解析库解析。

这是一个简单的例子:

from __future__ import print_function
import xml.etree.ElementTree as ET
from datetime import datetime

def get_robot_results(filepath):

    results = []
    with open(filepath, "r") as f:
        xml = ET.parse(f)
        root = xml.getroot()
        if root.tag != "robot":
            raise Exception("expect root tag 'robot', got '%s'" % root.tag)

    for suite_node in root.findall("suite"):
        for test_node in suite_node.findall("test"):
            status_node = test_node.find("status")

            name = test_node.attrib["name"]
            status = status_node.attrib["status"]
            start = status_node.attrib["starttime"]
            end = status_node.attrib["endtime"]
            start_time = datetime.strptime(start, '%Y%m%d %H:%M:%S.%f')
            end_time = datetime.strptime(end, '%Y%m%d %H:%M:%S.%f')
            elapsed = str(end_time-start_time)

            results.append([name, start, elapsed, status])

    return results


if __name__ == "__main__":
    results = get_robot_results("output.xml")
    for row in results:
        print(" | ".join(row))

关于robotframework - 如何使用 Robot Framework 获得每个测试结果一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44207886/

相关文章:

selenium - XPATH - 为什么在 text() 函数中使用括号

python - 如何使用机器人框架,selenium 打开新窗口?

python - 无法像 Javascript 一样使用 RobotFramework 执行 Python .py 文件

testing - 如何在 Web GUI 测试自动化中模拟 20 个用户同时单击一个按钮

python - 在robot framework中申请loop后,报错如下- Keyword name cannot be empty

html - 有没有办法使用 Vue 路由器路由到 html 文件?

selenium - 使用Robot框架的未处理错误 “Cannot find context with specified id”

python - 如何在机器人框架库文件中进行多重继承?

python - 在版本 56.0.2924.87 中,Selenium 在 Chrome 中设置窗口大小失败

robotframework - 我们如何为机器人框架中的 if 循环定义一组指令而不是一条指令?