共用方式為


WebTestRequest 建構函式 (String)

使用 URL 字串,初始化 WebTestRequest 類別的新執行個體。

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

語法

'宣告
Public Sub New ( _
    url As String _
)
public WebTestRequest(
    string url
)
public:
WebTestRequest(
    String^ url
)
new : 
        url:string -> WebTestRequest
public function WebTestRequest(
    url : String
)

參數

  • url
    型別:System.String
    正在接受 Web 效能測試的資源位置。

備註

這個建構函式會設定以下的預設屬性值:

如果 url 參數包含查詢字串參數,這些參數將會設定在 QueryStringParameters 屬性。

範例

下列 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;
        }
    }
}

以下是繼承自 ThreadedWebTest 的 Web 效能測試程式碼,名為 MyCodedWebTest。第二個要求會將三個控制項內所包含的表單資訊張貼至伺服器。

Option Strict Off
Option Explicit On

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

Namespace TestProject2
    
    Public Class MyCodedWebTest
        Inherits ThreadedWebTest
        
        Public Sub New()
            MyBase.New
            Me.PreAuthenticate = true
            
            // TODO: specify your proxy below
            Me.Proxy = "myproxy.seattle.corp.adatum.com:80"

        End Sub
        
        Public Overrides Sub Run()
            Dim request1 As WebTestRequest = New WebTestRequest _
                ("https://localhost/MyWebSite")
            request1.ThinkTime = 1
            Dim rule1 As ExtractHiddenFields = New ExtractHiddenFields
            rule1.ContextParameterName = "1"
            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", "Hello text")
            request2.Body = request2Body
            Dim rule2 As ExtractHiddenFields = New ExtractHiddenFields
            rule2.ContextParameterName = ""
            AddHandler request2.ExtractValues, AddressOf rule2.Extract
            MyBase.Send(request2)
        End Sub
    End Class
End Namespace

.NET Framework 安全性

請參閱

參考

WebTestRequest 類別

WebTestRequest 多載

Microsoft.VisualStudio.TestTools.WebTesting 命名空間