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.
You can use customized Web performance test plug-ins with the Web performance tests you have recorded, which enables you to write a minimal amount of code to obtain a greater level of control over your Web performance tests. However, you can also use them with coded Web performance tests. For more information, see How to: Create a Coded Web Performance Test.
Requirements
You can create a customized Web performance test plug-in by deriving your own class from the WebTestPlugin base class.
You can use customized Web performance test plug-ins with the Web performance tests you have recorded, which enables you to write a minimal amount of code to obtain a greater level of control over your Web performance tests. However, you can also use them with coded Web performance tests. For more information, see How to: Create a Coded Web Performance Test.
Note |
---|
You can also create load test plug-ins. See How to: Create a Load Test Plug-In. |
- Visual Studio Enterprise
To create a custom Web performance test plug-in
- Open a Web performance and load test project that contains a Web performance test.
For more information about how to create a Web performance and load test project, see How to: Create and Configure Test Projects for Automated Tests. - In Solution Explorer, right-click on the solution and select Add and then choose New Project.
The Add New Project dialog box is displayed. - Under Installed Templates, select Visual C#.
- In the list of templates, select Class Library.
- In the Name text box, type a name for your class.
- Choose OK.
- The new class library project is added to Solution Explorer and the new class appears in the Code Editor.
- In Solution Explorer, right-click the References folder in the new class library and select Add Reference.
- The Add Reference dialog box is displayed.
- Choose the .NET tab, scroll down, and select Microsoft.VisualStudio.QualityTools.WebTestFramework
- Choose OK.
The reference to Microsoft.VisualStudio.QualityTools.WebTestFramework is added to the Reference folder in Solution Explorer. - In Solution Explorer, right-click on the top node of the Web performance and load test project that contains the load test to which you want to add the Web performance test plug-in and select Add Reference.
- The Add Reference dialog box is displayed.
- Choose the Projects tab and select the Class Library Project.
- Choose OK.
- In the Code Editor, write the code of your plug-in. First, create a new public class that derives from WebTestPlugin.
- Implement code inside one or more of the event handlers. See the following Example section for a sample implementation.
- After you have written the code, build the new project.
- Open a Web performance test.
- To add the Web performance test plug-in, choose Add Web Test Plug-in on the toolbar.
The Add Web Test Plug-in dialog box is displayed. - Under Select a plug-in, select your Web performance test plug-in class.
- In the Properties for selected plug-in pane, set the initial values for the plug-in to use at run time.
Note You can expose as many properties as you want from your plug-ins; just make them public, settable, and of a base type such as Integer, Boolean, or String. You can also change the Web performance test plug-in properties later by using the Properties window. - Choose OK.
The plug-in is added to the Web Test Plug-ins folder.
code for changing the TLS Settings:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.WebTesting.Rules;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.ComponentModel;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
namespace ChgSSL
{
public class Tls12ForcedPlugin : WebTestPlugin
{
[Description("Enable or Disable the plugin functionality")]
[DefaultValue(true)]
public bool Enabled { get; set; }
public override void PreWebTest(object sender, PreWebTestEventArgs e)
{
base.PreWebTest(sender, e);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCB;
e.WebTest.AddCommentToResult(this.ToString() + " has made the following modification-> ServicePointManager.SecurityProtocol set to use Tlsv12 in WebTest Plugin.");
}
public static bool RemoteCertificateValidationCB(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
//If it is really important, validate the certificate issuer here.
//this will accept any certificate
return true;
}
}
}