无法使用使用 Python 编写的 Robot Framework 自定义库

Ram*_*man 4 python pycharm robotframework

使用如下函数创建了一个示例 Python 脚本(Elements.py):

from robot.api.deco import keyword

@keyword("join two strings")
def join_two_strings(arg1, arg2):
   return arg1 + " " + arg2
Run Code Online (Sandbox Code Playgroud)

然后我将机器人框架脚本(.robot 文件)作为库导入:

*** Settings ***
Library                 AppiumLibrary
Library                 Selenium2Library
Library                 BuiltIn
#Here is the import of Custom Lib
Library                 Elements.py 

*** Variable ***

*** Test Cases ***
Example that calls a Python keyword
   ${result}=   join two strings   hello world
   Should be equal     ${result}    hello world
Run Code Online (Sandbox Code Playgroud)

在脚本上方运行后,出现“找不到名称为‘连接两个字符串’的关键字”之类的错误。即使我已经导入了自定义库。

错误信息:

[ ERROR ] Error in file C:\Users\ramana.gouda\PycharmProjects\SafeMobile\Test_Suite\TestCase_346.robot: Test library 'Elements.py' does not exist.

TestCase 346 :: Creating internal cases using device                          

Example that calls a Python keyword                                   | FAIL |
No keyword with name 'join two strings' found.
Run Code Online (Sandbox Code Playgroud)

cul*_*zie 5

我总是必须使用相对路径,除非文件与我的测试用例位于同一目录中,并且根据错误,它看起来不像你的。

因此,在您的情况下,它看起来类似于以下内容(不完全是这样,因为我不知道 Elements.py 位于何处):

Library    ../../SafeMobile/Elements.py
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!