I want to run tests in Robot Framework.
I would also like the following kind of directory structure for the robot framework tests:
Or something along those lines. However, I do not know how to write my tests so they can access my library and resource files. For example, how to import Libraries\Library.py from Tests\test_1.txt.
What would be the best way to approach this?
Is there a syntax for acessing files in the parent directory?
Should I import the resource and library files in every test file, or is there a way to do it only once?
Robot automatically defines an ${EXECDIR}
variable that we're using in place of ${ROOT}
from Bryan's answer.
Pros:
Cons:
Robot supports relative imports. You can use ..
to represent the parent of a directory. In your example you would do it this way:
*** Settings ***
| Resource | ../Resource Files/Resource.txt
| Library | ../Libraries/Library.py
You can use variables in your settings table, so you could define a variable that points to the root of your repository. You would use this variable for all of your imports. For example:
*** Settings ***
| Resource | ${ROOT}/Resource Files/Resource.txt
| Library | ${ROOT}/Libraries/Library.py
You can set this variable on the command line with the --variable
option:
$ pybot --variable ROOT /path/to/root tests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With