robotframework - 框架做接口自動化post請求


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

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

3、get 請求流程如下:

a.創建session服務器鏈接

b.post請求把url和數據傳入

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

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

e.將json設置為參數 字典的格式

f.判斷斷言是否為 10201

4、在pycharm上編輯如下:

*** Settings ***
Library RequestsLibrary
Library Collections
testpost
Create Session event http://127.0.0.1:8899/api
&{headers} Create Dictionary Content-Type=application/x-www-form-urlencoded
&{payload}= Create Dictionary eid=1
${r} Post Request event /add_event/ data=${payload} headers=${headers}
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} parameter error
${sta} Get From Dictionary ${dict} status
${status} Evaluate str(10021)
Should Be Equal ${sta} ${status}

5&6 運行結果可參考下:robotframework - 框架做接口自動化get請求

 


免責聲明!

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



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