How to save Robot framework test run logs in some folder with timestamp? - robotframework

I am using Robot Framework, to run 50 Testcases. Everytime its creating following three files as expected:
c:\users\<user>\appdata\local\output.xml
c:\users\<user>\appdata\local\log.html
c:\users\<user>\appdata\local\report.html
But when I run same robot file, these files will be removed and New log files will be created.
I want to keep all previous run logs to refer in future. Log files should be saved in a folder with a time-stamp value in that.
NOTE: I am running robot file from command prompt (pybot test.robot). NOT from RIDE.
Could any one guide me on this?

Using the built-in features of robot
The robot framework user guide has a section titled Timestamping output files which describes how to do this.
From the documentation:
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
To specify a folder, this too is documented in the user guide, in the section 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...
Using a helper script
You can write a script (in python, bash, powershell, etc) that performs two duties:
launches pybot with all the options you wan
renames the output files
You then just use this helper script instead of calling pybot directly.

I'm having trouble working out how to create a timestamped directory at the end of the execution. This is my script it timestamps the files, but I don't really want that, just the default file names inside a timestamped directory after each execution?
CALL "C:\Python27\Scripts\robot.bat" --variable BROWSER:IE --outputdir C:\robot\ --timestampoutputs --name "Robot Execution" Tests\test1.robot

You may use the directory creation for output files using the timestamp, like I explain in RIDE FAQ
This would be in your case:
-d ./%date:~-4,4%%date:~-10,2%%date:~-7,2%

User can update the default output folder of the robot framework in the pycharm IDE by updating the value for the key "OutputDir" in the Settings.py file present in the folder mentioned below.
..ProjectDirectory\venv\Lib\site-packages\robot\conf\settings.py
Update the 'outputdir' key value in the cli_opts dictionary to "str(os.getcwd()) + "//Results//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'),

Related

How can we apply static analysis tool for robot framework rflint to all of the repository?

I'm using the rflint static analysis tool in order to improve the quality of my robot scripts and review its code for UI testing.
I use current code to get an output in cmd related to a specific file:
rflint myTestSuite.robot
How can I apply it to the folder that contains all of my robot tests in just one click to get the result?
If you ask rflint to print out its online help with rflint --help, you'll see there is a command line option named --recursive (and the short version -r) which causes rflint to recursively process directories. Also, the very last paragraph in the help is this:
If you give a directory as an argument, all files in the directory
with the suffix .txt, .robot or .tsv will be processed. With the
--recursive option, subfolders within the directory will also be
processed.

IAR project variable like $PROJ_DIR$

Is there any possibility in IAR to add additional project variable like $PROJ_DIR$ to specify my project environment?
I like to keep my project portable and adaptable.
Of course there are, according to the manuals:
Variable / Description
$CONFIG_NAME$ The name of the current build configuration, for example Debug or Release.
$CUR_DIR$ Current directory
$CUR_LINE$ Current line
$DATE$ Today’s date
$EW_DIR$ Top directory of IAR Embedded Workbench, for example c:\program files\iar systems\embedded workbench 6.n
$EXE_DIR$ Directory for executable output
$FILE_BNAME$ Filename without extension
$FILE_BPATH$ Full path without extension
$FILE_DIR$ Directory of active file, no filename
$FILE_FNAME$ Filename of active file without path
$FILE_PATH$ Full path of active file (in Editor, Project, or Message window)
$LIST_DIR$ Directory for list output
$OBJ_DIR$ Directory for object output
$PROJ_DIR$ Project directory
$PROJ_FNAME$ Project filename without path
$PROJ_PATH$ Full path of project file
$TARGET_DIR$ Directory of primary output file
$TARGET_BNAME$ Filename without path of primary output file and without extension
$TARGET_BPATH$ Full path of primary output file without extension
$TARGET_FNAME$ Filename without path of primary output file
$TARGET_PATH$ Full path of primary output file
$TOOLKIT_DIR$ Directory of the active product, for example c:\program files\iar systems\embedded workbench 6.n\arm
$USER_NAME$ Your host login name
$ENVVAR$ The environment variable ENVVAR. Any name within $_ and _$ will
be expanded to that system environment variable.
If you go to Tools > Configure Custom Argument Variables you can add variables that you can address with $VARIABLE_NAME$. Not sure if that's exactly what you were looking for.
As a caution, if you are using IarBuild.exe to build from the command line, the workspace or global values set from "Configure Custom Arguments Variables" are not included in the project files (.ewp) and thus is not expanded by IarBuild.exe at build time. This is not an issue if you only use the IDE to build.
I found a reason for my problem (but it givs another one):
I define a windows "path-variable" like LIB_PATH and put it in the IAR project file with $_LIB_PATH_$.This works as long until i save the IAR-project. Then IAR sets all paths realive to $PROJ_DIR$ :-(

How to get log file name and log directory in robot framework

How to get the robot generated log file name and log directory.
I want to write a post process script, which can process the output XML file generated by robot.
${LOG FILE}
Gives you absolute path to the log file.
${SUITE SOURCE}
Gives you absolute path to the suite file.
${OUTPUT DIR}
Gives you absolute path to the output directory.
http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.4#automatic-variables
The easiest thing is to tell robot where you want the file to be, then you don't have to figure it out. Use the output directory command line option --outputdir. Unless you tell it where to put the output files, they will go into the current working directory.
If neither one of those works, you can capture the output of robot, and the last three lines will tell you the location of the output.xml, log.html and report.html files.

How do I create a directory with a file in it, in one step?

In the terminal, is there a way to create a directory with a file in it in one step?
Currently I do this in 2 steps:
1. mkdir foo
2. touch foo/bar.txt
Apparently, touch foo/bar.txt doesn't work.
With only standard unix tools, the most direct way to create a directory and a file in this directory is
mkdir foo && touch foo/bar.txt
Unix is built around the philosophy of simple, single-purpose tools with the shell as a glue to combine them. So to create a directory and a file, you instruct a shell to run the directory creation utility then the file creation utility.
I won't swear that there isn't some bizarre way of using a standard tool that lets you do it with a single command. (In fact, there is: unpack an archive — except that you'll need to provide that archive as a file, with predefined owner, date and other metadata, or else use another command to build an archive.) But whatever it is would be convoluted.

PHPUnit testing individually in Symfony

I would like to run some unit Tests individually with PHPUnit, but I have certain classes separated from the Tests, since I am using the symfony framework, and I group the Tests and the Classes in different folders.
I would like to run the Tests individually like this:
php phpunit.phar MyTest.php
The problem is that the test file uses the classes from the controllers, and phpunit doesnt seem to be able to import the needed classes for the test.
This is not a problem to run all the tests together, thanks to phpunit.xml but when I want to run them individualy, its a problem.
How could I fix this?
You have to point phpunit where you have your phpunit.xml config file (because it must know the autoloader for example). If you have default symfony 2 structure it will be in app directory, so just run your test like that (I assume that you are in project root path):
phpunit -c app/ --filter="concreteTestPattern" src/Acme/DemoBundle/Tests/MyTest.php
edit:
Above will run all tests which names match to the pattern: /.*concreteTestPattern.*/
You would use the --filter argument in your PHPUnit command string. This will only run tests that match the pattern given. If you pass only the complete name of the test that you want run, phpunit should only run that test.
If you have a data provider associated with the test and only want to run one test case, you can also filter that by using --filter <testName>::<testcase name>
PHPUnit can be set to execute using a configuration file.
In our Symfony2 project this file is located at app/phpunit.xml.dist.
As this file is suffixed with .dist, you need to copy its contents into a file called app/phpunit.xml.
If you are using a VCS such as Git, you should add the new app/phpunit.xml file to the VCS ignore list.
You will also notice the configuration is specifying the bootstrap file located at app/bootstrap.php.cache. This file is used by PHPUnit to get the testing environment setup.
We can execute this test by running the following command from the root directory of the project. The -c option specifies that PHPUnit should load its configuration from the app directory.
$ phpunit -c app

Resources