Robot Cannot Find exe File - robotframework

I have a test that calls to executable file. that exec file gets a string and return another string.
for example:
cmd = "./myExecFile inputString"
out = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
when I ran it as python code it works well. the executable file run as expected and I get the right output string.
but when I ran it via robot test, for some reason I get the error message (the 'out' variable):
./myExecFile not found
that exec file located under the same folder where that robot file located:
|TestFolder
|----> myExecFile
|----> test.robot
I tried to add the path to robot by:
evaluate sys.path.append(os.path.join("path", "to", "library")) modules=os, sys
I printed the sys.path and verified that the path was added
but robot still cannot find ./myExecFile
what am I missing here?
Thanks.

Try to use the absolute path
Or always execute the script from the same path (with cd nd robot in Terminal) and go from the path you execute from

Related

PyInstaller: FileNotFoundError when trying to run the distribution file

I'm helping out a friend who needs to transform some data in csvs, so I made a little python program called "csv_converter.py"- it takes a csv input file and csv output file and everything's peachy.
I want to be able to give them a file they can run on their machine (without necessarily needing python and pandas) so I'm trying PyInstaller.
In the directory with my python program I run: pyinstaller csv_converter.py
According to the docs, it'll make a 'dist' folder where "you find the bundled app you distribute to your users." It sounds like the key file to run will be: dist/csv_converter/csv_converter (clarification source: here), and then I can either send the whole csv_converter folder, or just the csv_converter file if I run the Pyinstaller command with the --onefile argument.
After running PyInstaller I see these directories created, but when I navigate to dist/csv_converter/ and try to run that important csv_converter file (before trying to send anything), it's giving the following error:
Dianes-MacBook-Pro:csv_converter dkaplan$ ./csv_converter -h
Traceback (most recent call last):
File "site-packages/PyInstaller/loader/rthooks/pyi_rth__tkinter.py", line 30, in <module>
FileNotFoundError: Tcl data directory "/Users/dkaplan/PycharmProjects/chris_csv_converter/src/dist/csv_converter/tcl" not found.
[36637] Failed to execute script pyi_rth__tkinter
So close, but so far! Has anyone else had this issue or know a workaround?
I heard back from the kind folks at PyInstaller, and this is a common one they see with tinter. I'm not sure where it was being pulled in from, but the workaround was to exclude it with this argument: --exclude-module=tkinter
I had chosen to use the --onefile argument (slower, but means I can send just one file), so the full command was: pyinstaller --onefile --exclude-module=tkinter csv_converter.py
Then:
I could go to the dist folder and do a test run with: ./csv_converter -h
then I send that csv_converter file to my friend and he'll be able to run it the same way (without needing python)

Does Robot Framework automatically import current directory where your robot test is located?

Does Robot automatically import directories(current and sub directory) where you run your robot file? If yes, is there a way to avoid that?
e.g. mytest.robot current dir is /home/test/mytest.robot, after running mytest.robot, PYTHONPATH includes /home/test/
Does Robot automatically import directories(current and sub directory) where you run your robot file?
No, the only thing it automatically imports are the built-in keywords. Robot will not set PYTHONPATH unless you tell it to.
As explained in the documentation below,
The BuiltIn library is special because it is taken into use
automatically and thus its keywords are always available.
Although, RF documentation does not mention anything on loading directories automatically, according to robot run documentation, and the actual test robot code, they are testing with and without pythonpath argument.
robot would start the execution of the test file by loading the file and keeping the loaded file path in PYTHONPATH (even for this to happen, they are making use of --PYTHONPATH), that is the reason you are seeing dir.
excerpt code from robot framework code repo mentioned below,
${RUNNER DEFAULTS}
... ${COMMON DEFAULTS}
... --ConsoleMarkers OFF
... --PYTHONPATH "${CURDIR}${/}..${/}testresources${/}testlibs"
... --PYTHONPATH "${CURDIR}${/}..${/}testresources${/}listeners"
*** Keywords ***
Run Tests
[Arguments] ${options}= ${sources}= ${default options}=${RUNNER DEFAULTS} ${output}=${OUTFILE}
[Documentation] *OUTDIR:* file://${OUTDIR} (regenerated for every run)
${result} = Execute ${INTERPRETER.runner} ${options} ${sources} ${default options}
Log Many RC: ${result.rc} STDERR:\n${result.stderr} STDOUT:\n${result.stdout}
Process Output ${output}
[Return] ${result}
Does Robot automatically import directories(current and sub directory)
where you run your robot file? If yes, is there a way to avoid that?
Even according to the code, the answer is "no". as far as changing this behavior, you can always make use of --pythonpath option.

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

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'),

How "make" command locates makefile

I am trying to understand the working of "make" command (just started on this command). I have an ".sh" file which has a script to execute "make" command as shown below:
source /somepath/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
make arch=arm toolchainPrefix=arm-poky-linux-gnueabi- xeno=off mode=Debug all
The directory where the script file is located has a file named "makefile". but there is nothing specified in the script file above regarding this "makefile". After executing the script file, all the script withing "makefile" is executed automatically. Can someone explain the working of "make xyz all" command in few words.
Thanks
As often with UNIX systems the command works to some degree by conventions. make (the GNU version of make at least) will search the working directory for files called GNUmakefile, makefile, and Makefile in that order or you can use the -f (or --file) option to give it a specific file.

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.

Resources