I created Testclass.py as below:
class Testclass(object):
def testmethod(self):
print "Hi"
And I accessed it from my login.robot
file as
Library Testclass
and I called method testmethod
from my Robot Framework suite file.
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:
pybot --pythonpath ./robot/libraries my_test_case.robot
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
in Testclass.py
).
For example:
*** Settings ***
| Library | robot/libraries/Testclass.py
This is covered in the robot framework user guide, in the section Specifying library to import .
If your Testclass.py Library and .robot file are in the same folder use following:
Library Testclass.py
Make sure that class and python file Name are the same.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.