How to get and set the default output directory in Robot Framework(Ride) in Run time

自闭症网瘾萝莉.ら 提交于 2019-11-30 20:50:40

问题


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

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

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.

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.

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

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


回答1:


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.

Option 1: Use a script to kick off your tests

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.

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)

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

Option 2: Use a listener to do post processing

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.

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




回答2:


You can use the following syntax in RIDE (Arguments:) to create the output in newfolders dynamically

--outputdir C:/AutomationLogs/%date:~-4,4%%date:~-10,2%%date:~-7,2% --timestampoutputs

The above syntax gives you the output in below folder:

Output:  C:\AutomationLogs\20151125\output-20151125-155017.xml
Log:     C:\AutomationLogs\20151125\log-20151125-155017.html
Report:  C:\AutomationLogs\20151125\report-20151125-155017.html

Hope this helps :)




回答3:


At least you can write a custom run script that handles the moving of files after the test case execution. In this case the files are no longer used by pybot.



来源:https://stackoverflow.com/questions/17919279/how-to-get-and-set-the-default-output-directory-in-robot-frameworkride-in-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!