How to specify relative path in Robot Framework using Selenium - robotframework

I'm having a text file in Resource folder and my robot script in sibling folder namely Test, I need to use the relative path otherwise I need to specify the path explicitly once I changed the project location.
TEST PROJECT (Root folder)
|
|_____ Resource (folder)
| |_____ MyProfile.txt
| |_____ MyPicture.jpg
|
|_____ Test (folder)
|_____ MyTest.robot
I want to access the MyProfile.txt in MyTest.robot using relative reference instead of absolute path.
Kindly assist me.

We can give the Relative path by using the following approach
${CURDIR}${/}..\\Resource\\MyProfile.txt
The ${CURDIR} will return the path of where you are using this code, then we need to back track using the navigation operator ..\\
But if you use ${EXECDIR} will return the path of the file is executing.
${EXECDIR}${/}..\\Resource\\MyProfile.txt
Here the code and execution both are handled in a single file, so both the code will give you the appropriate location of MyProfile.txt

or another way, you may add the project root folder to the sys.path. it will search up the referenced resources from the root folder.

Related

Robot Framework how to set file path?

I am using Choose File keyword to upload file. In documentation is written that I can use ${CURDIR} to set the path to my file, but it means that this file has to be in the same directory ${CURDIR}/filename.txt. But how to set the path to the file that exists in another directory?
Use ${EXECDIR} so you go back to the root and go from there.

Grunt: what is the purpose of cwd?

I know cwd stands for "current working directory", but what I don't understand is why is has to be included in the gruntfile.js.
Won't the script run always in the current working directory? Why would you need to change or specify another one?
grunt.js resides in the root of our project.
cwd is the path where grunt looks for the files matching the pattern in src and performs operations on. It can be an img folder in the current project root or a script folder in the current project root.
In other words, cwd is the parent folder of src files. It might not be the root folder of the root of the current project but a child of it.
Hope this helps answer your question.

Creating a terminal command in Minix

I want to create a command that runs an executable created by compiling a c program. I couldn't find a proper solution. Let's say I have a file named myprogram.c and compile it and have myprogram as . I want to type myprogram in any folder in my system and run it. How can I achieve this?
First find out what your PATH is
echo $PATH
For you this outputs
/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin/usr/X11R7/bin:usr/X11R‌​‌​6/bin:/usr/local/sbin:/usr/local/bin
Then assuming your program is in the /usr/myprog directory, append /usr/myprog to your PATH (don't forget to separate directories with a colon :)
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin/usr/X11R7/bin:usr/X11R‌​‌​6/bin:/usr/local/sbin:/usr/local/bin:/usr/myprog
Doing this tells the system when you don't specify an absolute path (like ./myprogram) to look in all the directories in PATH. It is good to add the absolute path of your executable to PATH because adding . to your PATH is frowned upon by some (see this question).
You have to add it in your PATH from your shell rc file
You place the executable into a directory that your shell already searches for programs, or you add your program's location to that list.
the $PATH environment variable contains this information. You can add myProgram's location to it, i.e. export PATH=$PATH:/new/dir, or just print out $PATH and copy myProgram into one of the paths listed there already.

X509Certificate.Import file from folder on disk

Is it possible to import a certificate file using a (relative) path? I am trying to follow the example here:
http://msdn.microsoft.com/en-us/library/te7383x5.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
cert.Import( relative path )
I am not having any success. Keep running into "file not found" exception.
Is a fully-qualified path required?
Win32 documentation discourages use of relative paths so use of the absolute path is strongly recommended.

How do I create a directory from hook_install of a module in Drupal 7?

Actually, I know how to create a directory = mkdir.
However, I need to pass it a full absolute path in the server, and I don't know how to get the relevant path in hook_install.
I tried using base_path(), but it returned '/'.
The path I want is sites/default/files (inside "files" I create the directory).
Thanks.
Please use the proper APIs.
$directory = file_default_scheme() . '://yourdir';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
Did you try mkdir('sites/default/files/yourdir')? If so, where does that create the directory? If not, why not?
Relative directory names are resolved based on the working directory. The working directory in Drupal is usually the directory in which your install.php and index.php is located.

Resources