如何将机器人框架测试 运行 日志保存在带有时间戳的文件夹中?
How to save Robot framework test run logs in some folder with timestamp?
我正在使用 Robot Framework,运行 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) 运行ning 机器人文件。不是来自 RIDE。
有人可以指导我吗?
使用机器人的built-in功能
机器人框架用户指南中有一个标题为 Timestamping output files 的部分描述了如何执行此操作。
来自文档:
All output files listed in this section can be automatically timestamped with the option --timestampoutputs (-T). When this option is used, a timestamp in the format YYYYMMDD-hhmmss is placed between the extension and the base name of each file. The example below would, for example, create such output files as output-20080604-163225.xml and mylog-20080604-163225.html:
robot --timestampoutputs --log mylog.html --report NONE tests.robot
要指定文件夹,这也记录在用户指南的 Output Directory, under Different Output Files:
部分
...The default output directory is the directory where the execution is started from, but it can be altered with the --outputdir (-d) option. The path set with this option is, again, relative to the execution directory, but can naturally be given also as an absolute path...
使用帮助脚本
您可以编写执行两个任务的脚本(在 python、bash、powershell 等中):
- 使用您想要的所有选项启动 pybot
- 重命名输出文件
然后您只需使用这个帮助脚本,而不是直接调用 pybot。
我无法弄清楚如何在执行结束时创建带时间戳的目录。这是我的脚本,它为文件加上时间戳,但我真的不想要那个,只是每次执行后带时间戳的目录中的默认文件名?
CALL "C:\Python27\Scripts\robot.bat" --variable BROWSER:IE --outputdir C:\robot\ --timestampoutputs --name "Robot Execution" Tests\test1.robot
用户可以更新 pycharm IDE 中机器人框架的默认输出文件夹,方法是更新文件夹中存在的 Settings.py 文件中的键“OutputDir”的值下面提到。
..ProjectDirectory\venv\Lib\site-packages\robot\conf\settings.py
将cli_opts字典中的'outputdir'键值更新为"str(os.getcwd())+"//结果/ /Report " + datetime.datetime.now().strftime("%d%b%Y_%H%M%S")" of class _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'),
您可以使用时间戳为输出文件创建目录,就像我在 RIDE FAQ
中解释的那样
你的情况是这样的:
-d ./%date:~-4,4%%date:~-10,2%%date:~-7,2%
我正在使用 Robot Framework,运行 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) 运行ning 机器人文件。不是来自 RIDE。
有人可以指导我吗?
使用机器人的built-in功能
机器人框架用户指南中有一个标题为 Timestamping output files 的部分描述了如何执行此操作。
来自文档:
All output files listed in this section can be automatically timestamped with the option --timestampoutputs (-T). When this option is used, a timestamp in the format YYYYMMDD-hhmmss is placed between the extension and the base name of each file. The example below would, for example, create such output files as output-20080604-163225.xml and mylog-20080604-163225.html:
robot --timestampoutputs --log mylog.html --report NONE tests.robot
要指定文件夹,这也记录在用户指南的 Output Directory, under Different Output Files:
部分...The default output directory is the directory where the execution is started from, but it can be altered with the --outputdir (-d) option. The path set with this option is, again, relative to the execution directory, but can naturally be given also as an absolute path...
使用帮助脚本
您可以编写执行两个任务的脚本(在 python、bash、powershell 等中):
- 使用您想要的所有选项启动 pybot
- 重命名输出文件
然后您只需使用这个帮助脚本,而不是直接调用 pybot。
我无法弄清楚如何在执行结束时创建带时间戳的目录。这是我的脚本,它为文件加上时间戳,但我真的不想要那个,只是每次执行后带时间戳的目录中的默认文件名?
CALL "C:\Python27\Scripts\robot.bat" --variable BROWSER:IE --outputdir C:\robot\ --timestampoutputs --name "Robot Execution" Tests\test1.robot
用户可以更新 pycharm IDE 中机器人框架的默认输出文件夹,方法是更新文件夹中存在的 Settings.py 文件中的键“OutputDir”的值下面提到。
..ProjectDirectory\venv\Lib\site-packages\robot\conf\settings.py
将cli_opts字典
_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'),
您可以使用时间戳为输出文件创建目录,就像我在 RIDE FAQ
中解释的那样你的情况是这样的:
-d ./%date:~-4,4%%date:~-10,2%%date:~-7,2%