【问题标题】:Importing custom testing library in Robot Framework在 Robot Framework 中导入自定义测试库
【发布时间】:2020-02-05 11:27:32
【问题描述】:

我正在为Python 中的Robot Framework 编写一个自定义测试库,我想像这样导入它:

Library         CustomLibrary

我将包含源代码的文件夹放在PYTHONPATH 上,但仍然出现错误:Importing test library 'CustomLibrary' failed: ImportError: No module named CustomLibrary

CustomLibrary 类在__init__.py 文件中定义,就像在AppiumLibrary 中这样:

from CustomLibrary.keywords import *

class CustomLibrary(_CustomKeywords):
    ROBOT_LIBRARY_SCOPE = 'GLOBAL'

如何解决这个问题,以便将其导入 Robot Framework?我想将类定义保留在 init 文件中。

【问题讨论】:

  • 什么是 CustomLibrary 路径?
  • /Users/<user-name>/Desktop/Python/CustomLibrary/
  • 你看过这篇文章了吗? stackoverflow.com/questions/15746675/…
  • 是的。我的所有包裹中都有一个__init__.py 文件
  • 当你说“把包含源代码的文件夹放在PYTHONPATH上”,你是什么意思?如果CustomLibrary 是文件夹foo 中的一个文件夹,您是将foo 放在PYTHONPATH 上,还是foo/CustomLibrary

标签: python robotframework


【解决方案1】:

您需要确保包含 CustomLibrary 的文件夹位于 PYTHONPATH 上。

例如,以下对我来说可以正常工作:

  1. 在 /tmp 中创建一个名为 CustomLibrary 的文件夹
  2. 创建一个名为 /tmp/CustomLibrary/__init__.py 的文件
  3. 在 /tmp/CustomLibrary/__init__.py 中定义一个名为 CustomLibrary 的类
  4. 在 CustomLibrary 类中定义一个方法
  5. 在测试中使用Library CustomLibrary 导入库
  6. 将 /tmp 添加到 PYTHONPATH 并运行机器人。例如,robot --pythonpath /tmp example.robot

【讨论】:

    猜你喜欢
    • 2017-11-18
    • 2015-09-23
    • 1970-01-01
    • 2019-11-02
    • 2015-11-12
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    相关资源
    最近更新 更多