書接上回, Fiddler插件 在團隊內部試用後,效果很不錯,小夥伴們也提出了不少改進的建議;html
最近一段Fiddler使用的仍較爲頻繁,之前碰到一些特殊測試需求時,老是本身在FiddlerScript中改來改去,略有些不便;android
因而花了點時間,
將一些經常使用的測試功能封裝成了菜單項,作到一鍵切換,方便以後的測試工做ios
如下各菜單,Android和IOS都可使用api
//映射線上Host到灰度等測試環境; 在class中增長以下代碼 RulesString("HostMapping",true) RulesStringValue(0,"灰度1", "10.35.45.84") RulesStringValue(1,"灰度2", "10.35.45.84:8080") RulesStringValue(2,"233.94", "192.168.233.94") RulesStringValue(3,"14.206", "192.168.14.206") RulesStringValue(4,"9.28", "192.168.9.28") public static var m_host: String = null; // 在 OnBeforeRequest 方法中增長以下 if(null != m_host && oSession.HostnameIs("mobile-api2011.elong.com") ){ oSession.host=m_host; }
代碼以下網絡
//替換DeviceID,模擬MVT測試及新用戶 //在class中增長以下代碼 RulesString("ABTest測試",true) RulesStringValue(0,"測試組", "12345678-1234-5678-9012-123456789010") RulesStringValue(1,"對照組", "12345678-1234-5678-9012-123456789011") RulesStringValue(2,"新用戶", "12345678-1234-5678-9012-122211133344") public static var m_deviceid: String = null; // 在 OnBeforeRequest 方法中增長以下 if(null != m_deviceid && oSession.oRequest.headers.Exists("DeviceId") &&oSession.oRequest.headers.Exists("ClientType") ){ oSession.oRequest["DeviceId"] = m_deviceid; }
//經過設置網絡延時,來模擬不一樣的網速場景 //在class中增長以下代碼 ;增長菜單項 RulesString("網速模擬",true) RulesStringValue(0,"Simulate &Modem Speeds", "150") RulesStringValue(1,"Simulate 2G(25KB)", "40") RulesStringValue(2,"Simulate 3G(250KB)", "4") public static var m_networkSpeed: String = null; // 在 OnBeforeRequest 方法中增長以下 if(m_networkSpeed){ //網速模擬測試 oSession["request-trickle-delay"] = (parseInt(m_networkSpeed)*2).ToString(); oSession["response-trickle-delay"] = m_networkSpeed; }
//在class中增長以下代碼 //增長菜單項 public static RulesOption("標記HTTPS", "Other") var m_https: boolean = false; //只展現來自APP的Mapi請求,其它類型所有過濾 public static RulesOption("Only Show Mapi", "Other") var m_OnlyMapi: boolean = false; // 在 OnBeforeRequest 方法中增長以下 //將域名中包含elong的HTTPS請求,標記爲紅色 if ( m_https && oSession.isHTTPS && oSession.fullUrl.indexOf("elong")>0){ oSession["ui-color"] = "red"; } //只展現APP過來的請求,非app請求直接過濾掉 if(m_OnlyMapi && !oSession.oRequest.headers.Exists("DeviceId") && !oSession.oRequest.headers.Exists("ClientType")){ oSession["ui-hide"] = "true"; }
//在class中增長以下代碼便可 public static BindUIColumn("ClientIP", 120) function FillClientIPColumn(oS: Session): String { //oS.oResponse.headers. return oS.clientIP.Split(':')[3]; } public static BindUIColumn("Method", 60) function FillMethodColumn(oS: Session): String { return oS.RequestMethod; }
fiddler官方資料app