Udostępnij za pośrednictwem


Klasa ExtractionRule

Służy do definiowania reguł dla uzyskiwania danych z odpowiedź z sieci Web, który jest generowany przez test wydajności sieci Web klasy podstawowej.

Hierarchia dziedziczenia

Object
  Microsoft.VisualStudio.TestTools.WebTesting.ExtractionRule
    Więcej...

Przestrzeń nazw:  Microsoft.VisualStudio.TestTools.WebTesting
Zestaw:  Microsoft.VisualStudio.QualityTools.WebTestFramework (w Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)

Składnia

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

Typ ExtractionRule uwidacznia następujące elementy członkowskie.

Konstruktorzy

  Nazwa Opis
Metoda chroniona ExtractionRule Inicjuje nowe wystąpienie klasy ExtractionRule.

Początek

Właściwości

  Nazwa Opis
Właściwość publiczna ContextParameterName Pobiera lub ustawia nazwę kontekstu wyodrębnione właściwości.
Właściwość publiczna RuleDescription Nieaktualne. Ta metoda jest już używana.Użycie DisplayNameAttribute w klasie, aby ustawić opis dla tej reguły.
Właściwość publiczna RuleName Nieaktualne. Ta metoda jest już używana.Użycie DisplayNameAttribute w klasie, aby ustawić nazwę wyświetlaną dla tej reguły.

Początek

Metody

  Nazwa Opis
Metoda publiczna Equals Determines whether the specified object is equal to the current object. (Odziedziczone z Object).
Metoda publiczna Extract Po zastąpieniu w klasie pochodnej, ta metoda wyodrębnia informacje z HtmlDocument i umieszcza go w WebTestContext.
Metoda chroniona Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Odziedziczone z Object).
Metoda publiczna GetHashCode Serves as the default hash function. (Odziedziczone z Object).
Metoda publiczna GetType Gets the Type of the current instance. (Odziedziczone z Object).
Metoda chroniona MemberwiseClone Creates a shallow copy of the current Object. (Odziedziczone z Object).
Metoda publiczna ToString Returns a string that represents the current object. (Odziedziczone z Object).

Początek

Uwagi

ExtractionRule Klasy musi być dziedziczone przez wszelkie reguły wyodrębniania czy jest napisane przez użytkownika lub wbudowane.Ekstrakcja reguł, które są skojarzone z definicją żądania są uruchamiane po odpowiedź została odebrana, a wyniki ekstrakcji są dodawane do WebTestContext.

Uwagi dotyczące dziedziczenia

Kiedy dziedziczą z ExtractionRule, należy zmienić następujące elementy: Extract, RuleDescription, i RuleName.

Przykłady

Następujące reguły niestandardowe ekstrakcji wyodrębnia pola wyboru z HtmlDocument i umieszcza stan pola wyboru znalezionego w kontekście.

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

Bezpieczeństwo wątku

Wszystkie publiczne static (Shared w języku Visual Basic) elementy członkowskie tego typu są bezpieczne dla wątków. Wystąpienia elementów członkowskich nie dają gwarancji bezpieczeństwa wątków.

Zobacz też

Informacje

Przestrzeń nazw Microsoft.VisualStudio.TestTools.WebTesting

Inne zasoby

Kodowanie niestandardowej reguły wyodrębniania dla testów wydajności sieci Web

[wycofane] Porady: dodawanie reguły wyodrębniania do testów wydajności WWW

Hierarchia dziedziczenia

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