locked
how to make the check of response urls case-insensitive. RRS feed

  • Question

  • How can I change the rule so that when checking the response URL, the case is ignored

    For eaxample I'm getting this because of the difference in case.

    Response URL Validation The value of the ExpectedResponseUrl property 'http://test-ext-las.itestextranet.com/LAS/LoginMPP.asp' does not equal the actual response URL 'http://test-ext-las.itestextranet.com/las/loginmpp.asp'.  QueryString parameters were ignored.  

    Friday, May 27, 2011 8:38 PM

Answers

  • Hi Brit Tester,

    The built in Validation Rule - Response URL is case sensitive. 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 that I have created below and you should be in business. 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. 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;
          }
        }
      }
    }
    
    

    http://blogs.msdn.com/rogeorge
    Sunday, May 29, 2011 11:26 PM

All replies

  • Hi Brit Tester,

    The built in Validation Rule - Response URL is case sensitive. 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 that I have created below and you should be in business. 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. 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;
          }
        }
      }
    }
    
    

    http://blogs.msdn.com/rogeorge
    Sunday, May 29, 2011 11:26 PM
  • I finally got round to testing this, and there's a slight problem. The code works, but the built in ResponseURL validation rule still runs with the WebTest, and consequently fails the test. For the two urls in my webtest that I need to be case-insensitive, is there any way to remove the built in ResponseURL validation, or alternatively to make the test ignore this validation for these 2 urls? 
    Tuesday, June 14, 2011 3:03 PM
  • Hi Brit Tester,

    Simplest thing would be to replace the built in Response URL Validation (found at the webtest level in the tree hierarchy) with this one and kill two birds with one stone. So, this would become the only one you have and would be at the test level vs. attaching it to individual request level. Hope that makes sense.

    Robert


    http://blogs.msdn.com/rogeorge
    Tuesday, June 14, 2011 11:13 PM
  • One issue I notice with this, is if you have URLs that have query strings attached then the URL is only validated to the query string.  So if that is needed at certain places you need to adjust your URL carefully for validation, this is great though a gave me some coverage for what I needed in part of my Load Test.
    Tuesday, October 2, 2012 6:42 PM