WebTestPlugin.PreWebTest Method
When overridden in a derived class, represents the method that will handle the event associated with the start of a Web test.
Namespace: Microsoft.VisualStudio.TestTools.WebTesting
Assembly: Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)
Syntax
'Declaration
Public Overridable Sub PreWebTest ( _
sender As Object, _
e As PreWebTestEventArgs _
)
'Usage
Dim instance As WebTestPlugin
Dim sender As Object
Dim e As PreWebTestEventArgs
instance.PreWebTest(sender, e)
public virtual void PreWebTest(
Object sender,
PreWebTestEventArgs e
)
public:
virtual void PreWebTest(
Object^ sender,
PreWebTestEventArgs^ e
)
public function PreWebTest(
sender : Object,
e : PreWebTestEventArgs
)
Parameters
sender
Type: System.ObjectThe source of the event.
e
Type: Microsoft.VisualStudio.TestTools.WebTesting.PreWebTestEventArgsA PostWebTestEventArgs that contains the event data.
Remarks
This provides a code execution entry point at the start of a Web test run.
Examples
The following example shows a Web test plug-in that adds a random number to the context before the Web test is run using the PreWebTest method. 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.
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);
}
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.