问题
I have several test files in different folders (for different issues) and I want to use a separate folder that will contain all the Custom Libraries I use. All of the sub folders, including the custom libraries, will be in one master folder. How do I import the test library from the separated folder?
Here is the folder hierarchy:
Test Library
-Test Suite1
-test1.txt
-test2.txt
-Test Suite2
-test3.txt
-Custom Libraries
-customlibrary.py
Thank you.
回答1:
There are many ways. For one, just use the path. For example:
*** Settings ***
| Library | ../Custom Libraries/customlibrary.py
Or, you can add Test Library/Custom Libraries
to your PYTHONPATH variable and just use the library name itself:
*** Settings ***
| Library | customlibrary
Or, you can set a variable that defines the directory -- either in a variables table or from the command line:
*** Variables ***
| ${LIBRARIES} | Test Library/Custom Libraries
*** Settings ***
| Library | ${LIBRARIES}/customlibrary.py
This is all described in the robot framework user guide, under the section Taking test libraries into use
来源:https://stackoverflow.com/questions/31244476/import-custom-library-from-a-different-path-in-robot-framework