This documentation is archived and is not being maintained.

WebTestRequest Class

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

Namespace: Microsoft.VisualStudio.TestTools.WebTesting
Assembly: Microsoft.VisualStudio.QualityTools.WebTestFramework (in microsoft.visualstudio.qualitytools.webtestframework.dll)

public class WebTestRequest : WebTestItem
/** @attribute SerializableAttribute() */ 
public class WebTestRequest extends WebTestItem
public class WebTestRequest extends WebTestItem

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

This class is serializable.

The following Web 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()
            WebTestRequestrequest1 = new WebTestRequest("http://localhost/ts");
            ExtractCheckBoxes rule1 = new ExtractCheckBoxes();
            rule1.FindCheckedBoxes = true;
            rule1.ContextParameterName = "CheckedBoxes";
            request1.ExtractValues += new EventHandler
            ExtractCheckBoxes rule2 = new ExtractCheckBoxes();
            rule2.FindCheckedBoxes = false;
            rule2.ContextParameterName = "";
            request1.ExtractValues += new EventHandler
            yield return request1;

The following is a coded Web test called MyCodedWebTest that inherits from ThreadedWebTest The second request posts form information that is contained within 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()
            Me.PreAuthenticate = true
            // TODO: specify your proxy below
            Me.Proxy = ""
        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

            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" + _
            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
        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.