请大家先看看RequestsLibrary和接口测试官方用例这2个官方链接
RequestsLibrary 库接口测试用例:
*** Settings *** | ||||
Library | Collections | |||
Library | RequestsLibrary | |||
*** Test Cases *** | ||||
Get Requests | ||||
Create Session | github | http://api.github.com | ||
Create Session | http://www.google.com | |||
${resp}= | Get Request | / | ||
Should Be Equal As Strings | ${resp.status_code} | 200 | ||
${resp}= | Get Request | github | /users/bulkan | |
Should Be Equal As Strings | ${resp.status_code} | 200 | ||
Dictionary Should Contain Value | ${resp.json()} | Bulkan Savun Evcimen |
然后我们可以按照这样的思路去进行接口测试
第1步:创建一个请求header信息(可以根据自己的情况添加所需的值,类似于jmeter的头文件,不一定是必须的,可以用作切换体验区或者稳定区)
第2步:创建session,在get request或者post request时,可识别session。
第3步:发起请求。返回对象${resp}
第4步:判断请求响应是否为成功,${resp.status_code} 200
第5步:判断需要判断的接口中的值,或者数据类型,或者数据格式等等
判断返回的字典中是否包含abc: Dictionary Should Contain Value ${resp.json()} abc
判断返回的字典中code是否为0: Should Be Equal As Strings ${resp.json()['code']} 0
判断返回的字典中result不能为空:Should not be empty ${resp.json()['result']}