This blog post will show you how to write a plug-in to set properties on each request. For example, you might want to reduce all think times by 10% or change the timeout values for a request or turn off dependent parsing. These are just a few examples but as you can imagine, you would not want to have to go to each request and change the values. Especially if you are going to want to change it back to the original value. You can accomplish these types of activities by creating a web test plug-in. Here is a link to help documentation on web test plug-ins: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.webtesting.webtestplugin.aspx
A web test plug-in allows you to override the following methods:
We are going to create a simple plug-in which will set the ParseDependentsRequest value for each request and to do this we will override the PreRequest method. Do the following:
1) Add a class file to a test project.
2) Copy the below class and paste it into the class file:
[Description("This plugin can be used to set the ParseDependentsRequests property for each request")]
public class ParseDependentsPlugin : WebTestPlugin
private bool m_parseDependents = true;
public override void PreRequest(object sender, PreRequestEventArgs e)
//set the ParseDependentsRequests value on the request
e.Request.ParseDependentRequests = m_parseDependents;
[Description("All requests will have their ParseDependentsRequests property set to this value")]
public bool ParseDependents
m_parseDependents = value;
4) Go to webtest editor and right click on the root node an select Add Web test plugin...
5) You should see this plugin. One of the things that the above plug-in does is expose a property that can be seen in the Add Web Test Plugin dialog. As you can see, we can give it a default value and a description.
6) Set the value of the ParseDependents and choose Ok.
7) Run the test.
You should see that dependents were either parsed or not depending on what you selected. You could easily extend this by adding more properties and having one plug-in used to configure multiple properties of each request.