Fiddler如何模拟弱网环境进行测试

一、安卓手机使用fiddler模拟弱网环境

1.安卓手机连接代理

2.模拟弱网环境

打开Fiddler,Rules->Performance->勾选 Simulate Modem Speeds

3.修改fiddler脚本

首先点击Rules—>Cutomize Rules打开CustomRules.js 文档

Ctrl+F组合键调出搜索对话框,在文件中搜索关键字,m_SimulateModem

让我们来分析一下这几行代码:

  • 首先来判断m_SimulateModem是否为true,也就是是否设置了弱网模式。

  • 如果为弱网模式。则分析代码

  • oSession[“request-trickle-delay”] = “300”; 注释的也很明白,Delay sends by 300ms per KB uploaded

3.可修改send 和receive的速度值(根据实际需要~~) 
例如下面的配置: 
上行速度:send 3000ms per KB 
下行速度:receive 1500ms per KB


        if (m_SimulateModem) {
            // Delay sends by 3ms per KB uploaded.
            oSession["request-trickle-delay"] = "3000"; 
            // Delay receives by 1ms per KB downloaded.
            oSession["response-trickle-delay"] = "1500"; 
        }

修改完脚本后,保存修改 ,然后再进入Rules->Performance->勾选Simulate Modem Speeds ,此时代理手机的弱网环境就已生效了,如果不用了取消勾选Simulate Modem Speeds 即可

注意:此时电脑的网络也同样被限制了

二、扩展弱网络规则

可能我们在测试中不会想要一个一直虚弱的网络环境,而是随机强弱的网络,这样比较贴切我们的真是情况,那么我们可以修改上述代码为:

 

static function randInt(min, max) {
    return Math.round(Math.random()*(max-min)+min);
}
if (m_SimulateModem) {
    // Delay sends by 300ms per KB uploaded.
    oSession["request-trickle-delay"] = ""+randInt(1,3000);
    // Delay receives by 150ms per KB downloaded.
    oSession["response-trickle-delay"] = ""+randInt(1,3000);
}

randInt(1,3000)代表1-3000中的一个随机整数,这样就会出现偶尔有延迟偶尔网络又良好的情况

 

posted @ 2018-06-07 12:08  行走的笔尖  阅读(284)  评论(0)    收藏  举报