我正在使用visual studio负载测试工具加载测试网页,但是我在显示结果时遇到了问题。问题是无cookie会话。每当新用户访问某个页面时,页面URLL都会更改,我无法计算平均页面响应时间。可以做些什么呢?
答案 0 :(得分:0)
我们将cookie移动到查询字符串。
在此之前,我编写了一个不区分大小写的url验证事件处理程序,它忽略了Url的会话组件。下面的一个只会消除区分大小写。
class QueryLessCaseInsensitiveValidateResponseUrl : ValidateResponseUrl
{
public override void Validate(object sender, ValidationEventArgs e)
{
Uri uri;
string uriString = string.IsNullOrEmpty(e.Request.ExpectedResponseUrl) ? e.Request.Url : e.Request.ExpectedResponseUrl;
if (!Uri.TryCreate(e.Request.Url, UriKind.Absolute, out uri))
{
e.Message = "The request URL could not be parsed";
e.IsValid = false;
}
else
{
Uri uri2;
string leftPart = uri.GetLeftPart(UriPartial.Path);
if (!Uri.TryCreate(uriString, UriKind.Absolute, out uri2))
{
e.Message = "The request URL could not be parsed";
e.IsValid = false;
}
else
{
uriString = uri2.GetLeftPart(UriPartial.Path);
////this removes the query string
//uriString.Substring(0, uriString.Length - uri2.Query.Length);
Uri uritemp = new Uri(uriString);
if (uritemp.Query.Length > 0)
{
string fred = "There is a problem";
}
//changed to ignore case
if (string.Equals(leftPart, uriString, StringComparison.OrdinalIgnoreCase))
{
e.IsValid = true;
}
else
{
e.Message = string.Format("The value of the ExpectedResponseUrl property '{0}' does not equal the actual response URL '{1}'. QueryString parameters were ignored.", new object[] { uriString, leftPart });
e.IsValid = false;
}
}
}
}
}
由
调用public EventHandler<ValidationEventArgs> AddUrlValidationEventHandler(WebTestContext context, WebTest webTest)
{
EventHandler<ValidationEventArgs> urlValidationRuleEventHandler = null;
// Initialize validation rules that apply to all requests in the WebTest
if ((context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.Low))
{
QueryLessCaseInsensitiveValidateResponseUrl validationRule1 = new QueryLessCaseInsensitiveValidateResponseUrl();
urlValidationRuleEventHandler = new EventHandler<ValidationEventArgs>(validationRule1.Validate);
webTest.ValidateResponse += urlValidationRuleEventHandler;
}
return urlValidationRuleEventHandler;
}
现在我需要做的就是添加
//add case insensitive url validation for all requests
urlValidationRuleEventHandler = common.AddUrlValidationEventHandler(this.Context, this);
进入Web测试以获得不区分大小写的调用。 请注意,此代码包含以下不恰当的行
string fred = "There is a problem";