天天看點

RobotFramework 自定義Library

RobotFramework 主要使用Python,這裡簡單自定義Library,以擴充RobotFramework的功能

  1. 建立一個python類,自定義需要的方法

    例如:

    儲存成TestLibrary.py (檔案名和類名一緻)

    class TestLibrary():
        def Add(self,a,b):
            sum = a + b
            return  sum
               
  2. 把這個Python檔案放在,Python目錄下

    例如:

    windows:

    C:\Python27\Lib\site-packages

    mac:

    /Library/Python/2.7/site-packages

  3. 在RobotFramework,測試用例添加Library
    RobotFramework 自定義Library
  4. 可以按下F5檢視關鍵字,看是否生效,如果沒有添加進入,把ride關了,重新打開即可
    RobotFramework 自定義Library
  5. 之後就可以在Case 或者關鍵字裡面引用library了

    (在robot Case 裡面預設的輸入數字,會做為字元串運算,需要轉換成int)

    RobotFramework 自定義Library

    RF 内置有八個基本的Library:

    BuiltIn

    OperatingSystem

    Telnet

    Collections

    String

    Dialogs

    Screenshot

    Remote