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 如下:

 


免責聲明!

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



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