MSDN Library
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.

WebTestPlugin Class

 

Provides a means to run code and access a WebTest before and after the Web performance test is run. This class must be inherited.

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


public abstract class WebTestPlugin

NameDescription
System_CAPS_protmethodWebTestPlugin()

This class must be inherited.

NameDescription
System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodPostPage(Object, PostPageEventArgs)

When overridden in a derived class, represents the method that will handle the event associated with the completion of a Web page.

System_CAPS_pubmethodPostRequest(Object, PostRequestEventArgs)

When overridden in a derived class, represents the method that will handle the event associated with the completion of an HTTP request.

System_CAPS_pubmethodPostTransaction(Object, PostTransactionEventArgs)

When overridden in a derived class, represents the method that will handle the event associated with the completion of a transaction that is defined in the Web performance test.

System_CAPS_pubmethodPostWebTest(Object, PostWebTestEventArgs)

When overridden in a derived class, represents the method that will handle the event associated with the end of a Web performance test.

System_CAPS_pubmethodPrePage(Object, PrePageEventArgs)

When overridden in a derived class, represents the method that will handle the event associated with the start of a Web page.

System_CAPS_pubmethodPreRequest(Object, PreRequestEventArgs)

When overridden in a derived class, represents the method that will handle the event associated with the start of an HTTP request.

System_CAPS_pubmethodPreRequestDataBinding(Object, PreRequestDataBindingEventArgs)

System_CAPS_pubmethodPreTransaction(Object, PreTransactionEventArgs)

When overridden in a derived class, represents the method that will handle the event associated with the start of a transaction that is defined in the Web performance test.

System_CAPS_pubmethodPreWebTest(Object, PreWebTestEventArgs)

When overridden in a derived class, represents the method that will handle the event associated with the start of a Web performance test.

System_CAPS_pubmethodToString()

(Inherited from Object.)

Using a WebTestPlugin and using the PreWebTest/PostWebTest events of the WebTest class are functionally equivalent. The difference is that coded Web performance tests are the only place you can use the events.

Notes to Inheritors:

When you inherit from WebTestPlugin, you must override the following members: PostWebTest, and PreWebTest.

Legacy Code Example

The following example shows a Web performance test plug-in that adds a random number to the context before the Web performance test is run. In the same way you can override PostWebTest and perform an action after the Web performance test has run. For example, you might want to write to a log file the time it takes to complete the Web performance test and the number of requests issued during the Web performance test.

using System;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Windows.Forms;

namespace WebTestPluginNamespace
{
    public class MyWebTestPlugin : WebTestPlugin
    {
        public static string NewRandomNumberString(int size)
        {
            byte[] buffer = new byte[size];
            // Seed using system time
            Random random = new Random(unchecked((int)DateTime.Now.Ticks));

            random.NextBytes(buffer);
            return BitConverter.ToInt32(buffer, 0).ToString();
        }

        public override void PreWebTest(object sender, PreWebTestEventArgs e)
        {
            e.WebTest.Context["RandNum"] = NewRandomNumberString(4);
        }

    }
}

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

Return to top
Show:
© 2016 Microsoft