Monday, May 25, 2015

VS Web Performance / Load Test

You might get into the problem - Request failed: The remote name could not be resolved: '<>' when trying to work with VS (Visual Studio) web performance / load test. You might be wondering the URLs works perfectly fine while recording, however during the playback (Run Test) the same URLs are not working. The answer is - during recording, the browser proxy settings for firewall authentication can access URLs. However, during playback (Run Test) VS doesn't know the proxy settings. Solution is to let VS know on the proxy settings. 

Note that the proxy settings set for the webtest properties, as shown in the below screenshot, sometimes might not work (probably bug in the VS).



To overcome this there are two options. One is to attach the WebTestPlugin to the webtest OR attached the WebTestRequestPlugin for each URL in the recordings. Both the options are explained below

Option 1: WebTestPlugin

Create a class, inherited from WebTestPlugin as shown below.

using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Net;

public class ProxyWeb : WebTestPlugin
{
    public override void PreRequest(object sender, PreRequestEventArgs e)
    {
        // Create a WebProxy object for your proxy
        WebProxy webProxy = new WebProxy(""); //Enter the proxy

        //Set the WebProxy so that even local addresses use the proxy
        // webProxy.BypassProxyOnLocal = false;

        // Use this WebProxy for the Web test
        e.WebTest.WebProxy = webProxy;



        e.WebTest.PreAuthenticate = true;
        NetworkCredential proxyCredentials;

        proxyCredentials = new NetworkCredential();

        proxyCredentials.Domain = ""; // Enter the domain
        proxyCredentials.UserName = ""; // Enter the user name
        proxyCredentials.Password = ""; // Enter the password
        e.WebTest.WebProxy.Credentials = proxyCredentials;
    }
}

Attach the plugin to the webtest as shown in the below screenshot


Option 2: WebTestRequestPlugin

Create a class, inherited from WebTestRequestPlugin as shown below.

using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Net;

public class ProxyRequest : WebTestRequestPlugin
{
    public override void PreRequest(object sender, PreRequestEventArgs e)
    {
        // Create a WebProxy object for your proxy
        WebProxy webProxy = new WebProxy(""); // Enter the proxy

        //Set the WebProxy so that even local addresses use the proxy
        // webProxy.BypassProxyOnLocal = false;

        // Use this WebProxy for the Web test
        e.WebTest.WebProxy = webProxy;



        e.WebTest.PreAuthenticate = true;
        NetworkCredential proxyCredentials;

        proxyCredentials = new NetworkCredential();

        proxyCredentials.Domain = ""; // Enter the domain
        proxyCredentials.UserName = ""; // Enter the user name
        proxyCredentials.Password = ""; // Enter the password
        e.WebTest.WebProxy.Credentials = proxyCredentials;
    }
}

Attach the plugin to the each URL recorded in the webtest. i.e. Right click on the recorded URL and select "Add Request Plug-in".

For the most times option 1 should always work fine.

Post a Comment