Web Performance Test: 如果使用Plugin过滤Dependent Request
前言
由于Visual Studio的Web Performance Test是基于XML脚本的,留给用户修改测试行为的自由度并不高。因此,Plugin机制就对于实现很多客户化的配置显得很重要。
问题描述
当使用Web Performance Test进行测试,发送一个Request并收到Response后,框架会自动帮你解析Dependent Request,比如 -- css,javascript,图片等,然后再去请求这些资源。你需要做的是把 Parse Dependent Request属性设置为True:

这个功能很好,可以帮助你更真实地模拟实际的压力,但是由于对Dependent Request的解析是运行时动态解析的,因此从脚本中你是无法指定哪些Dependent Request并不想去请求。而我们不想去请求的原因可能是:
1,有的资源可能放在第三方的服务器上,比如用到了第三方的图片服务,但是你只想测试自己的服务。
2,有些第三方资源可能访问有问题,将导致测试用例失败。比如我遇到的是页面包含了google提供的jquery脚本,请求有时会抛出socket异常,测试用例就直接失败了。
3,第三种情况我猜测可能存在--即某些第三方资源对同一IP的访问有限制,可能导致资源有时请求成功,有时失败。
解决方案
我们通过Plugin来过滤掉我们不喜欢的Dependent Requests,
public class RequestFilterWebTestPlugin : WebTestPlugin
{
public override void PreRequest(object sender, PreRequestEventArgs e)
{
int count = e.Request.DependentRequests.Count;
for (int i = count - 1; i >= 0; i--)
{
if (e.Request.DependentRequests[i].Url.ToLower().Contains("****.com"))
{
continue;
}
else
{
e.Request.DependentRequests.RemoveAt(i);
}
}
} public override void PostRequest(object sender, PostRequestEventArgs e)
{
int count = e.Request.DependentRequests.Count;
for (int i = count - 1; i >= 0; i--)
{
if (e.Request.DependentRequests[i].Url.ToLower().Contains("****.com"))
{
continue;
}
else
{
e.Request.DependentRequests.RemoveAt(i);
}
}
}
}
以上代码很简单,继承WebTestPlugin, 在PreRequest和PostRequest方法中,移除掉e.Request.DependentRequests中不需要的Request。我们这里很简单,只是移除掉所有非****.com域的Dependent Requests,读者也可以自己实现更复杂的功能-- 黑名单、白名单、配置在配置文件中等等。
Binhua Liu原创,写于2013/9/29。
Web Performance Test: 如果使用Plugin过滤Dependent Request的更多相关文章
- Web Performance Test : 为Request的Post参数名添加XPath支持
问题描述 本文的标题看起来有些含糊其辞,这里我需要把问题阐述得更加清楚.这是我们使用VSTS进行Web Performance Test时,Asp.net造成的特定问题(也许其他开发工具或插件也会造成 ...
- Visual Studio的Web Performance Test提取规则详解(3)
总结 Visual Studio的Web Performance Test是基于HTTP协议层的,它不依赖于浏览器,通过直接接收,发送HTTP包来和Web服务器交互.Web Performance T ...
- Visual Studio的Web Performance Test提取规则详解(2)
总结 Visual Studio的Web Performance Test是基于HTTP协议层的,它不依赖于浏览器,通过直接接收,发送HTTP包来和Web服务器交互.Web Performance T ...
- Visual Studio的Web Performance Test提取规则详解(1)
总结 Visual Studio的Web Performance Test是基于HTTP协议层的,它不依赖于浏览器,通过直接接收,发送HTTP包来和Web服务器交互.Web Performance T ...
- C# .net mvc web api 返回 json 内容,过滤值为null的属性
在WebApiConfig.Register 中增加一段 #region 过滤值为null的属性 //json 序列化设置 GlobalConfiguration.Configuration.Form ...
- Web Performance and Load Test Project错误集
当我们创建Web Performance and Load Test Project时,经常会遇到下面这些问题: 1. 当点击Add Recording时, 左边的record tree没有出现: 解 ...
- 前端使用AngularJS的$resource,后端ASP.NET Web API,实现分页、过滤
在上一篇中实现了增删改查,本篇实现分页和过滤. 本系列包括: 1.前端使用AngularJS的$resource,后端ASP.NET Web API,实现增删改查2.前端使用AngularJS的$re ...
- 13 Reasons Why You Should Pay Attention to Mobile Web Performance
Mobile is no longer on the sidelines. If you’re not already thinking mobile first, you should at lea ...
- Learning Web Performance with MDN
Learning Web Performance with MDN Web 性能是客观的衡量标准,是加载时间和运行时的感知用户体验. https://developer.mozilla.org/en- ...
随机推荐
- iPhone的設置——FaceTime頁面
這裏說的是蘋果的Hand off功能,系統升級後,蘋果的多部設備可以更好的“連續互通”.有電話打進來,iPhone.iPad和Mac都能收到,用戶可以任意選擇一款設備接電 話.同樣,iMessage也 ...
- 使用花生壳6.5客户端FTP设置
1.打开FTP客户端—选项—参数选择 2.设置为主动模式(PORT) 3.连接FTP服务器 4.FTP连接成功
- repeater单双行颜色不同,gridview repeater DataList 鼠标经过改变背景颜色
1.gridview 双击GridView的OnRowDataBound事件: 在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示: protected void ...
- copy module
需求,当有一个实例a,我们需要一个新的实例b,b同a拥有相同的属性. 当我们使用a=b的模式的时候是一个赋值的过程.a和b指向同一个实例.b的任何操作都同a一样. 在这个使用需要使用copy模块.根据 ...
- json解析jackson ,Gson,等知识总结
相关资料链接: Java构造和解析json数据的两种方法详解 java解析json Android网络之数据分析---使用Google Gson 解析Json数据 使用jackson在java中处理j ...
- 解决windows 10关机自动重启的问题
自从windows 10推出来没多久,就给台式机安装了.可是,有点悲剧的是:每次关机,都会自动重启(restart). 之后也在网上找了一些解决方式,但还是没用.前天通过搜索”Windows 10 c ...
- The type XXX cannot be resolved. It is indirectly referenced from required .class files错误.....
遇到The type XXX cannot be resolved. It is indirectly referenced from required .class files错误.....,查找的 ...
- C++之路进阶——bzoj2879(美食节)
2879: [Noi2012]美食节 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1304 Solved: 702[Submit][Status] ...
- java权限修饰符
- ligerui_ligerTree_007_ligerTree动态加载节点
ligerui:ligerTree:动态加载节点: 源码地址:http://download.csdn.net/detail/poiuy1991719/8571255 效果图: 代码:json.txt ...