Export (0) Print
Expand All

ExtractionRule Class

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

Object
  Microsoft.VisualStudio.TestTools.WebTesting.ExtractionRule
    More...

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

public abstract class ExtractionRule

The ExtractionRule type exposes the following members.

  NameDescription
Protected methodExtractionRuleInitializes a new instance of the ExtractionRule class.
Top

  NameDescription
Public propertyContextParameterNameGets or sets the context name of the extracted property.
Public propertyRuleDescription Obsolete. This method is no longer used. Use the DisplayNameAttribute on the class to set a description for this rule.
Public propertyRuleName Obsolete. This method is no longer used. Use the DisplayNameAttribute on the class to set a display name for this rule.
Top

  NameDescription
Public methodEqualsDetermines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodExtractWhen overridden in a derived class, this method extracts information from a HtmlDocument and places it into the WebTestContext.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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 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.

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
Show:
© 2014 Microsoft