Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify relative path in Robot Framework using Selenium

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.


1 Answers

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

like image 50
B.Balamanigandan Avatar answered Jan 25 '26 08:01

B.Balamanigandan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!