13
votes

In a robot framework, I have a test suite like this:

test-suite/
  ├── Common.robot
  ├── TestCaseA.robot
  └── TestCaseB.robot

The file Common.robot defines some keywords which will used by both TestCaseA.robot and TestCaseB.robot. In other languages Common.robot would be called a library, but trying to import it like this

*** Settings ***
Library         Commons

or like that

*** Settings ***
Library         Commons.robot

results in an error.

[ ERROR ] Error in file '[...]/TestCaseA.robot': Importing test library 'Commons' failed: ImportError: No module named Commons

The keyword Library seems to work only for low level test libraries. I am sure there has to be another way. How can user-defined libraries be included in robot framework?

1

1 Answers

22
votes

If Common.robot is a plain text file or tab separated file having robot framework keywords, it should be imported in the Settings table. In robot framework, files with shared keywords are called resource files.

*** Settings ***
Resource      Common.robot

However, if it is a python file having shared keywords, it should be resourced as a library as

*** Settings ***
Library      Common.py

Note that in both cases the full filename has to be specified.