概述
1. 安装robotframework-requests
pip install robotframework-requests
2. 发起请求
a. Create Session:创建一个与服务器的会话
参数:
alias:别名,作为当前会话的标识
url:服务器地址,基本地址,不是接口地址
b. Post Request:发起post请求
alias:选择一个会话的别名,来自于Create Session
url:接口地址,不包含服务器地址
data:请求提参数
返回值:response 对象
注意:post 请求一定要添加请求头,否则发送请求会失败
*** Settings ***
Library
RequestsLibrary
*** Test Cases ***
测试用例1-发送post请求:
#需要创建session,在通session发起请求
Create Session
qcdApi
http://api.lemonban.com/futureloan
#测试数据
&{testdata}
Create Dictionary
mobile_phone=13122907522
pwd=12345678
&{headers}
Create Dictionary
X-Lemonban-Media-Type=lemonban.v2
User-Agent=Mozilla/5.0 LookSky
#发起post请求,一定需要传headers
${resp}
Post Request
qcdApi
/member/register
json=${testdata}
headers=${headers}
Log
${resp.status_code}
Log
${resp.text}
c. Get Requests:发送一个get请求,并返回一个响应对象
alias:选择一个会话别名
url:接口地址,不包含服务器地址
params:请求参数
返回值:response对象
*** Settings ***
Library
RequestsLibrary
*** Test Cases ***
测试用例2-发起get请求:
Create Session
weatherApi
http://www.sojson.com
&{testdata}
Create Dictionary
city=北京
${resp}
Get Request
weatherApi
/open/api/weather/json.shtml
params=${testdata}
Log
${resp.status_code}
Log
${resp.text}
最后
以上就是幸福外套为你收集整理的robotframework_api测试的全部内容,希望文章能够帮你解决robotframework_api测试所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复