当前位置:网站首页>How to use mitmproxy to get data return in automated testing?
How to use mitmproxy to get data return in automated testing?
2022-07-24 00:43:00 【TEST_ Two black】
Background introduction
When we are at the interface or UI In automation projects , This phenomenon often occurs —— It's obviously a normal request , But can't get the desired data return .
such as :
scene A: Pages are dynamic data , The data obtained by entering the page for the first time , It is completely different from the data obtained next time you enter the page .
scene B: Page data has display restrictions , Some modules of the page or the entire page data are only displayed 3 Time , And the server returns the control .
What should we do at this time ?
If it is a manual test , We can use it directly Charles、Fiddler To simulate , After all, agent software can basically solve most of the testing needs .
What if it's in an automation project ? If you still use agent software —— In fact, it's not completely impossible , But we have better ways to practice .
That is to use MitmProxy Act as a forward proxy to intercept requests and return data .
How to use MitmProxy As a forward agent
Realization Maplocal
MitmProxy It's a tripartite library , We can regard it as Charles To use .
Here to achieve Maplocal Function description :
(1)Maplocal function , The simple understanding is when specific requests , Return specific data .
For example, request "www.baidu.com", Normal should return to :

But we modify the returned data , As long as there is "www.baidu.com" Please come here , Just let it return automatically :
This is the most basic maplocal Case study .
(2) stay MitmProxy How to realize Maplocal What about function? ?
Here we use get Request the implementation to explain :
get.json The configuration file , Record all that need to be intercepted here get request :
MitmProxy Script :

In the executed script ( Like local shell or Other implemented py Script ):
After starting the script , Connect MitmProxy All requests from devices will be monitored by scripts .
If appear "www.baidu.com" Request , It will come to get.json Find the corresponding in json, Automatically return to the device .
such , It realizes the simplest maplocal.
Of course, based on the current MitmProxy Script , We can also expand some functions .
For example, for the interface type get or post request , For request parameter type json or x-www-form-urlencoded, Can be extended more .
Send learning resources to

These materials , For doing 【 software test 】 It should be the most comprehensive and complete war preparation warehouse for advanced friends , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful …….
边栏推荐
- Beifeng communication appeared in China (Xiamen) emergency exhibition | intelligent communication means are strong and eye-catching!
- QT入门篇(2.1初入QT的开始第一个程序)
- Gbase 8C access authority access function (IV)
- SAP 电商云 Spartacus UI Store 相关的设计明细
- Dataframe.groupby learning materials
- Blockbuster | certik: Web3.0 industry safety report release in the second quarter of 2022 (PDF download link attached)
- GBase 8c 字符串操作符
- Bean Validation使用篇----05
- MySQL client to server character set conversion
- 如何在自动化测试中使用MitmProxy获取数据返回?
猜你喜欢

How to speed up matrix multiplication -- optimizing GEMM (CPU single thread)

Reverse linked list drawing demonstration

Redis cluster hash sharding algorithm (slot location algorithm)

The high-quality digital collection of guochuang's "children's song line" is on sale, and you are invited to create a young martial arts Jianghu dream

Classic example of C language - loan balance

PayPal subscription process and API request

postman测试接口在URL配置正确的情况下出现404或者500错误

入职3个月的测试员面临转正,领导:1年工作经验包装成5年,试用期淘汰

Method of C language annotation

English grammar_ Demonstrative pronoun - so
随机推荐
如何提升数据质量
数据模型设计方法概述
Coloring old photos - deoldify get started quickly
Bean Validation自定义容器验证篇----06
多源文件方式去访问全局变量的方式(extern用法)
Redis distributed lock to be continued
工作3年的测试员跳槽后工资是原来的2倍,秘诀原来是......
Inode, soft link, hard link
Intelligent OCR identification of express documents helps the logistics industry to upgrade Digitalization
北峰通信亮相中国(厦门)应急展|智能化通信手段强势吸睛!
mysql 分支语句case报错
Summary of pit websocket
Gbase 8C access authority query function (II)
Dataframe.groupby learning materials
Don't let Fujin Yibo see this
Multi data source configuration of mongodb
GBase 8c 访问权限访问函数(四)
High number_ Chapter 2 differential calculus of multivariate functions__ Geometric application of partial derivatives_ Tangent and normal plane of space curve
Unity metaverse (I). Ready player me & blender customize your Avatar
网络系统实验:ping不通的问题解决