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

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?

+3


source to share


2 answers


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

      

+4


source


The robot automatically detects the variable ${EXECDIR}

that we use instead of ${ROOT}

from Brian's answer.

Pros:

  • The system of independent


Minuses:

  • May depend on how you invoke PyBot (working directory on the command line or which folder you open in RIDE)
+5


source







All Articles