Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a directory structure for robot framework testing

I want to run tests in Robot Framework.

I would also like the following kind of directory structure for the robot framework tests:

  • Root directory
    • Libraries
      • Library.py
    • Resource Files
      • Resource.txt
    • Tests
      • test_1.txt
      • test_2.txt

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?

like image 880
Little Py Avatar asked Aug 07 '14 10:08

Little Py


2 Answers

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)
like image 129
Ed Brannin Avatar answered Oct 18 '22 20:10

Ed Brannin


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
like image 31
Bryan Oakley Avatar answered Oct 18 '22 19:10

Bryan Oakley