简体   繁体   English

如何使报告在机器人框架中动态分类?

[英]How to make reports dynamically categorised in robot framework?

I want to keep reports in different directory every time the execution is done, but it should be done dynamically in automation execution itself我想在每次执行完成时将报告保存在不同的目录中,但它应该在自动化执行本身中动态完成

specifying the reports directory path in command line execution is not the one I am looking for, that is there but it needs manual input to place the reports in particular directory.在命令行执行中指定报告目录路径不是我要找的那个,但它需要手动输入才能将报告放在特定目录中。

Once the test starts running you cannot change the location of the outputs.一旦测试开始运行,您就无法更改输出的位置。 Your only solution is to use a command line option.您唯一的解决方案是使用命令行选项。

The other alternative which we can use to dynamically generate reports, is to create output directory based on current timestamp and generate Robot results there.我们可以用来动态生成报告的另一种方法是根据当前时间戳创建输出目录并在那里生成机器人结果。

For example, in the below Maven robotframework plugin, the "outputDirectory" tag has location where Robot results will be stored.例如,在下面的 Maven robotframework 插件中, “outputDirectory”标签具有存储 Robot 结果的位置。 This location is timestamped due to which every run of robot will generate report in different directory.该位置带有时间戳,因此机器人的每次运行都会在不同的目录中生成报告。

<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>

You can use a script to generate command line arguments for Robot Framework using the Reading argument files from standard input functionality.您可以使用脚本从标准输入功能中读取参数文件,为 Robot Framework 生成命令行参数。

To create a folder for the reports based on some logic, for example to name the folder as the current time and set that as the output directory , something like this can be done:要根据某些逻辑为报告创建一个文件夹,例如将文件夹命名为当前时间并将其设置为输出目录,可以这样做:

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)

You have to execute your tests like:您必须像这样执行测试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM