当前位置:网站首页>Interface Automation Testing Basics
Interface Automation Testing Basics
2022-08-10 13:19:00 【Jerry Lee~】
I. Common methods of understanding the requests library
The third-party library for python: pip install requests
Knowledge point: pytest's default test case rules
1. The module name must end with test_ or _test.
2. The class name must start with Test
3. The test case name must start with test_
post,delete,put,getAdd, delete, modify, query restful
def get(url, params=None, **kwargs): #Send get requestdef post(url, data=None, json=None, **kwargs): #Send post requestdata is a form parameterjson is json data parameterdef put(url, data=None, **kwargs): #Send put requestdef delete(url, **kwargs): #Send delete request----------------------The first four methods will call the following methods-------------------------def requests.request(method, url, **kwargs): #Send the request according to the request method of the method passing parameters----------------------The previous method calls the following request method-----------------------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(): #Get the session object
method: request method
url: request path
params: get request parameters
data=None can be a post or put parameter
json=None The second way to pass parameters for post requests
headers=None Request headers
cookies=None cookie information in the request header
files=Nnoe file upload
stream=None File Download
Second, common methods of understanding response
- res.txt Return String
- res.content Returns byte data
- res.json() Returns json data, python is a dictionary
- res.status_code Returns the status code
- res.reason Returns status information
- res.cookies Returns the response cookie
- res.encoding Returns the response encoding
- res.headers Returns response headers
- res.request.xxx returns some requested data
Three, actual combat
get request passes parameters through params
The post request passes parameters through data and json
1. Form file transfer parameters: Content-Type: form-data (multipart/form-data), which supports uploading files FormType;
2. Form parameters: Content-Type: x-www-form-urlencoded, interface request of form type;
3. Text raw parameters: json: Content-Type: application/json (supports various native types, JSON type interface requests);
4, binary binary parameter: Content-Type: Content-Type: application/octet-stream (binary, stream type interface request): Corresponding to Content-Type: application/octet-stream in the http request, onlyBinary data can be uploaded, usually used to upload files. Since there is no key value, only one file can be uploaded at a time;
Fourth, authentication (cookie authentication, session authentication and token authentication)
Identify whether you have permission to access the interface.
Both sessions and tokens can be transmitted through cookies.
Principle
cookies: stored in the browser, with size limit and status;
session: stored in the server, the server has resource overhead, distributed and cross-system is not easy to achieve;
Token: The client can save the Token anywhere, unlimited and stateless, which is conducive to distributed deployment.
边栏推荐
猜你喜欢
LeetCode简单题之合并相似的物品
【论文+代码】PEBAL/Pixel-wise Energy-biased Abstention Learning for Anomaly Segmentation on Complex Urban Driving Scenes(复杂城市驾驶场景异常分割的像素级能量偏置弃权学习)
数字藏品,“赌”字当头
生成树协议STP(Spanning Tree Protocol)
jenkins数据迁移和备份
ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]
11+ chrome高级调试技巧,学会效率直接提升666%
mSystems | Zhongnong Wang Jie Group Reveals the Mechanisms Affecting Soil "Plastic Interstitial" Microbial Communities
ASP.NET Core依赖注入系统学习教程:ServiceDescriptor(服务注册描述类型)
浙大、阿里提出DictBERT,字典描述知识增强的预训练语言模型
随机推荐
Solution for "Certificate not valid for requested usage" after Digicert EV certificate signing
神了!阿里数据库专家纯手写了这份604页的Oracle+MySQL攻坚指南
LeetCode medium topic search of two-dimensional matrix
Mysql—— 内连接、左连接、右连接以及全连接查询
Jenkins修改端口号, jenkins容器修改默认端口号
Wirshark common operations and tcp three-way handshake process example analysis
在web页面播放rtsp流视频(webrtc)
M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
协程与任务
一个 CRM One Order Application log 的单元测试报表
ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]
Loudi Cosmetics Laboratory Construction Planning Concept
iTextSharp操作PDF
I would like to ask the big guys, how to solve this error when cdc oracle initializes a 3 million table task running
把相亲角搬到海外,不愧是咱爸妈
【数字IC验证进阶】SoC系统验证和IP模块验证的区别及侧重点分析
娄底农产品检验实验室建设指南盘点
Codeforces Round #276 (Div. 1) D. Kindergarten
漏洞管理计划的未来趋势
线代 | 秒杀方法与技巧