Reputation: 43
I started a project in Robot Framework and I have some issues with my custom libraries from python.
I have such structure:
My problem now is that my Keywords (the ones inside Keywords directory) has dependencies on files from GeneralCommands directory and also from HelperClass.py and HelperClass2.py. If I run the code in Python, everything is fine. But when I call one of the keywords in Robot Framework with:
Library ../../Common/Keywords/TestKeyword.py
it complains that it cannot find the dependencies:
[ ERROR ] Error in file 'C:\(...)\test.robot': Importing test library 'C:\(...)\Common\Keywords\TestKeyword.py' failed: ModuleNotFoundError: No module named 'GeneralCommand1'
Traceback (most recent call last):
File "C:\(...)\Common\Keywords\TestKeyword.py", line 5, in <module>
from GeneralCommand1 import *
The only way I found to solve this was to add literally every single dependency inside the .robot file, like:
Library ../../Common/HelperClass.py
Library ../../Common/HelperClass2.py
Library ../../Common/LmCommands/GeneralCommand1.py
Library ../../Common/Keywords/TestKeyword.py
However this approach will become complicated to deal with when I will extend the custom libraries, in the end I will have dozens of import library lines. I know there is such thing as the --pythonpath, but I want to avoid using it because this project will be in different machines and paths will not always be the same.
Any suggestions?
Upvotes: 1
Views: 1913
Reputation: 305
Create a robot file only with generic imports in a common directory
e.g. myImports.robot
*** Settings ***
Library SeleniumLibrary
Library Collections
Library DateTime
Library ../../Common/HelperClass.py
Library ../../Common/HelperClass2.py
Library ../../Common/LmCommands/GeneralCommand1.py
Library ../../Common/Keywords/TestKeyword.py
Now myImports.robot can be imported to test suites
*** Settings ***
Resource ../../Common/myImports.robot
Upvotes: 1