Search code examples
robotframework

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.


Solution

  • 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