Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ExtractionRule::Extract Method (Object^, ExtractionEventArgs^)

 

When overridden in a derived class, this method extracts information from a HtmlDocument and places it into the WebTestContext.

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

public:
virtual void Extract(
	Object^ sender,
	ExtractionEventArgs^ e
) abstract

Parameters

sender
Type: System::Object^

The source of the event.

e
Type: Microsoft.VisualStudio.TestTools.WebTesting::ExtractionEventArgs^

An ExtractionEventArgs that contains the event data.

This method contains the core extraction functionality. This method has the responsibility of extracting the data from the response.

Notes to Inheritors:

When overridden in a derived class, the Extract method adds the extracted value to the WebTestContext provided by e.WebTest.Context. The name for the value added to the WebTestContext is set with the ContextParameterName property. If the extraction is a success, e.Success is set to true; otherwise it should be set to false.

Legacy Code Example

The following is a Web performance test that uses the ExtractCheckBoxes custom extraction rule. The code for this can be found at ExtractionRule. The code checks for the existence of check boxes in the HtmlDocument provided by the WebTestResponse that is contained in the ExtractionEventArgs. The results are yielded to the test engine.

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. This test extracts Hidden Fields. The second request posts form information 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()
            MyBase.New
            Me.PreAuthenticate = true
            Me.Proxy = "myproxy.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
Return to top
Show: