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- ...
随机推荐
- $.getJSON JSONP的新坑
神坑1:返回的内容必须是正规的json数据.如 { "firstName": "Bill", "lastName": "Gates ...
- Bootstrap css背景图片的设置
一. 网页中添加图片的方式有两种 一种是:通过<img>标签直接插入到html中 另一种是:通过css背景属性添加 居中方法:水平居中的text-align:center 和 margin ...
- SQL Server 存储过程(转)
Transact-SQL中的存储过程,非常类似于Java语言中的方法,它可以重复调用.当存储过程执行一次后,可以将语句缓存中,这样下次执行的时候直接使用缓存中的语句.这样就可以提高存储过程的性能. Ø ...
- 使用MyBatis Generator生成DAO
虽然MyBatis很方便,但是想要手写全部的mapper还是很累人的,好在MyBatis官方推出了自动化工具,可以根据数据库和定义好的配置直接生成DAO层及以下的全部代码,非常方便. 需要注意的是,虽 ...
- junit测试框架
import junit.framework.Assert; import org.junit.After; import org.junit.Before; import org.junit.Tes ...
- Empire C:游戏篇(1)
随机生成1-6的数字,我们来猜是几 猜小了就提示数字小了,请再猜 猜大了就提示数字大了,请再猜 猜对了就提示恭喜,并提示是否继续再玩 ///riddle ///Author:JA //2015-1-2 ...
- embedded tomcat context.xml
在网络下载相关的embedded tomcat jar.也可直接在maven中检索. 在main方法中,输入以下代码: //新建tomcat实例 Tomcat tomcat = new Tomcat( ...
- 将类型(int,string,…)转换为 T 类型
方法定义: private static T GetValueByKey<T>(string key) where T : IConvertible { T localVal=defaul ...
- 采用CSS3的动态元素(动画)设计div块的层级式展现
此练习作品是为学习HTML5+CSS3而设计的(如有不好请大家批评指教~~~). 操作:当页面加载时,点击网页中的绿色块(一层),则有其他几块(二层)从其中央出现并向外延伸并旋转,点击这几块中任意一个 ...
- FlipView 索引为0 WP8.1
如果使用FlipView时,出现别的页面切换到含有FlipView的页面时(缓存此页面/MainPage),点击或者滑动FlipView,Flipview自动索引到0 的问题解决办法 1.对Flipv ...