Sdílet prostřednictvím


ExtractionRule – třída

Základní třídy slouží k definování pravidel pro získání dat z webové odpovědi je generován test výkonnosti webové.

Hierarchie dědičnosti

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.ExtractHiddenFields
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractHttpHeader
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractRegularExpression
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractText

Obor názvů:  Microsoft.VisualStudio.TestTools.WebTesting
Sestavení:  Microsoft.VisualStudio.QualityTools.WebTestFramework (v Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)

Syntaxe

'Deklarace
Public MustInherit Class ExtractionRule
public abstract class ExtractionRule
public ref class ExtractionRule abstract
[<AbstractClass>]
type ExtractionRule =  class end
public abstract class ExtractionRule

Typ ExtractionRule zveřejňuje následující členy.

Konstruktory

  Název Popis
Chráněná metoda ExtractionRule Inicializuje novou instanci ExtractionRule Třída

Na začátek

Vlastnosti

  Název Popis
Veřejná vlastnost ContextParameterName Získá nebo nastaví název kontextu extrahované vlastnost.
Veřejná vlastnost RuleDescription Zastaralé. Tato metoda se již používá.Použití DisplayNameAttribute ve třídě nastavení popisu pravidla.
Veřejná vlastnost RuleName Zastaralé. Tato metoda se již používá.Použití DisplayNameAttribute ve třídě nastavit zobrazovaný název pro toto pravidlo.

Na začátek

Metody

  Název Popis
Veřejná metoda Equals Určuje, zda zadaná Object se rovná aktuální Object. (Zděděno z Object.)
Veřejná metoda Extract Při přepsání v odvozené třídě tuto metodu extrahuje informace z HtmlDocument a umístí jej do WebTestContext.
Chráněná metoda Finalize Umožňuje zkuste uvolnit prostředky a provádět další operace vyčištění před je převzaty systémem pro uvolnění objektu. (Zděděno z Object.)
Veřejná metoda GetHashCode Slouží jako funkce hash určitého typu. (Zděděno z Object.)
Veřejná metoda GetType Získává Type aktuální instance. (Zděděno z Object.)
Chráněná metoda MemberwiseClone Vytvoří kopii aktuální Object. (Zděděno z Object.)
Veřejná metoda ToString Vrátí řetězec, který představuje aktuální objekt. (Zděděno z Object.)

Na začátek

Poznámky

ExtractionRule Třídy musí být zděděna jakékoli pravidlo extrakce zda je uživatel zapsán nebo vestavěné. Extrakce pravidla přidružené žádosti definice jsou spuštěny po obdržela odpověď a extrakce výsledky budou přidány do WebTestContext.

Poznámky pro dědice

Když dědíte z třídy ExtractionRule, je nutné přepsat následující členy: Extract, RuleDescription a RuleName.

Příklady

Následující vlastní extrakce pravidlo extrahuje z políček HtmlDocument a umístí stav nalezených políčka do kontextu.

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.";
        }
    }
}
Imports System
Imports Microsoft.VisualStudio.TestTools.WebTesting

Namespace ClassLibrary2
    Public Class ExtractCheckBoxes
        Inherits ExtractionRule

        Private myContextParameter As String = "ExtractCBoxParam"
        Private isChecked As Boolean = True

        Public Overrides Property ContextParameterName() As String
            Get
                Return myContextParameter
            End Get
            Set(ByVal value As String)
                If (value <> String.Empty) Then
                    myContextParameter = value
                End If
            End Set
        End Property

        Public Property FindCheckedBoxes() As Boolean
            Get
                Return isChecked
            End Get
            Set(ByVal value As Boolean)
                isChecked = value
            End Set
        End Property

        Public Overrides ReadOnly Property RuleName() As String
            Get
                Return "Extract Check Boxes"
            End Get
        End Property

        Public Overrides ReadOnly Property RuleDescription() As String
            Get
                Return "Extract check boxes based on whether they are" + _
                    " checked or not."
            End Get
        End Property

        Public Overrides Sub Extract(ByVal sender As Object, ByVal e As ExtractionEventArgs)
            e.Success = False
            If Not e.Response.HtmlDocument Is Nothing Then
                ' Gets all input tags
                Dim tag As HtmlTag
                For Each tag In e.Response.HtmlDocument.GetFilteredHtmlTags(New String() {"input"})
                    ' Verify if current tag is a checkbox
                    If tag.GetAttributeValueAsString("type") = "checkbox" Then
                        ' Is the check box checked
                        If tag.GetAttributeValueAsString("checked") = "CHECKED" Then
                            ' Add checked checkbox to context
                            If isChecked = True Then
                                e.WebTest.Context.Add(myContextParameter + "_" + _
                                tag.GetAttributeValueAsString("id"), "Is Checked")
                                e.Success = True
                            End If
                        Else ' The check box is not checked
                            If isChecked = False Then
                                ' Add non-checked boxes to context
                                e.WebTest.Context.Add(myContextParameter + "_" + _
                                tag.GetAttributeValueAsString("id"), "Is Not Checked")
                                e.Success = True
                            End If
                        End If
                    End If
                Next
            End If
            If e.Success = True Then
                e.Message = "Extracted check boxes."
            Else
                e.Message = "No check boxes extracted."
            End If
        End Sub
    End Class
End Namespace

Zabezpečení podprocesu

Všechny veřejné členy static (Shared v jazyce Visual Basic) tohoto typu jsou zabezpečeny pro používání podprocesů. Zabezpečení sdílených členů pro používání podprocesů není zaručeno.

Viz také

Odkaz

Microsoft.VisualStudio.TestTools.WebTesting – obor názvů

Další zdroje

How to: Create a Custom Extraction Rule

How to: Add an Extraction Rule to a Web Test