Robot Framework 常用斷言

2021-09-24 17:38:08 字數 2277 閱讀 1984

robotframework帶有豐富的系統關鍵,使用時無需匯入,直接使用,為寫自動化用例帶來了極大的方便;不能停留在知道或者是會得程度,只有熟練使用各關鍵字,才能提公升自動化用例的寫作效率。

下面將逐個舉例介紹:為方便講解,首先建立三個list變數:list_a、list_b、list_c;以及兩個scalar變數:string和name。

備註:以下提供的用例都是斷言成功。

01、should contain 、 should not contain 與should contain x times

should contain $ 1.0

should not contain $ 1

should contain x times $ 21 2

說明:變數lis

tb包含

物件1.0而不包

含物件1

,且物件

21在變數

包含物件1.0而不包含物件1,且物件21在變數

listb​

包含物件

1.0而

不包含對

象1,且

物件21

在變數出現了兩次。

02、should be empty 與 should not be empty

should be empty $

should not be empty $

說明:變數lis

tc沒有

賦值,所

以為空;

相反,變

量沒有賦值,所以為空;相反,變數

listc​

沒有賦值

,所以為

空;相反

,變數有賦初始值,故為非空。

03、should be equal 與 should not be equal

should be equal $ $

should not be equal $ $

說明:lis

ta[1

]=a,

=a,li

sta​

[1]=

a,=a故兩個物件相等;而lis

ta和和

lista​

和有元素不一致,這兩個物件不相等。

04、should be equal as numbers 與 should not be equal as numbers

should be equal as numbers $ 1.0000

should not be equal as numbers $ 1.1

說明:$=1,忽略精度,故與1.0000相等;而即使是忽略精度,1與1.1還是不相等的;

05、should be equal as integers與should not be equal as integers

should be equal as integers $ $

should not be equal as integers $ $

說明:lis

ta[3

]=21,

=21,

lista​

[3]=

21,=21,而系統預設為字串格式的「21」,故需要轉化為整數型別,轉化為整數後兩個物件相等;

l is

ta[4

]=12,

=12,

lista​

[4]=

12,=21,即使轉化為整數後兩個物件依舊是不相等;

06、should be equal as strings與should not be equal as strings

should be equal as strings $ $

should not be equal as strings $ $

說明:lis

ta[2

]==li

sta​

[2]=

,l is

tb[2

]==li

stb​

[2]=

,而均為數值型的21,故需要轉化為字串型別,轉化為字串後兩個物件相等;

RobotFramework測試Rest服務

python有乙個都對http請求封裝的很好的類庫 requests 見這裡 而rest服務就是基於http請求之上的,活躍的社群也有提供了乙個封裝 robotframework requests 見這裡 可以用來方便的測試rest服務 這裡記錄下在使用過程中碰到的問題 1.import的時候,名字...

RobotFramework 資料分離

robotframework 資料分離分為三種 1.run 新增引數 2.外部的python檔案 3.讀取excel run 新增引數 適用於jenkins 使用 v 引數名 引數值 使用外部的python檔案 使用外部的python檔案進行資料分離的話,首先建乙個python檔案,並在裡面定義乙個...

robot framework環境搭建

一 robot framework環境搭建 官網 序號安裝包名 安裝方法備註1 python exe檔案,直接雙擊安裝 一切的基礎,安裝路徑不能有空格 2setuptools python 的套件管理程式 3pip 1 cmd進入ez setup.py檔案目錄 2 用setuptools安裝 eas...