How to spceify relative path in Robot Framework using Selenium

偶尔善良 提交于 2020-02-24 17:00:37

问题


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:


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




回答2:


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.



来源:https://stackoverflow.com/questions/44717988/how-to-spceify-relative-path-in-robot-framework-using-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!