使用API时使log.html更详细

2024-10-05 17:44:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用API来构建和运行测试套件,我注意到使用API和shell时输出的log.html有细微的不同

The log when using the command line invocation

使用命令行调用时的日志

The log when run through a minimal python script

通过最小python脚本运行时的日志

最小python脚本:

import robot.api
import robot.result
from robot.conf.settings import RobotSettings

options = {
    "output": "./results.xml",
    "log": "./log.html",
    "report": "./report.html",
    "loglevel": "TRACE"
}

settings = RobotSettings(options)

suite = robot.api.TestSuiteBuilder().build(".")
result = suite.run(settings=settings)

result_writer = robot.api.ResultWriter(result)
result_writer.write_results(settings=settings.get_rebot_settings())

正如可以看到的日志丢失了很多关键字细节,我如何才能找回这些

编辑:更改为正确方法后的最小文件:

import robot.api
import robot.result
from robot.conf.settings import RobotSettings

options = {
    "output": "./results.xml",
    "log": "./log.html",
    "report": "./report.html",
    "loglevel": "TRACE",
    "rpa": False
}

settings = RobotSettings(options)

suite = robot.api.TestSuiteBuilder().build(".")
result = suite.run(settings=settings)

result_writer = robot.api.ResultWriter("./results.xml")
result_writer.write_results(settings=settings.get_rebot_settings())

Tags: importreportlogapisettingshtmlrobotxml
1条回答
网友
1楼 · 发布于 2024-10-05 17:44:20

您确定您的系统上没有两个不同的Robot Framework程序包处于活动状态吗?一个在路径外部,另一个作为包在venv中。 试一试

robot  version

并检查cmd行中的版本是否与运行脚本的版本相同。 您还应该尝试升级到最新版本,这通常可以解决此类错误

我还发现了一个类似的错误on this thread,它表示

The problem is that the result object you get from suite.run(settings) doesn't contain all information about test execution. The reason for this behavior is saving memory during test execution. All information about the execution is in the generated output.xml file, and what you need to do is passing a path to it to the ResultWriter class instead of the result object. This ought to be documented somewhere in the API docs but I'm not sure about it.

相关问题 更多 >