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這個庫了