1

I'm load testing a web page using visual studio load testing tool, but I have problems displaying results. The problem is cookieless session. Everytime new user comes to a page, page URLL changes and I'm not able to calculate average page response time. What can be done about it?

Sergej Andrejev
  • 9,091
  • 11
  • 71
  • 108

1 Answers1

0

We moved the cookie to the querystring.

Before that I wrote a case insensitive url validation event handler that ignores the session component of the Url. The one below only removes case sensitivity.

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;
                }
            }
        }
    }
}

Called by

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;

}

Now all I need to do is add

    //add case insensitive url validation for all requests
    urlValidationRuleEventHandler = common.AddUrlValidationEventHandler(this.Context, this);

into a web test to get case insensitive calling. Be aware that this code contains the following innappropriate line

string fred = "There is a problem";
Nat
  • 14,175
  • 5
  • 41
  • 64
  • To my shame I never really understood how validating request can help me calculate common statistics on a request. I would appreciate if you try to explain it to me once more. Now here is my story in the end I figured out that I can just put any request in a transaction and have statistics on just that transaction alone. This doesn't require any coding at all and looks like is flexible enough to support most of use cases. – Sergej Andrejev May 31 '10 at 13:01
  • Sorry, that is my bad. You can use the validator to extract the session from the URL and that way all the Url's will compare correctly. – Nat Jun 14 '10 at 02:59
  • The best bet is to move the session into the querystring, removing the need for the custom validator. – Nat Jun 14 '10 at 03:00