How To Create A Team System Web Test Plug-in
I will start by explaining what is a test plug-in and than I will show how to create one.
Web Test Plug-in is used to do the following:
- Run code that you write at the beginning or at the end of each Iteration.
In order to use it in the beginning and the end of each iteration you will need to override the PreWebTest and PostWebTest methods.
- Run code at the beginning or the end of each Request.
In order to use a Web Test Plug-in in the beginning and the end of each request you will need to override the PreRequest or PostRequest methods.
- Run code at the beginning or the end of each Page.
In order to use a Web Test Plug-in in the beginning and the end of each page you will need to override the PrePage or PostPage methods.
- Run code at the beginning or the end of each Transaction.
In order to use a Web Test Plug-in in the beginning and the end of each page you will need to override the PreTransaction or PostTransaction methods.
So, how do I create a Web Test Plug-in?
Step 1: Create a new project, make it a “Class Library” type.
Step 2: Add a reference to: Microsoft.VisualStudio.QualityTools.WebTestFramework.dll located in “Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies\”.
Step 3: Add the following using:
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.ComponentModel;
Note: The last using is not related to the Team System but it will let us the use of attributes in order to make the implementation simple.
Step 4: Next step is to add the following, see that you override only what you need:
namespace TestPlugin
{
[DisplayName("Web Test Plug-in Name")]
[Description("Web Test Plug-in Description")]
public class MyWebPlugin : WebTestPlugin
{
public override void PreRequest(object sender, PreRequestEventArgs e)
{
base.PreRequest(sender, e);
}
public override void PostRequest(object sender, PostRequestEventArgs e)
{
base.PostRequest(sender, e);
}
public override void PreWebTest(object sender, PreWebTestEventArgs e)
{
base.PreWebTest(sender, e);
}
public override void PostWebTest(object sender, PostWebTestEventArgs e)
{
base.PostWebTest(sender, e);
}
public override void PrePage(object sender, PrePageEventArgs e)
{
base.PrePage(sender, e);
}
public override void PostPage(object sender, PostPageEventArgs e)
{
base.PostPage(sender, e);
}
public override void PreTransaction(object sender, PreTransactionEventArgs e)
{
base.PreTransaction(sender, e);
}
public override void PostTransaction(object sender, PostTransactionEventArgs e)
{
base.PostTransaction(sender, e);
}
}
}
Important: Don’t forget to make the class public!!!
Step 5: Now add a reference from your test project to the Web Test Plug-in project.
Now the Web Test Plug-in is available.
So How can I use it?
Step 1: Click the “Add Web Test Plug-in” button.
Step 2: Choose the Web Test Plug-in to use and click OK
Run the test and see the result of the Web Test Plug-in.
Have Fun!!!