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- ...
随机推荐
- C++对析构函数的误解(转)
C++析构前言 析构函数在什么时候会自动被调用,在什么时候需要手动来调用,真不好意思说偶学过C++…今日特此拨乱反正. C++析构误解正文 对象在构造的时候系统会分配内存资源,对一些数据成员进行初始化 ...
- SpringMVC表单标签简介
在使用SpringMVC的时候我们可以使用Spring封装的一系列表单标签,这些标签都可以访问到ModelMap中的内容.下面将对这些标签一一介绍. 在正式介绍SpringMVC的表单标签之前,我们需 ...
- 如何查看JSP和Servlet版本
我们在java web开发的过程中,有时在资料上可能会提到环境所要支持的JSP,Servlet版本.如果版本低就可能出现测试错误. 方法:打开tomcat的common/lib 目录下,有两个JAR文 ...
- php课程---简单的分页练习
在写代码时,我们可以用类来使代码更加方便简洁,下面是一个简单的查询分页练习 源代码: <html> <head> <style type="text/css&q ...
- 【iCore3 双核心板】例程十七:USB_MSC实验——读/写U盘(大容量存储器)
实验指导书及代码包下载: http://pan.baidu.com/s/1qXt1L0o iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- mvn打包idea项目
首先 通过cmd进入docs 然后用cd命令进入项目文件夹所在路径 然后输入mvn -Dmaven.test.skip=true package//-Dmaven.test.skip=true跳过测试
- ThinkPHP 3.2.3 关联模型的使用
关于关联模型 ThinkPHP 3.2.3 的关联模型(手册地址)一般处理关联数据表的 CURD 操作,例如关联读取.关联写入.关联删除等. 实例 博客管理模块关于博客有 4 张数据表:博客表 crm ...
- Tomcat负载均衡配置-未完成
集群技术是目前非常流行的提高系统服务能力与高可靠性( HA- High Availability )的手段,通过把多个独立的服务器组成一个集群可以实现失效无缝转移.也就是说当有某一台集群中的服务器当机 ...
- LeetCode Shortest Distance from All Buildings
原题链接在这里:https://leetcode.com/problems/shortest-distance-from-all-buildings/ 题目: You want to build a ...
- LeetCode Missing Ranges
原题链接在这里:https://leetcode.com/problems/missing-ranges/ 题目: Given a sorted integer array where the ran ...