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

一、作get請求以前先安裝 Request庫,參考github上連接 :https://github.com/bulkan/robotframework-requests/#readmehtml

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

三、get 請求流程以下:github

a.建立session服務器連接json

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

c.判斷響應狀態碼是否爲200服務器

d.將響應的格式轉換爲json格式session

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

f.判斷斷言是否爲 10201框架

四、在pycharm上編輯以下:post

*** 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請求
相關文章
相關標籤/搜索