Click to Rate and Give Feedback

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Team Test API
WebTestPlugin Class

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

Namespace:  Microsoft.VisualStudio.TestTools.WebTesting
Assembly:  Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)
Visual Basic (Declaration)
Public MustInherit Class WebTestPlugin
Visual Basic (Usage)
Dim instance As WebTestPlugin
C#
public abstract class WebTestPlugin
Visual C++
public ref class WebTestPlugin abstract
JScript
public abstract class WebTestPlugin

Using a WebTestPlugin and using the PreWebTest/PostWebTest events of the WebTest class are functionally equivalent. The difference is that coded Web 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.

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

C#
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);
        }
        
    }
}
System..::.Object
  Microsoft.VisualStudio.TestTools.WebTesting..::.WebTestPlugin
    Microsoft.VisualStudio.TestTools.WebTesting..::.WebTestRequestPluginConverter
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker