Robot Framework常用關鍵字


雖然通過RIDE提供“填表”一樣的寫測試用例的方式。但它卻支持強大的關鍵字功能,以及可以開發關鍵字的擴展能力。

Comment

注釋功能,也可以使用python中的"#"

Comment 注釋
#注釋

log

打印。類似於print

log Hello World

set variable

定義變量

${a} set variable Hello World!!!
log ${a}

catenate

連接對象

${a} catenate hello world
log ${a}

SEPARATOR

對多個連接進行分割(必須大寫)

${a} catenate SEPARATOR=, hello world
log ${a}

create list

創建列表

${a} create list a b c
log ${a}

通過@{}定義列表

必須使用 log many 打印

@{a} create list a b c
log many @{a}

get time

獲取當前時間

${a} get time
log ${a}

sleep

設置休眠時間

${a} get time
sleep 5
${a} get time

run keyword if

通過該語句可以編寫if分支語句

${a} set variable 59
run keyword if ${a}>=90 log 優秀
... ELSE IF ${a}>=60 and ${a}<90 log 一般
... ELSE log

:FOR

實現循環

:FOR ${i} IN RANGE 10
log ${i}

列表遍歷

@{lista} create list a b c
:FOR ${a} in @{lista}
log ${a}

Exit For Loop If

退出循環的判斷語句

@{lista} create list a b c
:FOR ${a} IN @{lista}
exit for loop if '${a}'=='b'
log ${a}

Evaluate

執行python中的方法

${a} Evaluate random.randint(1000,9999) random
log ${a}

Import Library

導入標准和第三方模塊或框架。比如調用unittest單元測試框架

Import Library unittest

導入外部py文件

Import Library c:/test.py
${sum} add 3 4
log ${sum}
Import Library c:/test.py
${a} Evaluate int(4)
${b} Evaluate int(5)
${sum} add ${a} ${b}
log ${sum}

Take Screenshot

截取當前屏幕,Screenshot庫為robot framework的標准類庫,需手動加載

字典

Collections庫:該庫為Robot Framework標准類庫,它提供的關鍵字主要用於列表、索引、字典的處理。需要手動加載。

Create Dictionary

創建字典

${dict} Create Dictionary sname Luffy age 19

Get Dictionary Items

獲取字典中的key和value

| ${item} | Get Dictionary Items | ${dict} |
| log | ${item} ||

Get Dictionary Keys

獲取字典中的key

${keys} Get Dictionary keys ${dict}
log ${keys}

Get Dictionary Values

獲取字典中的value

${values} Get Dictionary Values ${dict}
log ${values}

Get From Dictionary

根據key獲取對應的value

${a} Get From Dictionary ${dict} sname
log ${a}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM