WebTestRequest Class

Represents an HTTP request that will be sent to a Web server.

System.Object
  Microsoft.VisualStudio.TestTools.WebTesting.WebTestItem
    Microsoft.VisualStudio.TestTools.WebTesting.WebTestRequest

Namespace:  Microsoft.VisualStudio.TestTools.WebTesting
Assembly:  Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)

[SerializableAttribute]
public class WebTestRequest : WebTestItem

The WebTestRequest type exposes the following members.

  NameDescription
Public methodWebTestRequest(String)Initializes a new instance of the WebTestRequest class by using a URL string.
Public methodWebTestRequest(Uri)Initializes a new instance of the WebTestRequest class by using a Uri object.
Top

  NameDescription
Public propertyBodyGets or sets the body of this request.
Public propertyBodyBytesGets the bytes that are associated with the body.
Public propertyCacheGets or sets a value that indicates whether to simulate browser caching for the request.
Public propertyClientCertificatesGets or sets a reference to allow users to authenticate by using X.509 SSL certificates.
Public propertyContentLengthGets the length, in bytes, of the request body.
Public propertyContentTypeGets the content type of the request.
Public propertyCookiesGets a collection of cookies.
Public propertyCorrelationExtractionRuleReferencesGets the collection of references to extraction rules that are used to correlate dynamic parameters.
Public propertyDependentRequestsGets the collection of dependent requests.
Public propertyEncodeRedirectedUrlGets or sets a Boolean value that indicates whether to encode query string parameters on a redirected URL.
Public propertyEncodingGets or sets the Encoding format.
Public propertyExpectedHttpStatusCodeGets or sets the HTTP status code that is expected for this request.
Public propertyExpectedResponseUrlGets or sets the expected URL of the response. When a redirect is expected, this URL might differ from the request URL.
Public propertyExtractionRuleReferencesGets the collection of references to extraction rules that are defined for the request.
Public propertyFollowRedirectsGets or sets a value that indicates whether to automatically follow redirects.
Public propertyHasCookiesGets a value that indicates whether the request has cookies.
Public propertyHasDependentRequestsGets a value that indicates whether the request has dependent requests.
Public propertyHasHeadersGets a value that indicates whether the request has HTTP headers.
Public propertyHasQueryStringParametersGets a value that indicates whether the request has querystring parameters.
Public propertyHeadersGets the collection of HTTP headers for the request.
Public propertyIsRedirectFollowGets a value that indicates whether the request was created as the result of following a redirect.
Public propertyItemIdZero-based sequence number of the item in the Web performance test. (Inherited from WebTestItem.)
Public propertyMethodGets or sets the method to use for the request.
Public propertyOutcomeGets or sets the Pass or Fail outcome of the Web performance test request.
Public propertyParseDependentRequestsGets or sets a value that indicates whether to automatically fetch dependent requests that are found in the response body.
Public propertyQueryStringParametersGets the list of query string parameters for the request.
Public propertyRecordedCookiesGets the cookies that is recorded together with the request.
Public propertyRecordResultGets or sets a value that indicates whether individual statistics and result data are tracked for this request.
Public propertyReportingNameGets or sets the reporting name for a request.
Public propertyResponseTimeGoalGets or sets the response time goal for a particular page.
Public propertySendChunkedGets or sets a value that indicates whether the user can send a chunked request body.
Public propertyThinkTimeGets or sets a value that represents the think time to wait after the response is received.
Public propertyTimeoutGets or sets a value that indicates the time to wait for this request before timing out.
Public propertyUrlGets or sets the URL to the resource that is used for the request.
Public propertyUrlWithQueryStringGets the URL to the resource that is used for the request. This includes the query string.
Public propertyValidationRuleReferencesGets the collection of references to validation rules that are defined for the request.
Public propertyVersionGets or sets the HTTP version of the request.
Public propertyWebTestRequestPluginReferencesGets the collection of references to the Web performance test request plug-ins that are defined on the request.
Top

  NameDescription
Public methodCloneMakes a deep copy of the WebTestRequest object. (Overrides WebTestItem.Clone().)
Public methodEqualsDetermines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInternalSetOutcomeRepresents the outcome that was set internally by RequestPlugin.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodRuntimeCloneReturns a clone of this object at run time. (Inherited from WebTestItem.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventExtractValuesOccurs after the ValidateResponse event.
Public eventPostRequestOccurs after the ValidateResponse and the ExtractValues events.
Public eventPreRequestOccurs before the request is sent.
Public eventPreRequestDataBindingThis event is raised before the data binding occurs.
Public eventValidateResponseOccurs immediately after the response is received.
Public eventValidateResponseOnPageCompleteThis event is raised after the page is fully loaded. This is used to check that the response was valid.
Top

This class provides the core functionality to simulate HTTP requests in a coded Web performance test. The simulated HTTP requests are returned to the Web performance test engine by the GetRequestEnumerator method for Visual C# Web performance tests and by the Run method that is used by ThreadedWebTest in Visual Basic.

This class is serializable.

The following Web performance test extracts values that represent the status of check boxes and adds the values to the context.

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("http://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;
        }
    }
}

The following is a coded Web performance test called MyCodedWebTest that inherits from ThreadedWebTest. The second request posts form information that is contained in three controls back to the server.

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.northwind.com:80"
        End Sub
        
        Public Overrides Sub Run()
            Dim request1 As WebTestRequest = New WebTestRequest _
                ("http://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 _
                ("http://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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show: