1. 首先在..\Python27\Lib\site-packages 目录下创建MyLibrary 目录,用于放自定义的library库。
2.在MyLibrary 文件夹下新建mylibrary.py文件创建自己的关键字,如下所示:
class MyLibrary(object):
def test1(self):
"""test 1"""
print "test1"
def test2(self):
"""test 2"""
print "test1"
def test3(self):
"""test 3"""
print "test3"
这里我们定义了三个关键字test1,test2,test3
2.要想在robot framework 启动后加载这些关键字,还需要在MyLibrary 目录下创建__init__.py 文件,并且它不是空的。
# mylibrary 即建立的py文件名,MyLibrary即关键字Class名
from mylibrary import MyLibrary
__version__ = '0.1'
class MyLibrary(MyLibrary):
"""
this is comment about mylibrary
"""
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
这个文件中其实有用的信息就三行,但必不可少。robot framwork 在启动时会加载这个文件,因为
在这个文件里指明了有个mylibrary 文件下面有个MyLibrary类。从而加载类里的方法(test1(),test2等)。
这样在robot framework RIDE中就可以像添加普通库一样,添加自定义的MyLibrary这个库了