I created Testclass.py as below:
class Testclass(object):
def testmethod(self):
print "Hi"
And I accessed it from .robot file as
Library Testclass
and I called method testmethod.
But when I run through command line pybot login.robot I get import error
Error in file 'login.robot': Importing test library 'Testclass' failed: ImportError: No module named Testclass
If I don't define class and only define method it works.
The problem is simply that robot cannot find your library. It only looks in places in your PYTHONPATH. So, one solution is to add the path to your library to your PYTHONPATH environment variable.
You can also use the --pythonpath option to pybot if you don't want to alter your PYTHONPATH.
For example, assuming your file
Testclass.py
is in the folder./robot/libraries
, you can run your tests like this:For more information about this option, see the section Configuring where to search libraries and other extensions in the robot framework user guide.
You can also specify the file by path, if you want to hard-code the path of the file into your test case. If you do this, the class name inside the file must match the filename (eg:
class Testclass
inTestclass.py
).For example:
This is covered in the robot framework user guide, in the section Specifying library to import.