robot 關鍵詞

weixin_34185364發表於2018-05-04

關鍵詞

  • 建立resource型別的userkey.robot檔案
*** Keyword ***
mykeyworkd      
    [Arguments]        ${input}
    Log    ${input}    
    
  • 使用時引入
*** Settings ***
Resource    userkey.robot

*** Test Cases ***
test
    mykeyworkd    hello world

python子函式引入

  • 建立任意python檔案
#conding=utf-8

def addNum(num1,num2):
    return int(num1)+int(num2)
  • 在需要使用的地方引入library
*** Settings ***

*** Test Cases ***
test
    Import Library    /Users/peter/Desktop/hlpx/03test/good/myrobot/mygod/apitestsuite/userpython.py
    ${ret}         addNum     19    4    

自定義python庫

  • 在python庫目錄編寫庫檔案
➜  myCustomLibrary pwd
/Library/Python/2.7/site-packages/myCustomLibrary
➜  myCustomLibrary cat myclass.py
class MyClass(object):
    def __init__(self):
        pass

    def printMsg(self,msg):
        print "hello "+msg
➜  myCustomLibrary cat __init__.py
from myclass import MyClass

class myCustomLibrary(MyClass):
    ROBOT_LIBRARY_SCOPE = 'GLOBAL'
  • 在robot中引用
*** Settings ***
Library        myCustomLibrary


*** Test Cases ***
test
    printMsg        god

相關文章