Using a directory structure for robot framework testing

Using relative imports

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

Defining the root in a variable

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

Robot automatically defines an ${EXECDIR} variable that we're using in place of ${ROOT} from Bryan's answer.

Pros:

  • System-independent

Cons:

  • May depend on how you invoke PyBot (working dir in command prompt, or which folder you open in RIDE)