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