Aracılığıyla paylaş


Web Performans Testi için Özel bir Ayıklama Kuralı Nasıl Oluşturulur

Kendi ayıklama kurallarınızı oluşturabilirsiniz.Bunu yapmak için, bir ayıklama kuralı sınıfından kendi kurallarınızı türetin.Çıkarma kuralları ExtractionRule temel sınıfından türetilir.

Visual Studio Ultimate bazı önceden tanımlanmış ayıklama kuralları sağlar.Daha fazla bilgi için bkz. Web Başarım Testlerinde Doğrulama ve Ayıklama Kurallarını Kullanma.

[!NOT]

Ayrıca, özel doğrulama kuralları oluşturabilirsiniz.Daha fazla bilgi için bkz. Yükleme ve Web Performansı Testleri için Özel Eklentiler Oluşturma ve Kullanma.

Gereksinimler

  • Visual Studio Ultimate

Özel ayıklama kuralı oluşturma

  1. Web performans testi içeren bir Test Projesi açın.

  2. (İsteğe bağlı) Ayıklama kuralınızı saklayacağınız ayrı bir Sınıf kitaplığı projesi oluşturun.

    Önemli notÖnemli

    Testlerinizin içinde olduğu aynı proje içinde bir sınıf oluşturabilirsiniz.Ancak, kuralı yeniden kullanmak istiyorsanız, kuralınızı saklayacağınız ayrı br Sınıf kitaplığı projesi oluşturmanız daha iyi olur.Ayrı bir proje oluşturursanız, bu yordamdaki isteğe bağlı adımları tamamlamanız gerekir.

  3. (İsteğe bağlı) Sınıf kitaplığı projesinde, Microsoft.VisualStudio.QualityTools.WebTestFramework dll dosyasına bir başvuru ekleyin.

  4. ExtractionRule sınıfından türetilen sınıfı oluşturun.Extract ve RuleName üyelerini uygulayın.

  5. (İsteğe bağlı) Yeni sınıf kitaplığı projesi derleyin.

  6. (İsteğe bağlı) Test Projesinde, özel ayıklama kuralı içeren Sınıf kitaplığı projesine başvuru ekleyin.

  7. Test Projesinde Web Başarım Testi Düzenleyicisi'nden bir Web başarım testi açın.

  8. Özelleştirilmiş bir ayıklama kuralı eklemek için, Web başarım testi isteğine sap tıklayın ve Ayıklama Kuralı Ekle öğesini seçin.

    Ayıklama Kuralı Ekle iletişim kutusu görünür.Kural seç listesinde, önceden tanımlanmış doğrulama kuralları ile birlikte, özel doğrulama kuralınızı görürsünüz.Özel ayıklama kural seçip ardından Tamam.

  9. Web performans testinizi çalıştırın.

Örnek

Aşağıdaki kod bir özel ayıklama kuralı uygulamasını gösterir.Bu çıkarma kurala, belirtilen giriş alanı için değer ayıklar.Bu örneği, kendi özel ayıklama kurallarınız için bir başlangıç noktası olarak kullanın.

using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Globalization;

namespace ClassLibrary2
{
    //-------------------------------------------------------------------------
    // This class creates a custom extraction rule named "Custom Extract Input"
    // The user of the rule specifies the name of an input field, and the
    // rule attempts to extract the value of that input field.
    //-------------------------------------------------------------------------
    public class CustomExtractInput : ExtractionRule
    {
        /// Specify a name for use in the user interface.
        /// The user sees this name in the Add Extraction dialog box.
        //---------------------------------------------------------------------
        public override string RuleName
        {
            get { return "Custom Extract Input"; }
        }

        /// Specify a description for use in the user interface.
        /// The user sees this description in the Add Extraction dialog box.
        //---------------------------------------------------------------------
        public override string RuleDescription
        {
            get { return "Extracts the value from a specified input field"; }
        }

        // The name of the desired input field
        private string NameValue;
        public string Name
        {
            get { return NameValue; }
            set { NameValue = value; }
        }

        // The Extract method.  The parameter e contains the web performance test context.
        //---------------------------------------------------------------------
        public override void Extract(object sender, ExtractionEventArgs e)
        {
            if (e.Response.HtmlDocument != null)
            {
                foreach (HtmlTag tag in e.Response.HtmlDocument.GetFilteredHtmlTags(new string[] { "input" }))
                {
                    if (String.Equals(tag.GetAttributeValueAsString("name"), Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        string formFieldValue = tag.GetAttributeValueAsString("value");
                        if (formFieldValue == null)
                        {
                            formFieldValue = String.Empty;
                        }

                        // add the extracted value to the web performance test context
                        e.WebTest.Context.Add(this.ContextParameterName, formFieldValue);
                        e.Success = true;
                        return;
                    }
                }
            }
            // If the extraction fails, set the error text that the user sees
            e.Success = false;
            e.Message = String.Format(CultureInfo.CurrentCulture, "Not Found: {0}", Name);
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports Microsoft.VisualStudio.TestTools.WebTesting
Imports System.Globalization

Namespace ClassLibrary2

    '-------------------------------------------------------------------------
    ' This class creates a custom extraction rule named "Custom Extract Input"
    ' The user of the rule specifies the name of an input field, and the
    ' rule attempts to extract the value of that input field.
    '-------------------------------------------------------------------------
    Public Class CustomExtractInput
        Inherits ExtractionRule

        ' Specify a name for use in the user interface.
        ' The user sees this name in the Add Extraction dialog box.
        '---------------------------------------------------------------------
        Public Overrides ReadOnly Property RuleName() As String
            Get
                Return "Custom Extract Input"
            End Get
        End Property

        ' Specify a description for use in the user interface.
        ' The user sees this description in the Add Extraction dialog box.
        '---------------------------------------------------------------------
        Public Overrides ReadOnly Property RuleDescription() As String
            Get
                Return "Extracts the value from a specified input field"
            End Get
        End Property

        ' The name of the desired input field
        Private NameValue As String
        Public Property Name() As String
            Get
                Return NameValue
            End Get
            Set(ByVal value As String)
                NameValue = value
            End Set
        End Property

        ' The Extract method.  The parameter e contains the web performance test context.
        '---------------------------------------------------------------------
        Public Overrides Sub Extract(ByVal sender As Object, ByVal e As ExtractionEventArgs)

            If Not e.Response.HtmlDocument Is Nothing Then

                For Each tag As HtmlTag In e.Response.HtmlDocument.GetFilteredHtmlTags(New String() {"input"})

                    If String.Equals(tag.GetAttributeValueAsString("name"), Name, StringComparison.InvariantCultureIgnoreCase) Then

                        Dim formFieldValue As String = tag.GetAttributeValueAsString("value")
                        If formFieldValue Is Nothing Then

                            formFieldValue = String.Empty
                        End If

                        ' add the extracted value to the web performance test context
                        e.WebTest.Context.Add(Me.ContextParameterName, formFieldValue)
                        e.Success = True
                        Return
                    End If
                Next
            End If
            ' If the extraction fails, set the error text that the user sees
            e.Success = False
            e.Message = String.Format(CultureInfo.CurrentCulture, "Not Found: {0}", Name)
        End Sub
    End Class
end namespace

Extract yöntemi bir ayıklama kuralının temel işlevselliğini içerir.Önceki örnekteki Extract yöntemi bu ayıklama kuralının kapsadığı istek tarafından oluşturulan yanıtın sağladığı bir ExtractionEventArgs öğesi alır.Yanıt, tüm etiketleri bünyesinde kapsayan bir HtmlDocument öğesini içerir.Giriş etiketleri HtmlDocument öğesinden filtrelenerek çıkarılır.Her giriş etiketi değeri Ad özelliği için kullanıcı tarafından sağlanan değere eşdeğer olan ad adı verilen bir öznitelik ile incelenir.Bu eşleştirme özniteliğini içeren bir etiket bulunursa, bir değer özniteliği varsa, değer özniteliğinin içerdiği değeri çıkarmak için bir deneme yapılır.Varsa, etiketin adı ve değeri çıkarılır ve web performans testi içeriğine eklenir.Ayıklama kuralı geçer.

Ayrıca bkz.

Görevler

Web Performans Testine bir Ayıklama Kuralı Nasıl Eklenir

İzlenecek yol: Web Performans Testine Doğrulama ve Ayıklama Kuralı Ekleme

Web Performans Testi için Özel Doğrulama Kuralı Nasıl Oluşturulur

Başvuru

ExtractionRule

Microsoft.VisualStudio.TestTools.WebTesting.Rules

ExtractAttributeValue

ExtractFormField

ExtractHttpHeader

ExtractRegularExpression

ExtractText

ExtractHiddenFields

Kavramlar

Web Başarım Testlerinde Doğrulama ve Ayıklama Kurallarını Kullanma