Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Library contains no keywords

I'm beginner to robot framework. I wanted to use my own library,do import and write test case.unfortunately I'm facing an error "Import Library contains no keywords" .I have gone through some of the posts realted to this in stack over flow ,but still i'm not able to figure out the issue in robot framework. I might be doing something silly. Here is my code in python

class ExampleLibrary(object):

    def __init__(self):        
        print "Hello"
    def hello(self):
        print "The given name"

here is the error [ WARN ] Imported library RobotFramework\TestSuite\Testclass.py' contains no keywords.

I have placed the .py file in the same directory as the test case.

Robotframework script

*** Settings ***

Library           Testclass.py

*** Test Cases ***

LibraryTest

    hello

Please Help

Thanks in advance

like image 613
Chandan Kumar Avatar asked Jun 09 '16 07:06

Chandan Kumar


2 Answers

Class name of your library must be same as filename. Please have a look at this: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-library-class-or-module

class Testclass(object):

    def __init__(self):
        print "Hello"

    def hello(self):
        print "The given name"
like image 58
Pekka Avatar answered Oct 21 '22 15:10

Pekka


You should follow Pekka's answer or change your import as below:

*** Settings ***
Library  ExampleLibrary.TestClass

From Documentation:

Python classes are always inside a module. If the name of a class implementing a library is the same as the name of the module, Robot Framework allows dropping the class name when importing the library. For example, class MyLib in MyLib.py file can be used as a library with just name MyLib. This also works with submodules so that if, for example, parent.MyLib module has class MyLib, importing it using just parent.MyLib works. If the module name and class name are different, libraries must be taken into use using both module and class names, such as mymodule.MyLibrary or parent.submodule.MyLib.

like image 1
anukalp Avatar answered Oct 21 '22 16:10

anukalp