Offending the testing gods...

Robert George offers musings on performance testing.

Visual Studio WebTest Validation Rules - Built-in Response URL rule is case sensitive...

Visual Studio WebTest Validation Rules - Built-in Response URL rule is case sensitive...

Rate This
  • Comments 1

 The built in Validation Rule, called Response URL is case sensitive, and this rule is to help validate that a page that was redirected to another page during recording, also honors the same when playing back via a VS WebTest. The problem is that some web apps don’t always respond with urls that are same case as what was recorded, especially if the data used to drive the test might have a virtual user exercise a slightly different code path. So a URL to http://mysite/mypage.aspx is not equivalent to http://mysite/myPage.aspx, well, this may be a bit too restrictive, so the good news is that with Visual Studio we can rely on the extensibility models to get the solution you need. Just replace the built in validation rule with this sample code that I have created below. You can modify this validation rule with additional logic if you desire. Add a class to your project and add the code snippet below, update the namespace if you desire, and be sure you have the using statement for the System.ComponentModel and the TestTools.WebTestingl. Make sure to rebuild the project once so the custom validation rule will show up before you try to add to the .webtest.

 

using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.WebTesting;

namespace TestProject5
{
  [Description("Validates that the response URL after redirects are followed is the same as the recorded response URL. QueryString parameters are ignored. The match will be done on case insensitive basis.")]
  [DisplayName("Response URL Case Insensitive")]
  public class ResponseURLCaseInsensitive : ValidationRule
  {
    public override void Validate(object sender, ValidationEventArgs e)
    {
      //determine if request is a redirect follow and validate the URL accordingly
      if (e.Request.IsRedirectFollow)
      {
        //use to upper to force case insensitive comparision
        if (e.Request.ExpectedResponseUrl.ToUpper() == e.Request.Url.ToUpper())
        {
          e.IsValid = true;
          e.Message = "Response URL successfully matched case insensitive comparison. Expected Value=" + e.Request.ExpectedResponseUrl + " , Actual Value=" + e.Request.Url;
        }
        else
        {
          e.IsValid = false;
          e.Message = "Response URL did NOT match. Expected Value=" + e.Request.ExpectedResponseUrl + " , Actual Value=" + e.Request.Url;
        }
      } //if the request did not redirect, determine if one was expected and fail if true
      else if (!string.IsNullOrEmpty(e.Request.ExpectedResponseUrl))
      {
        e.IsValid = false;
        e.Message = "The expected response redirect did not occur. Expected Response URL=" + e.Request.ExpectedResponseUrl;
      }
    }
  }
}

Leave a Comment
  • Please add 4 and 8 and type the answer here:
  • Post
  • If I want to check the Query String parameters with this can it be done or does the ExpectedURL cut off the validating URL at the first Query String Parameter like it shows up in the log?

Page 1 of 1 (1 items)