天天看點

Robot Framework經驗談 -- 将已有庫運作為Remote庫的例子

在目标機器上裝好Python,RF以及你需要的庫,比如你在遠端機器上需要運作Selenium2Library和AutoItLibrary這兩個庫,寫一個簡易的server腳本mysrv.py,然後在遠端機器上打開cmd視窗運作 python mysrv.py 10.22.33.44 8270,如果顯示Robot Framework remote server at 10.22.33.44:8270 starting.就說明啟動監聽服務了。然後在本地RF上加載遠端庫http://10.22.33.44:8270并取個短的别名myremote: Library | Remote | http://10.22.33.44:8270 | WITH NAME | myremote,加載之後如果顯示為黑色而不是紅色,說明遠端庫連接配接成功。接着就可以在本地RF運作遠端Selenium2Library和AutoItLibrary的關鍵字了(如果本地也運作這倆庫,那麼記得關鍵字加字首指明本地還是遠端,比如myremote.Open Browser是遠端執行,而Selenium2Library.Open Browser則是本地執行)。

附注mysrv.py代碼(Xiaoping原創)

 from Selenium2Library import Selenium2Library

from AutoItLibrary import AutoItLibrary

import sys

class MyRemote(Selenium2Library,AutoItLibrary):

    def __init__(self):

        Selenium2Library.__init__(self)

        AutoItLibrary.__init__(self)

    def print_message(self,message):

        print message

if __name__ == '__main__':

    from robotremoteserver import RobotRemoteServer

    RobotRemoteServer(MyRemote(), *sys.argv[1:])

繼續閱讀