Using the directory structure to test the robot platform
I want to run tests in Robot Framework.
I also need the following directory structure for the robot based tests:
- Root directory
- Libraries
- Library.py
- Resource files
- Resource.txt
- Tests
- test_1.txt
- test_2.txt
- Libraries
Or something like that. However, I don't know how to write my tests so that they can access my libraries 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 accessing files in the parent directory?
Do I have to import resource and library files into each test file or is there a way to do this only once?
source to share
Using relative imports
The robot supports relative imports. You can use ..
to represent the parent of a directory. In your example, you would do like this:
*** Settings ***
| Resource | ../Resource Files/Resource.txt
| Library | ../Libraries/Library.py
Defining a root in a variable
You can use variables in your settings table so you can define a variable pointing to the root of your repository. You will use this variable for all your imported products. 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 option --variable
:
$ pybot --variable ROOT /path/to/root tests
source to share