Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ExtractionRule Class

 

Base class used to define rules for obtaining data from a Web response that is generated by a Web performance test.

Namespace:   Microsoft.VisualStudio.TestTools.WebTesting
Assembly:  Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)

System.Object
  Microsoft.VisualStudio.TestTools.WebTesting.ExtractionRule
    Microsoft.VisualStudio.TestTools.WebTesting.ExtractHtmlSelectTag
    Microsoft.VisualStudio.TestTools.WebTesting.ExtractHtmlTagInnerText
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractAttributeValue
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractFormField
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractGuids
    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.Rules.SharePointExtractFormField2
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.SharePointExtractListViewWebPartScriptValues
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.SharePointExtractSelectFormField
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.SharePointExtractViaKeyString
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.SharePointFindCalendarDates
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.SharePointFindCalendarItems
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.SharePointFindDocumentItems
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.SharePointFindHrefs
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.SharePointFindListItems
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.SharePointFindWorkFlowInstances

public abstract class ExtractionRule

NameDescription
System_CAPS_protmethodExtractionRule()

Initializes a new instance of the ExtractionRule class.

NameDescription
System_CAPS_pubpropertyContextParameterName

Gets or sets the context name of the extracted property.

System_CAPS_pubpropertyRuleDescription

Obsolete.This method is no longer used. Use the DisplayNameAttribute on the class to set a description for this rule.

System_CAPS_pubpropertyRuleName

Obsolete.This method is no longer used. Use the DisplayNameAttribute on the class to set a display name for this rule.

NameDescription
System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_pubmethodExtract(Object, ExtractionEventArgs)

When overridden in a derived class, this method extracts information from a HtmlDocument and places it into the WebTestContext.

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodToString()

(Inherited from Object.)

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.

Legacy Code Example

The following custom extraction rule extracts check boxes from the HtmlDocument and places the status of the found check boxes 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 check boxes 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 check boxes.";
            else
                e.Message = "No check boxes extracted.";
        }
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: