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
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With