Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use Robot Framework custom library which has written using Python

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

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 Message:

[ 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.
like image 763
Raman Avatar asked Jan 26 '23 17:01

Raman


1 Answers

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.

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

Hope this helps!

like image 131
cullzie Avatar answered Jan 31 '23 10:01

cullzie