robotframework的學習筆記(十四)------學習Robot Framework必須掌握的庫—-BuiltIn庫


       作為一門表格語言,為了保持簡單的結構,RF沒有像別的高級語言那樣提供類似if else while等內置關鍵字來實現各種邏輯功能,而是提供給了用戶BuiltIn庫。如果用戶想在測試用例中實現比較復雜的邏輯,那就需要對BuiltIn中的重要關鍵字有一些了解。BuiltIn庫中還封裝了很多常見方法和能夠控制RF運行狀態的關鍵字,如果想用好RF,一定要對BuiltIn庫中的函數有一個比較全面的理解。下面就帶着大家認識一下BuiltIn庫中比較重要的關鍵字。

Evaluate 關鍵字:

Arguments:[ expression | modules=None | namespace=None ]Evaluates the given expression in Python and returns the results.

如果你需要進行一些數值運算並得到結果,你就需要用到Evaluate關鍵字。Evaluate會把你想要計算的表達式直接傳遞給Python,並把Python的計算結果返回給你。這是最經常要用到的。
 
Should 系列關鍵字:
Should系列關鍵字是Should打頭的一系列關鍵字。
Should Be Empty-------- Verifies that the given item is empty. 
Should Be Equal------- -Fails if the given objects are unequal. 
Should Be Equal As Integers -------- Fails if objects are unequal after converting(轉換) them to integers. 
Should Be Equal As Numbers-------- Fails if objects are unequal after converting(轉換) them to real numbers. 
Should Be Equal As Strings-------- Fails if objects are unequal after converting(轉換) them to strings. 
Should Be True-------- Fails if the given condition(狀態) is not true. 
Should Contain-------- Arguments:[ container | item | msg=None | values=True | ignore_case=False ]Fails if container does not contain(包含) item one or more times.
Should Contain X Times-------- Arguments:[ item1 | item2 | count | msg=None | ignore_case=False ]Fails if item1 does not contain item2 count times.
Should End With-------- Arguments:[ str1 | str2 | msg=None | values=True | ignore_case=False ]Fails if the string str1 does not end with the string str2.
Should Match-------- Arguments:[ string | pattern | msg=None | values=True | ignore_case=False ]Fails unless the given string matches the given pattern.
Should Match Regexp --------Arguments:[ string | pattern | msg=None | values=True ] Fails if string does not match pattern as a regular expression(正則表達式).
Should Start With-------- Arguments: [ str1 | str2 | msg=None | values=True | ignore_case=False ] Fails if the string str1 does not start with the string str2.
Should Not Be Empty
Should Not Be Equal
Should Not Be Equal As Integers
Should Not Be Equal As Numbers
Should Not Be Equal As Strings
Should Not Be True
Should Not Contain
Should Not End With
Should Not Match
Should Not Match Regexp
Should Not Start With
這些關鍵字都是用作判斷時用的,每個用例都會用到,比如我們的執行結果得到了一個字符串,我們要判斷這個字符串要與一個預期字符串相等,否則用例就無法通過,這時候,肯定會用上Should Be Equal As String關鍵字,其它關鍵字我們通過關鍵字的名字就能顧名思義,知道它的作用。
 
Convert To系列關鍵字:
Convert To Binary
Convert To Boolean
Convert To Hex 
Convert To Integer 
Convert To Number 
Convert To Octal 
Convert To String
做類型轉換,將某個值轉換為相對應的類型。
 
Run keyword系列關鍵字:
Run Keyword If------ Arguments: [ condition | name | *args ]Runs the given keyword with the given arguments, if condition is true.
Run Keyword If All Critical Tests Passed
Run Keyword If All Tests Passed
Run Keyword If Any Critical Tests Failed
Run Keyword If Any Tests Failed
Run Keyword If Test Failed
Run Keyword If Test Passed
Run、Keyword If Timeout Occurred
這些關鍵字能根據一個判斷條件的真假來看是否執行關鍵字。一般使用這些關鍵字來實現高級語言中的ifelse功能。最常用的是Run Keyword If 和 Run Keyword unless 他們倆實現的效果正好相反。
 
Exit For Loop關鍵字:
用作退出循環,一般和Run Keyword If關鍵字聯合使用,來實現條件退出。
 
Wait Until Keyword Succeeds關鍵字:
這是一個將異步調用變為同步調用的關鍵字。舉一個例子:如果call某個WebService,並且需要得到返回結果才能做下一部操作。我們就會用到這個關鍵字
 
BuiltIn庫里還有很多寶貝
比如日期相關的關鍵字GetTime。
讓測試暫停的Sleep等。都相當有用。
RF目前僅有2個內置關鍵字:FOF 和 IN,來實現循環結構。功能還是比較弱的。
 


免責聲明!

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



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