当前位置:网站首页>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 …….
边栏推荐
- There are various signs that apple is expected to support AV1
- Printf function - conversion description
- Classic examples of C language switch case statement conversion date format
- Notes and Thoughts on the red dust of the sky (VI) due to lack
- Classic example of C language - convert the input two digits into English
- Classic examples of C language - adding two scores
- Gbase 8C session information function (V)
- 【数据挖掘工程师-笔试】2022年海尔 公司
- MySQL table field quantity limit and row size limit
- GBase 8c 访问权限查询函数(二)
猜你喜欢

【LeetCode第 83 场双周赛】

Problem note - unable to open include file: "direct.h": no such file or directory

Educational Codeforces Round 132 (Rated for Div. 2) D. Rorororobot

【电赛训练】非接触物体尺寸形态测量 2020年电赛G题

The prediction of domestic AI protein structure reproduced a breakthrough and solved the 3D structure with a single sequence. Peng Jian's team: "the last piece of puzzle since alphafold2 has been comp

Generic mechanism and enhanced for loop
CA digital certificate

如何提升数据质量

Codeforces Round #807 (Div. 2)(A-D)

Summary of polynomial commitment schemes
随机推荐
Accelerating matrix vector multiplication of special matrices with FFT
GBase 8c 访问权限查询函数(一)
Gbase 8C access authority access function (IV)
Generic mechanism and enhanced for loop
GBase 8c 会话信息函数(三)
Method of C language annotation
Inode, soft link, hard link
GBase 8c 字符串操作符
Flutter | firstwhere error reporting
MySQL client to server character set conversion
C language: deep analysis of const keyword
Classic example of C language - find the minimum number of banknotes
CA digital certificate
Development of main applet for business card traffic near the map
How to speed up matrix multiplication -- optimizing GEMM (CPU single thread)
A good habit to develop when writing SQL
暑假第四周总结
Expérience du système réseau: résoudre les problèmes de ping
GBase 8c 字符串操作符
Bean validation custom container validation chapter ----06