Dela via


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.

Inheritance Hierarchy

System.Object
  Microsoft.VisualStudio.TestTools.WebTesting.WebTestPlugin
    Microsoft.VisualStudio.TestTools.WebTesting.WebTestRequestPluginConverter

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

Syntax

'Declaration
Public MustInherit Class WebTestPlugin
public abstract class WebTestPlugin
public ref class WebTestPlugin abstract
[<AbstractClass>]
type WebTestPlugin =  class end
public abstract class WebTestPlugin

The WebTestPlugin type exposes the following members.

Constructors

  Name Description
Protected method WebTestPlugin This class must be inherited.

Top

Methods

  Name Description
Public method Equals Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method PostPage When overridden in a derived class, represents the method that will handle the event associated with the completion of a Web page.
Public method PostRequest When overridden in a derived class, represents the method that will handle the event associated with the completion of an HTTP request.
Public method PostTransaction 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.
Public method PostWebTest When overridden in a derived class, represents the method that will handle the event associated with the end of a Web performance test.
Public method PrePage When overridden in a derived class, represents the method that will handle the event associated with the start of a Web page.
Public method PreRequest When overridden in a derived class, represents the method that will handle the event associated with the start of an HTTP request.
Public method PreRequestDataBinding When overridden in a derived class, represents the method that will handle the event associated with the start of a databinding call.
Public method PreTransaction 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.
Public method PreWebTest When overridden in a derived class, represents the method that will handle the event associated with the start of a Web performance test.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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.

Examples

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);
        }
        
    }
}

Thread Safety

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

See Also

Reference

Microsoft.VisualStudio.TestTools.WebTesting Namespace

Other Resources

How to: Create a Web Performance Test Plug-In