共用方式為


ExtractionRule.ContextParameterName 屬性

取得或設定擷取之屬性的內容名稱。

命名空間:  Microsoft.VisualStudio.TestTools.WebTesting
組件:  Microsoft.VisualStudio.QualityTools.WebTestFramework (在 Microsoft.VisualStudio.QualityTools.WebTestFramework.dll 中)

語法

'宣告
<BrowsableAttribute(False)> _
Public Overridable Property ContextParameterName As String
    Get
    Set
[BrowsableAttribute(false)]
public virtual string ContextParameterName { get; set; }
[BrowsableAttribute(false)]
public:
virtual property String^ ContextParameterName {
    String^ get ();
    void set (String^ value);
}
[<BrowsableAttribute(false)>]
abstract ContextParameterName : string with get, set
[<BrowsableAttribute(false)>]
override ContextParameterName : string with get, set
function get ContextParameterName () : String
function set ContextParameterName (value : String)

屬性值

型別:System.String
擷取之屬性的內容名稱。

備註

在後續要求中,您可使用這個名稱繫結至資料項目。

範例

以下是指派內容名稱給擷取值的 Web 效能測試。

namespace TestProject1
{
    using System;
    using System.Collections.Generic;
    using Microsoft.VisualStudio.TestTools.WebTesting;
    using ClassLibrary2;

    public class MyWebTest : WebTest
    {
        public MyWebTest()
        {
            this.PreAuthenticate = true;
        }

        public override IEnumerator<WebTestRequest> GetRequestEnumerator()
        {
            WebTestRequest request1 = new WebTestRequest("https://localhost/ts");
            ExtractCheckBoxes rule1 = new ExtractCheckBoxes();
            rule1.FindCheckedBoxes = true;
            rule1.ContextParameterName = "CheckedBoxes";
            request1.ExtractValues += new EventHandler
                <ExtractionEventArgs>(rule1.Extract);
            ExtractCheckBoxes rule2 = new ExtractCheckBoxes();
            rule2.FindCheckedBoxes = false;
            rule2.ContextParameterName = "";
            request1.ExtractValues += new EventHandler
                <ExtractionEventArgs>(rule2.Extract);
            yield return request1;
        }
    }
}
Option Strict Off
Option Explicit On

Imports Microsoft.VisualStudio.TestTools.WebTesting
Imports Microsoft.VisualStudio.TestTools.WebTesting.Rules
Imports System
Imports System.Collections.Generic

Namespace MyVBTestProject
    
    Public Class MyCodedWebTest
        Inherits ThreadedWebTest
        
        Public Sub New()
            MyBase.New
            Me.PreAuthenticate = true

            // TODO: specify your proxy below
            Me.Proxy = "myproxy.seattle.corp.northwind.com:80"
        End Sub
        
        Public Overrides Sub Run()
            Dim request1 As WebTestRequest = New WebTestRequest _
                ("https://localhost/MyWebSite")
            request1.ThinkTime = 10
            Dim rule1 As ExtractHiddenFields = New ExtractHiddenFields
            rule1.ContextParameterName = "MyContextParam"
            AddHandler request1.ExtractValues, AddressOf rule1.Extract
            MyBase.Send(request1)

            Dim request2 As WebTestRequest = New WebTestRequest _
                ("https://localhost/MyWebSite/Default.aspx")
            request2.Method = "POST"
            Dim request2Body As FormPostHttpBody = New FormPostHttpBody
            request2Body.FormPostParameters.Add("__VIEWSTATE", _
                "{{$HIDDEN1.__VIEWSTATE}}")
            request2Body.FormPostParameters.Add("Button1", "Button")
            request2Body.FormPostParameters.Add("TextBox1", "Entered text")
            request2.Body = request2Body
            MyBase.Send(request2)
        End Sub
    End Class
End Namespace

.NET Framework 安全性

請參閱

參考

ExtractionRule 類別

Microsoft.VisualStudio.TestTools.WebTesting 命名空間