Path to Robot Framework libraries and resources

Introduction

From this article you will learn how to explicitly specify the path to resources and external Python libraries in Robot Framework.

This will be especially useful for those who write their own libraries for the robot and/ or use a complex structure with a large number of nestings.

I recommend that you first read the articles about test architecture and about connecting external Python libraries

In the example from the article «Connecting external Python libraries» the libraries were in the directory libraries and the tests in tests

ext_py_lib/ |-- browser |-- libraries | `-- unstable_url.py `-- tests `-- test_title.robot

Therefore, the library import looked like this original way

Library ../libraries/unstable_url.py

If subdirectories appear in the tests directory, the import from there will look like this

Library ../../libraries/unstable_url.py

or even like that

Library ../../../libraries/unstable_url.py

To avoid doing a relative import, you can use one of the methods described below.

--pythonpath

Using the --pythonpath option, you can temporarily add the path to the libraries to PYTHONPATH

Starting with this example, we will specify libraries without .py

Library unstable_url

robot --pythonpath /c/Users/Andrei/robot/ext_py_lib/libraries test_unstable_title.robot

--argumentfile

To avoid entering the path manually, you can save it in the so-called argumentfile

Let's create a file all_arguments.robot and add the following code there

--pythonpath /c/Users/Andrei/robot/ext_py_lib/libraries test_unstable_title.robot

To use this file, we will use the --argumentfile option.

robot --argumentfile all_arguments.robot test_unstable_title.robot

Official documentation

Dockerfile

If your environment is created using Docker , then the path to the libraries can be specified in Dockerfile

An example that works in one of my projects:

… ENV TEST_DIR=/opt ENV PYTHON_DIR=/user/local/bin/python ENV ROBOT_RESOURCES=/opt/robot/src/resources ENV ROBOT_LIBRARIES=/opt/robot/src/libraries ENV PYTHONPATH=$TEST_DIR:$PYTHON_DIR:$ROBOT_RESOURCES:$ROBOT_LIBRARIES …

Article author: Andrei Olegovich

Related articles
Robot Framework
Architecture
Logs
__init__.robot
Create custom .py libs
Path to libs and resources
Keyword as decorator
Template
Parametrize
Demo with pywinauto

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: