Importing Variables and Resource files

Hi,

To import Variables and Resources we are using relative path to the location where Variables and Resources are present.
I am using .py files to keep variables and .robot files to maintain resources

And using relative paths like.-> …/…/Resources/TestDataFiles/LoginPage.robot

It’s difficult to maintain the relative path if we have to import huge number of Variables and Resources file. In some cases we may have to import 50 or more than 100 files. So have to write 100 lines of import using relative path.
Now if there is a change in location of the file then I will have to update the location in all the places where I am using the relative path to the file.

Is there any better approach for this?
Instead of writing the relative path and moving backward or forward direction can we use the project root path and then move from there.
Not sure how we can get project root path using robot framework.

Any suggestions or possible solutions?

Thanks

Don’t you use the builtin variable ${CURDIR} ?

${CURDIR} isn’t helping me in this case. It’s giving the path to the directory where i am using it.
But the Variables and resource files which i am trying to access are not present inside the current directory. They are present outside of the current directory.

Again i have to use the relative references to get those resources.

1 Like

So try to use a variable for common paths.

Hi Subha,

How about in the resources folder you create a main.robot that you import in all your robot tests, this main.robot file then has all the imports for the other resoiurce files that your tests need, then if a resource file is moved you update just main.robot and all your test cases can stay the same.

I gave an example of this approach here:

Dave.

1 Like

Thanks @HelioGuilherme66 & @damies13 for your suggestions.
Both the solutions are helpful and resolving the issue to a large extent.

Also wanted to know is there any way to get project root path in robot ?

Hi Subha,

What do you mean by “project root path”? If you refer to Built-in variables you’ll find

  • ${CURDIR} - The directory where the robot file is
  • ${EXECDIR} - The directory where you executed the robot command from
    These may or may not have the same value consider the following example command
c:\users\Subha>robot p:\my_project\tests\regression\my_test_suite\functional_area_a\test_cases\my_test.robot

In this case

  • ${CURDIR} would be p:\my_project\tests\regression\my_test_suite\functional_area_a\test_cases
  • ${EXECDIR} would be c:\users\Subha

But perhaps you would refer to p:\my_project\tests\regression\my_test_suite as the “project root path”? If that’s the case no there’s no built in variable for that but you could easily determine what it is with Normalize Path. Something like this should give you what you need:

${projectroot}= 	Normalize Path 	${CURDIR}${/}..${/}..

Dave.

2 Likes

Thanks! This is helpful.

1 Like