ExtractionRule Class
Visual Studio 2008
Base class used to define rules for obtaining data from a Web response that is generated by a Web test.
Assembly: Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)
The ExtractionRule class must be inherited by any extraction rule whether it is user-written or built-in. Extraction rules that are associated with the request definition are run after a response has been received, and the results of the extraction are added to the WebTestContext.
Notes to Inheritors:When you inherit from ExtractionRule, you must override the following members: Extract, RuleDescription, and RuleName.
The following custom extraction rule extracts checkboxes from the HtmlDocument and places the status of the found checkboxes into the context.
using System; using Microsoft.VisualStudio.TestTools.WebTesting; namespace ClassLibrary2 { public class ExtractCheckBoxes : ExtractionRule { private string myContextParameter = "ExtractCBoxParam"; private bool isChecked = true; public override string ContextParameterName { get { return myContextParameter; } set { if (value != string.Empty) myContextParameter = value; } } public bool FindCheckedBoxes { get { return isChecked; } set { isChecked = value; } } public override string RuleName { get { return "Extract Check Boxes"; } } public override string RuleDescription { get { return "Extract check boxes based on whether they are" + " checked or not."; } } public override void Extract(object sender, ExtractionEventArgs e) { e.Success = false; if (e.Response.HtmlDocument != null) { // Gets all input tags foreach (HtmlTag tag in e.Response.HtmlDocument .GetFilteredHtmlTags(new string[] { "input" })) { // Verify that current tag is a checkbox if (tag.GetAttributeValueAsString("type") == "checkbox") { // Is the checkbox checked if (tag.GetAttributeValueAsString("checked") == "CHECKED") { // Add checked checkboxes to context if (isChecked) { e.WebTest.Context.Add(myContextParameter + "_" + tag.GetAttributeValueAsString("id"), "Is Checked"); e.Success = true; } } else // The checkbox is not checked { // Add non-checked boxes to context if (!isChecked) { e.WebTest.Context.Add(myContextParameter + "_" + tag.GetAttributeValueAsString("id"), "Is Not Checked"); e.Success = true; } } } } } if (e.Success) e.Message = "Extracted checkboxes."; else e.Message = "No checkboxes extracted."; } } }
System.Object
Microsoft.VisualStudio.TestTools.WebTesting.ExtractionRule
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractAttributeValue
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractFormField
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractHiddenFields
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractHttpHeader
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractRegularExpression
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractText
Microsoft.VisualStudio.TestTools.WebTesting.ExtractionRule
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractAttributeValue
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractFormField
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractHiddenFields
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractHttpHeader
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractRegularExpression
Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractText