【问题标题】:How to make reports dynamically categorised in robot framework?如何使报表在机器人框架中动态分类?
【发布时间】:2019-09-06 09:58:42
【问题描述】:

我想在每次执行完成时将报告保存在不同的目录中,但它应该在自动化执行本身中动态完成

在命令行执行中指定报告目录路径不是我要寻找的,但它需要手动输入才能将报告放置在特定目录中。

【问题讨论】:

    标签: python python-2.7 robotframework


    【解决方案1】:

    一旦测试开始运行,您就无法更改输出的位置。您唯一的解决方案是使用命令行选项。

    【讨论】:

      【解决方案2】:

      我们可以用来动态生成报告的另一种方法是根据当前时间戳创建输出目录并在那里生成机器人结果。

      例如,在下面的 Maven 机器人框架插件中,“outputDirectory” 标签具有存储机器人结果的位置。该位置带有时间戳,因此机器人的每次运行都会在不同的目录中生成报告。

      <plugin>
          <groupId>org.robotframework</groupId>
          <artifactId>robotframework-maven-plugin</artifactId>
          <version>1.4.7</version>
          <executions>
              <execution>
                  <goals>
                      <goal>run</goal>
                  </goals>
              </execution>
          </executions>
          <configuration>
              <testCasesDirectory>
                  ....
              </testCasesDirectory>
              <variableFiles>
                  <variableFiles>....</variableFiles>
              </variableFiles>
              <outputDirectory>/myloca/reports/${maven.build.timestamp}/</outputDirectory>
              <libdoc/>
              <testdoc/>
          </configuration>
      </plugin>
      

      【讨论】:

      • 好的,我试试看,但是我有一个问题,一旦添加了这个插件,我应该在运行测试时跳过 OutputDirectory 参数吗?
      • 是的,如果您将参数作为命令行调用的一部分提供。我建议删除它。
      【解决方案3】:

      您可以使用脚本通过 Reading argument files from standard input 功能为 Robot Framework 生成命令行参数。

      要根据一些逻辑为报表创建一个文件夹,例如将该文件夹命名为当前时间并将其设置为output directory,可以这样做:

      import datetime
      import os
      
      time = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
      
      dirpath = str(time)
      
      if not os.path.exists(dirpath):
          os.makedirs(dirpath)
      
      print('--outputdir ' + dirpath)
      

      你必须像这样执行你的测试:

      python OutputDirArgumentFile.py | robot --argumentfile STDIN my_test.robot
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-12-18
        • 2018-12-29
        • 1970-01-01
        • 2023-03-18
        • 1970-01-01
        • 2017-09-13
        • 1970-01-01
        相关资源
        最近更新 更多