当前位置:网站首页>接口自动化测试基础篇
接口自动化测试基础篇
2022-08-10 12:29:00 【Jerry Lee~】
一、认识requests库的常用方法
python的第三方库:pip install requests
知识点:pytest的默认的测试用例的规则
1.模块名必须以test_或者_test结尾。
2.类名必须以Test开头
3.测试用例名必须以test_开头
post,delete,put,get 增加,删除,修改,查询 restful
def get(url, params=None, **kwargs): #发送get请求
def post(url, data=None, json=None, **kwargs): #发送post请求
data是表单传参
json是json数据传参
def put(url, data=None, **kwargs): #发送put请求
def delete(url, **kwargs): #发送delete请求
----------------------前面四个方法都会调用下面的方法-------------------------
def requests.request(method, url, **kwargs): #根据method传参的请求方式发送请求
----------------------前面这个方法调用下面的request方法-----------------------
def session.request(
self,
method,
url,
params=None,
data=None,
headers=None,
cookies=None,
files=None,
auth=None,
timeout=None,
allow_redirects=True,
proxies=None,
hooks=None,
stream=None,
verify=None,
cert=None,
json=None,
):
---------------------------------------------------------------------------------
def session(): #获得会话对象
method:请求方式
url:请求路径
params:get请求传参
data=None 可以是post或者put传参
json=None post请求的第二种传参方式
headers=None 请求头
cookies=None 请求头里面的cookie信息
files=Nnoe 文件上传
stream=None 文件下载
二、认识reponse的常用方法
- res.txt 返回字符串
- res.content 返回字节数据
- res.json() 返回json数据,python是字典
- res.status_code 返回状态码
- res.reason 返回状态信息
- res.cookies 返回响应cookie
- res.encoding 返回响应编码
- res.headers 返回响应头
- res.request.xxx 返回请求的一些数据
三、实战
get请求通过params传参
post请求通过data和json传参
1、表单文件传参:Content-Type:form-data(multipart/form-data),支持上传文件的表单类型;
2、表单传参:Content-Type:x-www-form-urlencoded,表单类型的接口请求;
3、文本raw传参:json:Content-Type:application/json(支持各种原生的类型,JSON类型的接口请求);
4、binary二进制传参:Content-Type:Content-Type:application/octet-stream (二进制,流类型的接口请求 ):对应着http请求中的Content-Type:application/octet-stream,只可以上传二进制数据,通常用来上传文件,由于没有键值,所以,一次只能上传一个文件;
四、鉴权(cookie鉴权和session鉴权和token鉴权)
鉴定是否有访问接口的权限。
session和token都是可以通过cookie传输。
原理
cookie:保存在浏览器种,有大小限制,有状态;
session:保存在服务器中,服务器有资源开销,分布式、跨系统不好实现;
Token:客户端可以将Token保存到任何地方,无限制,无状态,利于分布式部署。
边栏推荐
- 「网络架构」网络代理第一部分: 代理概述
- [List merge] Combine multiple lists into one list
- 广东10个项目入选工信部2021年物联网示范项目名单
- 海外邮件发送指南(二)
- Nanodlp v2.2/v3.0 light curing circuit board, connection method of mechanical switch/photoelectric switch/proximity switch and system state level setting
- 【百度统计】用户行为分析
- MYSQL误删数据恢复
- Jenkins修改默认主目录
- Solve the idea that unit tests cannot use Scanner
- kubernetes介绍
猜你喜欢
关于flask中static_folder 和 static_url_path参数理解
Comparison version number of middle questions in LeetCode
ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]
Alibaba Cloud Jia Zhaohui: Cloud XR platform supports Bizhen Technology to present a virtual concert of national style sci-fi
Ethernet channel 以太信道
mSystems | Zhongnong Wang Jie Group Reveals the Mechanisms Affecting Soil "Plastic Interstitial" Microbial Communities
数字藏品,“赌”字当头
Is there a problem with the CURRENT_TIMESTAMP(6) function?
鸿蒙开发从hello world开始
CV复习:空洞卷积
随机推荐
iTextSharp 使用详解
Custom filters and interceptors implement ThreadLocal thread closure
教育Codeforces轮41(额定Div。2)大肠Tufurama
The basic components of Loudi plant cell laboratory construction
MySQL面试题——MySQL常见查询
讯飞创意组别 全国选拔赛成绩公布说明
娄底干细胞制备实验室建设须知要求
IP地址分类以及网络地址的计算(子网划分、超网划分)[通俗易懂]
BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection Paper Notes
Chapter9 : De Novo Molecular Design with Chemical Language Models
Highways「建议收藏」
金山云要飘到哪里?
瑞幸「翻身」?恐言之尚早
Loudi Cosmetics Laboratory Construction Planning Concept
【iOS】面试整理
【黑马早报】雷军称低谷期曾想转行开酒吧;拜登正式签署芯片法案;软银二季度巨亏230亿美元;北京市消协约谈每日优鲜...
mSystems | 中农汪杰组揭示影响土壤“塑料际”微生物群落的机制
AtCoder Beginner Contest 077 D - Small Multiple
什么是云流化?
Comparison version number of middle questions in LeetCode