Extraction/validation Rule Code  
Author Message
fodnick96





PostPosted: Visual Studio Team System - Testing, Extraction/validation Rule Code Top

Is there anyway we can get coded versions of the built in extractio/validation rules I am writing some custom extraction rules and mine are only slight changes to the build in ones so it would nice to not have to write all of the code. VB code would be cool, but C# is fine now that I found a working convert. http://www.hide-link.com/ !!

~Todd


Visual Studio Team System43  
 
 
ChrisPat MSFT





PostPosted: Visual Studio Team System - Testing, Extraction/validation Rule Code Top

I don't think we are going to release the source for those rules but there are some samples on the web. But the code is all managed and not obfuscated so if you are resourceful you could probably figure out how they work.

 
 
fodnick96





PostPosted: Visual Studio Team System - Testing, Extraction/validation Rule Code Top

could u then provide an example in VB to remove text from an html response that starts with "id=" and ends with ","

~Todd

 
 
ChrisPat MSFT





PostPosted: Visual Studio Team System - Testing, Extraction/validation Rule Code Top

See my answer in the following post http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=509966&SiteID=1

 
 
fodnick96





PostPosted: Visual Studio Team System - Testing, Extraction/validation Rule Code Top

The built in extract text is not working as I hoped. There is a bug such that it fails even if the required value is set to false. http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=198822&SiteID=1
I need to write a custom one, but I was unsure of how to do this easily.  This was more of a coding block than anything. I was thinking regular expressions. Any help would be great appreciated.

~Todd

 
 
ChrisPat MSFT





PostPosted: Visual Studio Team System - Testing, Extraction/validation Rule Code Top

you can find some detailed information about creating a custom extraction rule on the following site http://blogs.msnd.com/joshch as far as parsing out your text goes:

Here is an expample of looking for a tag with a specific attribute. Then grabbing the value from one of the attributes and parsing it to get a specific part of te string. The tag in question will look like the following

<a id="Categories_repCategories_ctl01_lnkCategory" href="Products.aspx page=0&amp;categoryId=BIRDS">Birds</a>

and the code to get the category id out of it looks like this:

  public class ExtractRandomCategory : ExtractionRule
  {
    public override void Extract(object sender, ExtractionEventArgs e)
    {
      List linkTags = new List();
      e.Success = false;
      if (e.Response.IsHtml)
      {
        foreach (HtmlTag tag in e.Response.HtmlDocument.GetFilteredHtmlTags( "a" ))
        {
          if (tag.GetAttributeValueAsString("id").StartsWith("Categories"))
          {
            linkTags.Add(tag);
          }
        }
      }
                                                                          
      Random rand = new Random();
      int linkIndex = rand.Next(linkTags.Count);

      HtmlTag linkTag = linkTags[linkIndex];
      string linkValue = linkTag.GetAttributeValueAsString("href");
      string categoryId;
      string categoryIdParamName = "categoryId=";
      if (linkValue.IndexOf(categoryIdParamName) != -1)
      {
        categoryId = linkValue.Substring((linkValue.IndexOf(categoryIdParamName) + categoryIdParamName.Length));
        e.WebTest.Context.Add(this.ContextParameterName, categoryId);
        e.Success = true;
      }
      else
      {
        e.Success = false;
      }
                                                                                                             
      
      return;

    }

    public override string RuleName
    {
      get { return "Extract Ramdom Category Id"; }
    }
  }