robotframework - 框架做接口自动化post请求 Moco模拟服务器post&get请求 (二) robotframework - 框架做接口自动化get请求

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请求

猜你喜欢

转载自www.cnblogs.com/Teachertao/p/11042802.html
今日推荐