1. 程式人生 > >robotframework - 框架做介面自動化get請求

robotframework - 框架做介面自動化get請求

1、做get請求之前先安裝 Request庫,參考github上鍊接 :https://github.com/bulkan/robotframework-requests/#readme

2、請求&響應使用moco來模擬伺服器,可參考此篇文件:Moco模擬伺服器post&get請求 (二)

3、get 請求流程如下:

a.建立session伺服器連結

b.get請求把url和資料傳入

c.判斷響應狀態碼是否為200

d.將響應的格式轉換為json格式

e.將json設定為引數 字典的格式

f.判斷斷言是否為success & 200

 

4、可在pycharm上編輯,如下:

*** Settings ***
Library RequestsLibrary
Library Collections

*** Test Case ***
testget
${payload} Create Dictionary eid=1
Create Session event http://127.0.0.1:8899/api
${r}= Get Request event /get_event_list params=${payload}
Should Be Equal As Strings ${r.status_code} 200
log ${r.json()}
${dict} Set variable ${r.json()}
#斷言結果
${msg} Get From Dictionary ${dict} msg
Should Be Equal ${msg} success
${sta} Get From Dictionary ${dict} status
${status} Evaluate str(200)
Should Be Equal ${sta} ${status}

 

5、執行結果如下:

6、執行結果report.html 如下:

&n