WebTestPlugins – Why? and How


WebTestPlugins – Why? and How

In my last post I’ve talked about Increase Web Test Reponses Size using Web Test Plugins, now I would like to go one step back and talk about what is Web Test Plugin and Why you may want to use it.

Web performance tests plug-ins enable you to isolate and reuse code outside the main declarative statements in your Web performance test.

A customized Web performance test plug-in offers you a way to call some code as the Web performance test is run.

The Web performance test plug-in is run one time for every test iteration.

In addition, if you override the PreRequest or PostRequest methods in the test plug-in, those request plug-ins will run before or after each request, respectively.

You can create a customized Web performance test plug-in by deriving your own class from the WebTestPlugin base class.

Download Demo Project

Create Web Test Plugin

1. Create new image project, add reference to Microsoft.VisualStudio.QualityTools.WebTestFramework.dll located under C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies.

2. Add new image and give the the desire name for the plugin, define your new class to derive from WebTestPlugin.

Now you can override the desire method and add your own code.

public class WebPluginDemo : WebTestPlugin
    //PrePage fires before any explicit request in the webtest. It also fires before any PreRequest method.
    public override void PrePage(object sender, PrePageEventArgs e) { base.PrePage(sender, e); }

    //PreRequest fires before ALL requests made, including redirects and dependant requests. If you want it to act on only redirects,
    //or skip redirects. use the e.Request.IsRedirectFollow property to handle code flow.
    public override void PreRequest(object sender, PreRequestEventArgs e) { base.PreRequest(sender, e); }

    //PreRequestDataBinding fires before data from the context has been bound into the request. Gives an opportunity to change the data binding.
    public override void PreRequestDataBinding(object sender, PreRequestDataBindingEventArgs e) { base.PreRequestDataBinding(sender, e); }

    //PreTransaction is fired before all user defined transaction in the test.
    public override void PreTransaction(object sender, PreTransactionEventArgs e) { base.PreTransaction(sender, e); }

    //PreWebTest fires before the first request is sent.
    public override void PreWebTest(object sender, PreWebTestEventArgs e) { base.PreWebTest(sender, e); }

    public override void PostPage(object sender, PostPageEventArgs e) { base.PostPage(sender, e); }
    public override void PostRequest(object sender, PostRequestEventArgs e) { base.PostRequest(sender, e); }
    public override void PostTransaction(object sender, PostTransactionEventArgs e) { base.PostTransaction(sender, e); }
    public override void PostWebTest(object sender, PostWebTestEventArgs e) { base.PostWebTest(sender, e); }              
3. Create new Test Project under the same solution and add project reference to the Class Library we created in step 1.
4. Add the Web Test Plugin into you Web Test by clicking on image, now you should see you plugin as part of the Web Test
Download Demo Project
Add comment
facebook linkedin twitter email

Leave a Reply