往期经典文章回顾:
抓包工具mitmproxy | mitmweb基本用法(二)
mitmproxy抓包 | Python实时生成接口自动化用例
mitmproxy抓包 | Python实时生成接口自动化用例(三)
在实际工作中,经常会遇到前端模块开发完了,后端还没开发完,测试闲的没事干,导致测试介入延迟,为了解决此问题,我们可以采用mitmproxy代理抓包进行mock服务测试,根据接口文档mock不同的响应数据,对前端功能进行测试,提前介入测试,暴露问题,节省项目成本。
还有一些疑难测试场景,很难手动模拟出来,简单介绍一种,例如:已打卡,button置灰无法再次打卡测试重复提交,小A说:可以快速连点,如果前端做了防重点,还是很难连点出来进行测试的;小B说:可修改数据库打卡状态,这样只能说明他今天没打卡,还可以进行正常打卡的,未达到测试重复提交测试效果;小C说:可以通过接口重复请求进行测试,这样是可以的,但是只是针对后端重复提交进行了测试,还是未达到前端测试的效果;小D说:可以通过模拟网络延迟,这个应该是可以的,因为当你点击签到时,请求发出去了,响应还没有回来,打卡button还未更新,仍显示的亮起可打卡,这时,可以再次发起第2次打卡,测试重复提交。
借助mitmproxy代理抓包工具的mock功能还是很方便,结合简单的python脚本匹配要mock的接口地址,替换成想要设置的响应数据,每次APP
发起请求,会经过mitmproxy代理抓包工具,得到设置好的响应数据,前端对应展示出我们想要的测试场景。
我们以得物APP-打卡话题列表-今天只晒鞋-打卡,案例实战一下,测试场景:打卡成功,再次打卡
未打卡时,打卡话题页面,今天只晒鞋,立即打卡显示亮起可点击
未打卡时,打卡话题列表接口信息
https://m.dewu.com/sns/v1/tag/clockin-topic-list?newSign=338e7a221b66936aa313763a5c139a42
appId: duapp
brand: Apple
cookieToken: d41d8cd9|1573201658|1638408681|68e26bc5b040d083
emu: 0
isProxy: 1
isRoot: 0
lastId:
limit: 20
loginToken: 44462107|1573201658|4bed211ae9d2d5a8
mode: 0
platform: iPhone
shumeiid: 20210918092735f1e54bce67bb69d503b7fb355c4690cf01d77ce3f35e2132
sign: a2a9aa440b638aafd8b4ff62671231ed
timestamp: 1638409137400
token: JLIjsdLjfsdII%3D%7CMTQxODg3MDczNA%3D%3D%7C07aaal32795abdeff41cc9633329932195
userId: 1573201658
uuid: UUID785a82408e934daf9f9240fb286900ea
v: 4.79.7
{
"data": {
"existOfflineClockin": 0,
"go": true,
"lastId": "",
"list": [
{
"clockInId": "19",
"containsNum": 1971522,
"orderBy": "665",
"tagDesc": "鞋狗每日打卡!晒晒你的宝贝球鞋\n欢迎分享:球鞋上脚照、入手感受、搭配建议等\n图片、文字符合主题,可获得更多点赞和关注!",
"tagId": 295,
"tagName": "今天只晒鞋",
"thumb": "https://du.hupucdn.com/Fu1T5EEUemk6sW6210x8O5M7-woi",
"userContinuousNum": "0",
"userHistoryNum": 0,
"userJoined": "0",
"userRank": "-",
"userTodayJoined": "0"
},
{
"clockInId": "47",
"containsNum": 1594616,
"orderBy": "663",
"tagDesc": "OOTD,来分享你的每日穿搭~",
"tagId": 9,
"tagName": "今天穿什么",
"thumb": "https://du.hupucdn.com/FtoOBG0AM6e0MYXcEvxq6Rctcbjs",
"userContinuousNum": "0",
"userHistoryNum": 0,
"userJoined": "0",
"userRank": "-",
"userTodayJoined": "0"
},
{
"clockInId": "126",
"containsNum": 87783,
"orderBy": "657",
"tagDesc": "欢迎分享各类体育比赛视频,送你上首页推荐!",
"tagId": 267,
"tagName": "体育精彩视频分享",
"thumb": "https://du.hupucdn.com/lghvdJY0hjTdIOHV870o1-l41SHl",
"userContinuousNum": "0",
"userHistoryNum": 0,
"userJoined": "0",
"userRank": "-",
"userTodayJoined": "0"
},
{
"clockInId": "138",
"containsNum": 83280,
"orderBy": "655",
"tagDesc": "欢迎分享你喜爱的、想推荐的说唱音乐视频!\n建议:清晰无水印、写出作品名称、作者名字、你想推荐的理由\n质量越高的内容,越容易获得更多曝光哦!",
"tagId": 1360,
"tagName": "说唱音乐视频分享",
"thumb": "https://du.hupucdn.com/Fr1A4aB9BxdLb_RrHZ84WI6Cj8o7",
"userContinuousNum": "0",
"userHistoryNum": 0,
"userJoined": "0",
"userRank": "-",
"userTodayJoined": "0"
},
{
"clockInId": "140",
"containsNum": 68899,
"orderBy": "650",
"tagDesc": "欢迎分享你喜爱的、想推荐的街舞视频!\n建议:清晰无水印、写出作品名称、作者名字、你想推荐的理由\n质量越高的内容,越容易获得更多曝光哦!",
"tagId": 247,
"tagName": "街舞视频分享",
"thumb": "https://du.hupucdn.com/FoAfCBfHKIfxvr5pWPjvxvBelfZY",
"userContinuousNum": "0",
"userHistoryNum": 0,
"userJoined": "0",
"userRank": "-",
"userTodayJoined": "0"
},
{
"clockInId": "25",
"containsNum": 293796,
"orderBy": "644",
"tagDesc": "康康你的自拍照,有机会上首页推荐哦!",
"tagId": 310,
"tagName": "就是爱自拍",
"thumb": "https://du.hupucdn.com/Fn3LjHqtx1mR1TsJhhIuMzklPzC0",
"userContinuousNum": "0",
"userHistoryNum": 0,
"userJoined": "0",
"userRank": "-",
"userTodayJoined": "0"
},
{
"clockInId": "147",
"containsNum": 220616,
"orderBy": "643",
"tagDesc": "让我康康仙女都在买啥(⊙_⊙)",
"tagId": 1595,
"tagName": "美妆种草",
"thumb": "https://du.hupucdn.com/FpeNLkzEWUeckefHu0gxqFKPqvab",
"userContinuousNum": "0",
"userHistoryNum": 0,
"userJoined": "0",
"userRank": "-",
"