Friday, January 12, 2018

Load Testing with VisualStudio

Sometimes as developers we are asked to do load testing development server to get an rough idea about how the site will perform based on user load. If you are a .net developer and have access to visual studio enterprise edition then you can do it easily without much hassle.
Lets follow the steps to create load testing.

1> Go to visual studio and select "web performance and load test project" from test in Project
2> delete default webtest file and create a new webtest file. ( it may happen that you get an error as Add-ons in IE is disabled. this test primarily use IE for testing)

image 1


3> Enable the recording in IE and browse the site. Once you visit enough url stop the test.
image 2


4> Right click on the webtest1 and try to run the test. If your performance test runs you are lucky.
Else you might get SSL\TLS connection error. In that case you have to write a plugin.

5>  Go ahead and create below plugin.

using System;
using System.ComponentModel;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using Microsoft.VisualStudio.TestTools.WebTesting;

namespace WebAndLoadTestSiteCore
{

    public class MyCustomPlugin : WebTestPlugin
    {
        [Description("Enable or Disable the plugin")]
        [DefaultValue(true)]
        public bool Enabled { get; set; }
        public override void PreWebTest(object sender, PreWebTestEventArgs e)
        {
            base.PreWebTest(sender, e);
            //For TLS
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            //For SSL
            // ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            //wire up the callback so we can override  behavior and force it to accept the cert
            ServicePointManager.ServerCertificateValidationCallback = CertificateValidation;
            //let them know we made changes to the service point manager
            e.WebTest.AddCommentToResult(
            this.ToString() + " has made the following modification-> ServicePointManager.SecurityProtocol set to use SSLv3 in WebTest Plugin.");
        }

        public static bool CertificateValidation(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

        {         
            //this will accept any certificate
            return true;

        }

    }

}

6> Now we have to add the plugin into our performance test(webtest). Build VS project.
7>come back to the .webtest tab in VS
8> Add a context Parameter (right click on webtest1,refer image2). Put a custom name.
image 3

9> Add a web test plugin. Put target context parameter name.
10> Now comeback and generate code for performance test.
image 4


11> Go to the code and update plugin name as MyCustomPlugin
12> right click on the method GetRequestEnumerator and select "run coded web performance test"
13> If everything looks fine then right click on the project and add Load Test.
14> follow this url for detail steps.



No comments:

Post a Comment