如何在运行时获取和设置 Robot Framework(Ride) 中的默认输出目录 [英] How to get and set the default output directory in Robot Framework(Ride) in Run time

查看:214
本文介绍了如何在运行时获取和设置 Robot Framework(Ride) 中的默认输出目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我所有的输出文件移动到一个自定义位置,移动到运行时基于日期时间创建的运行目录.在TestSetup中按日期时间创建输出文件夹

I would like to move all my output files to a custom location, to a Run directory created based on Date time during Run time. The output folder by datetime is created in the TestSetup

我有函数Process_Output_files",它将文件移动到运行文件夹(Run1、Run2、Run3 文件夹).

I have function "Process_Output_files" which will move the files to the Run folder(Run1,Run2,Run3 Folders).

我尝试使用参数-d 并使用函数Process_Output_files"作为套件拆卸以将输出文件移动到相应的运行目录.

I have tried using the argument-d and used the function "Process_Output_files" as suite tear down to move the output files to the respective Run directory.

但我收到以下错误进程无法访问该文件,因为它正被另一个进程使用".我知道这是因为 Robot Framework (Ride) 目前正在使用它.

But I get the following error "The process cannot access the file because it is being used by another process". I know this is because the Robot Framework (Ride) is currently using this.

如果我不使用 -d 参数,输出文件将保存在临时文件夹中.

If I dont use the -d argument, the output files are getting saved in temp folders.

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

我的问题是,有没有办法在运行时使用 Robot Framework 将文件移动到自定义位置.

My question is, Is there a way to get move the files to custom location during run time with in Robot Framework.

推荐答案

我知道您想要的最终结果是将您的输出文件放在他们的自定义文件夹中.如果这是您的愿望,它可以在运行时完成,您不必在后期处理中移动它们.不幸的是,这在 RIDE 中不起作用,因为文件夹结构是动态创建的.我有两个选择.

I understand the end result you want is to have your output files in their custom folders. If this is your desire, it can be accomplished at runtime and you won't have to move them as part of your post processing. This will not work in RIDE, unfortunately, since the folder structure is created dynamically. I have two options for you.

RIDE 很棒,但在我看来,不应使用它来运行测试,而应使用它来构建和调试测试.脚本更加强大和灵活.

RIDE is awesome, but in my humble opinion, one shouldn't be using it to run ones tests, only to build and debug ones tests. Scripts are far more powerful and flexible.

假设你有一个测试,test2.txt,你想运行,你用来做这个的脚本可能是这样的:

Assuming you have a test, test2.txt, you wish to run, the script you use to do this could be something like:

from time import gmtime, strftime
import os

#strftime returns string representations of a date-time tuple.
#gmtime returns the date-time tuple representing greenwich mean time 
dts=strftime("%Y.%m.%d.%H.%M.%S", gmtime())


cmd="pybot -d Run%s test2"%(dts,)
os.system(cmd)

顺便说一句,如果您确实打算使用 rebot 对文件进行后期处理,请注意您可能不需要创建中间日志和报告文件.output.xml 文件包含您需要的所有内容,因此如果您不想创建多余的文件,请使用 --log NONE --report NONE

As an aside, if you do intend to do post processing of your files using rebot, be aware you may not need to create intermediate log and report files. The output.xml files contain everything you need, so if you don't want to create superfluous files, use --log NONE --report NONE

侦听器是您编写的响应事件(x_start、x_end 等)的程序.close() 事件类似于拆卸函数,是最后调用的东西.因此,假设您有一个函数 moveFiles(),您只需创建一个侦听器类 (myListener),定义 close() 方法来调用您的 moveFiles() 函数,并提醒您的测试它应该向带有参数 --listener myListener 的侦听器报告.

A listener is a program you write that responds to events (x_start, x_end, etc). The close() event is akin to the teardown function and is the last thing called. So, assuming you have a function moveFiles() you simply need to create a listener class (myListener), define the close() method to call your moveFiles() function, and alert your test that it should report to a listener with the argument --listener myListener.

这个选项应该与 RIDE 兼容,尽管我承认我从未尝试在 IDE 中使用侦听器.

This option should be compatible with RIDE though I admit I have never tried to use listeners with the IDE.

这篇关于如何在运行时获取和设置 Robot Framework(Ride) 中的默认输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆