无法使用使用 Python 编写的 Robot Framework 自定义库 [英] Unable to use Robot Framework custom library which has written using Python

查看:46
本文介绍了无法使用使用 Python 编写的 Robot Framework 自定义库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Created a sample Python script( Elements.py) with a function like below:

from robot.api.deco import keyword

@keyword("join two strings")
def join_two_strings(arg1, arg2):
   return arg1 + " " + arg2

然后我已经将 Robot Framework 脚本(.robot 文件)作为库导入:

Then I have imported into Robot Framework script(.robot file) as a Library:

*** 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

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

After running above the script, getting error like "No keyword with name 'join two strings' found." even though where I have imported the Custom library.

错误信息:

[ 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.

推荐答案

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

I always have to use relative paths unless the file is in the same directory as my test case and based on the error it looks like yours is not.

>

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

So in your case it would look something like the following (Not exactly this as I don't know where Elements.py is located):

Library    ../../SafeMobile/Elements.py

希望这会有所帮助!

这篇关于无法使用使用 Python 编写的 Robot Framework 自定义库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆