简体   繁体   中英

Importing custom testing library in Robot Framework

I am writing a custom testing library for Robot Framework in Python and I want to import it like this:

Library         CustomLibrary

I put the folder containing the source code on the PYTHONPATH but I am still getting the error: Importing test library 'CustomLibrary' failed: ImportError: No module named CustomLibrary

The CustomLibrary class is defined in the __init__.py file, like in the AppiumLibrary like this:

from CustomLibrary.keywords import *

class CustomLibrary(_CustomKeywords):
    ROBOT_LIBRARY_SCOPE = 'GLOBAL'

How can I solve this problem, so I can import it in Robot Framework? I want to keep the class definition inside the init file.

You need to make sure that the folder containing CustomLibrary is on PYTHONPATH.

For example, the following works as expected for me:

  1. create a folder in /tmp named CustomLibrary
  2. create a file named /tmp/CustomLibrary/__init__.py
  3. define a class named CustomLibrary in /tmp/CustomLibrary/__init__.py
  4. define a method in the CustomLibrary class
  5. import the library in a test with Library CustomLibrary
  6. add /tmp to PYTHONPATH and run robot. For example, robot --pythonpath /tmp example.robot

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM