【问题标题】:How to save Robot framework test run logs in some folder with timestamp?如何将机器人框架测试运行日志保存在带有时间戳的文件夹中?
【发布时间】:2016-05-01 15:47:51
【问题描述】:

我正在使用机器人框架来运行 50 个测试用例。每次按预期创建以下三个文件:

c:\users\<user>\appdata\local\output.xml
c:\users\<user>\appdata\local\log.html
c:\users\<user>\appdata\local\report.html

但是当我运行相同的机器人文件时,这些文件将被删除并创建新的日志文件。

我想保留所有以前的运行日志以供将来参考。日志文件应保存在具有时间戳值的文件夹中。

注意:我正在从命令提示符 (pybot test.robot) 运行机器人文件。不是来自 RIDE。

有人可以指导我吗?

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    使用机器人的内置功能

    机器人框架用户指南有一个标题为Timestamping output files 的部分描述了如何执行此操作。

    来自文档:

    本节中列出的所有输出文件都可以使用选项 --timestampoutputs (-T) 自动添加时间戳。使用此选项时,格式为 YYYYMMDD-hhmmss 的时间戳将放置在每个文件的扩展名和基本名称之间。例如,下面的示例将创建诸如 output-20080604-163225.xml 和 mylog-20080604-163225.html 之类的输出文件:

    机器人 --timestampoutputs --log mylog.html --report NONE tests.robot

    要指定一个文件夹,这也记录在用户指南中,在Output Directory 部分的Different Output Files 下:

    ...默认输出目录是开始执行的目录,但可以使用 --outputdir (-d) 选项进行更改。同样,使用此选项设置的路径相对于执行目录,但自然也可以作为绝对路径给出...

    使用帮助脚本

    您可以编写执行两个职责的脚本(在 python、bash、powershell 等中):

    1. 用你想要的所有选项启动 pybot
    2. 重命名输出文件

    然后您只需使用此帮助脚本,而不是直接调用 pybot。

    【讨论】:

      【解决方案2】:

      我无法确定如何在执行结束时创建带时间戳的目录。这是我的脚本,它为文件添加时间戳,但我真的不想要那个,只是每次执行后时间戳目录中的默认文件名?

      CALL "C:\Python27\Scripts\robot.bat" --variable BROWSER:IE --outputdir C:\robot\ --timestampoutputs --name "Robot Execution" Tests\test1.robot
      

      【讨论】:

        【解决方案3】:

        用户可以通过更新位于下面提到的文件夹中的 Settings.py 文件中的键“OutputDir”的值来更新 pycharm IDE 中机器人框架的默认输出文件夹。

        ..ProjectDirectory\venv\Lib\site-packages\robot\conf\settings.py

        cli_opts 字典 中的 'outputdir' 键值更新为 "str(os.getcwd()) + "//Results//Report" + datetime.datetime.now( ).strftime("%d%b%Y_%H%M%S")" 类_BaseSettings(object):

        _cli_opts = {
                     # Update the abspath('.') to the required folder path.  
                     # 'OutputDir'        : ('outputdir', abspath('.')),
                     'OutputDir'        : ('outputdir', str(os.getcwd()) + "//Results//Report_" + datetime.datetime.now().strftime("%d%b%Y_%H%M%S") + "//"),
                     'Report'           : ('report', 'report.html'),
        

        【讨论】:

          【解决方案4】:

          您可以使用时间戳为输出文件创建目录,就像我在 RIDE FAQ 中解释的那样

          这就是你的情况:

          -d ./%date:~-4,4%%date:~-10,2%%date:~-7,2%
          

          【讨论】:

            猜你喜欢
            • 2017-08-06
            • 1970-01-01
            • 1970-01-01
            • 2021-02-10
            • 1970-01-01
            • 2016-05-03
            • 1970-01-01
            • 2012-10-09
            • 1970-01-01
            相关资源
            最近更新 更多