DCSIMG
How To Create A Team System Web Test Plug-in - SRL Group

SRL Group

This blog is about Team System, QA and Development methodologies and more...

VSTS Resources

Team System Bloggers

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.

image

Step 2: Choose the Web Test Plug-in to use and click OK

image

Run the test and see the result of the Web Test Plug-in.

Have Fun!!!

Comments

Shai Raiten said:

Pre/PostPage & Pre/PostTransaction are only available in SP1.

If you don't have SP1 installed you can only override Request and WebTest.

# April 5, 2009 4:40 PM

Team System News said:

Brian Harry on ALM Catalyst workshops and Second annual Team System Conference in Germany The SRL Team

# April 9, 2009 4:04 PM

Rinku said:

Very precise way to define, it works...:)

It would be great if you can also include a live example also to understand its implementation.

If possible please do that it will help others.

Thanks!!!

# July 13, 2009 5:42 PM

Joeb Low said:

The project doesn't build:

The type or namespace name 'PrePageEventArgs' could not be found

# August 19, 2009 5:52 AM

Eran Ruso said:

Joeb,

Make sure you have the Team Explorer 2008 and Visual Studio SP1 installed.

# August 26, 2009 11:25 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: