locked
Proxy settings for dependent requests in web test RRS feed

  • Question

  • Hi!

    I use web tests to create a load test with Visual Studio 2012 (and 2015). I have to set a proxy for my web tests (in web test properties) and it works fine for single requests but for the dependent request the proxy setting does not seem to apply. Is there a way to set proxy settings for dependent requests?

    Thanks Stefan

    Monday, October 24, 2016 11:14 AM

All replies

  • Hi Stefan Stoffe,

    According to your description, you could use Web Test request plugin (not web test plugin) to implement your idea. Please refer to the following MSDN document:

    https://msdn.microsoft.com/en-us/library/ms182554%28VS.80%29.aspx?f=255&MSPPError=-2147217396

    And then add the following codes in PreWebTest to the PreRequest method in web test request plugin:

    https://blogs.msdn.microsoft.com/tfssetup/2016/05/31/how-to-add-a-web-performance-test-plug-in-to-authenticate-through-different-proxy-in-visual-studio-2015/

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 25, 2016 5:39 AM
  • Hi Oscar, thanks for your answer! 

    Im a bit confused, first you say that I should create a web request plugin, but then you refer to a web test plugin for the proxy setting. In the blog the WebTest.Proxy is set, not the proxy for the web request. Still I have tested the plugin as suggested but with no success. Dependent requests are still failing.

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

    namespace WebRequestPlugin
    {
        public class Proxy : WebTestRequestPlugin
        {
            public override void PreRequest(object sender, PreRequestEventArgs e)
            {
                e.WebTest.WebProxy = new WebProxy("myproxy");
            }
        }

    }

    BTW, what is the difference between WebTest.Proxy and WebTest.WebProxy?

    BR Stefan

    Tuesday, October 25, 2016 11:12 AM
  • Hi Stefan Stoffe,

    Thank you for your response.

    Both in web test plugin or web request test plugin are also have the PreRequest method. We need to override it. The difference between them is that PreRequest method in web test plugin will be triggered before every request and PreRequest method in web test request plugin will be triggered in a specify request.

    Because you have said, you want to let it works fine in dependent request, so I suggest you add the following code to the PreRequest of web test request plugin.  After you have coded the web test request plugin, you could right click one request and choose Add Request Plug-in.

    // Create a WebProxy object for your proxy
    
    WebProxy webProxy = new WebProxy(“<http://yourproxy>”);
    
    //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 = “yourDomain”;
    
    proxyCredentials.UserName = “yourUserName”;
    
    proxyCredentials.Password = “yourPassword”;
    
    e.WebTest.WebProxy.Credentials = proxyCredentials;

    The difference between e.WebTest.WebProxy and e.WebTest.Proxy is that:

    We could use             

    e.WebTest.WebProxy = new WebProxy("Address");

    or

    e.WebTest.Proxy = "Address";

    to set the proxy.


    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.




    • Edited by Oscar_Wu Wednesday, October 26, 2016 2:21 AM
    Wednesday, October 26, 2016 2:10 AM
  • I am wondering which dependent requests are failing - is it all of them or just some of them?

    If it is just some dependant requests that are failing then it may be that the plugin is not being called on all of them.

    Please read all the posts in this thread to understand why I ask the question and why just some dependant requests are affected. Then consider adding a plugin based on Ian's code in that thread. The important parts are the two "r.PostRequest += new System.EventHandler ... ;" statements. See https://social.msdn.microsoft.com/Forums/vstudio/en-US/b47722ba-6cc5-4fea-a327-7c64b51c2940/dependencies-not-showing-in-collection?forum=vstest

    Regards

    Adrian

    Wednesday, October 26, 2016 8:16 AM
  • I'd forgotten about that!

    Yes basically webtest plugins will get added to every request in the Webtest you'll need to add the plugin to any dependent requests from within the plugin itself.

    Wednesday, October 26, 2016 8:41 AM
  • Hi Adrian and Ian, thanks for your responses!

    I think you are on to something, although I think that proxy settings for dependent requests should be inherided from the parent request. However, if I add the event handler, how do I set the proxy settings for the dependent requests?

    foreach (WebTestRequest r in e.Request.DependentRequests)
    {
        r.PostRequest += new System.EventHandler<PostRequestEventArgs>(r_PostRequest);
    }

    Thanks/Stefan

    Wednesday, October 26, 2016 9:32 AM
  • Have your proxy setting as a property of the plugin

    and then do it like this

                    WebTestDependentProxy DepProxy = new WebTestDependentProxy();
                    DepProxy.Proxy = this.Proxy
    
                    foreach (WebTestRequest r in e.Request.DependentRequests)
                    {
                        r.PreRequest += new EventHandler<PreRequestEventArgs>(DepProxy.PreRequest);
                        r.PostRequest += new EventHandler<PostRequestEventArgs>(DepProxy.PostRequest);
    
                    }
    
    Hope this makes sense

    Wednesday, October 26, 2016 9:44 AM
  • Hi Stefan Stoffe,

    Whether you could use the following code I modified it based on lan’s code. I have not tested it because I have not proxy in my side. You could refer it:

            public override void PreRequest(object sender, PreRequestEventArgs e)
            {
                foreach (WebTestRequest r in e.Request.DependentRequests)
                {
                    r.PreRequest += new EventHandler<PreRequestEventArgs>(r_PreRequest);
                }
    
            }
            void r_PreRequest(object sender, PreRequestEventArgs e)
            {
                WebProxy webProxy = new WebProxy("<http://yourproxy>");
                e.WebTest.WebProxy = webProxy;
                e.WebTest.PreAuthenticate = true;
                NetworkCredential proxyCredentials;
                proxyCredentials = new NetworkCredential();
                proxyCredentials.Domain = “yourDomain”;
                proxyCredentials.UserName = “yourUserName”;
                proxyCredentials.Password = “yourPassword”;
                e.WebTest.WebProxy.Credentials = proxyCredentials;
            }

    If it works, you need to tidy the r_PreRequest function.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 26, 2016 10:06 AM
  • Hi Stefan,

    You wrote "although I think that proxy settings for dependent requests should be inherided from the parent request" and, whilst I agree, it seems that second level dependant requests (DRs) are treated differently than first level DRs. It seems that DRs of a top level response are treated differently to DRs of DRs. Hence some extra code is needed.

    Regards

    Adrian

    Wednesday, October 26, 2016 10:22 AM
  • Hi Stefan, Adrian

    I think effectively what happens is that Webtest plugins get applied to every request listed in the webtest, however, dependent requests are parsed dynamically at runtime and don't automatically get the plugin.

    Cheers

    Wednesday, October 26, 2016 10:26 AM
  • Hi Ian!

    Acctually I don't understand what you mean by

                    WebTestDependentProxy DepProxy = new WebTestDependentProxy();
                    DepProxy.Proxy = this.Proxy

    What is WebTestDependentProxy? :)

    BR Stefan

    Wednesday, October 26, 2016 10:49 AM
  • Hi Stefan

    WebtestDewpendentProxy is your plugin so basically you are instantiating a copy of your plugin copying it's properties from the current instance and then adding the relevant methods to the event handler.

    Hope this makes sense

    Wednesday, October 26, 2016 11:37 AM
  • Hi Adrian, how do I know if it is a dependent request or a dependent dependent request so to speek? :) All I see is that all "dependent requests" fails with "407 Proxy Authentications Required".

    BR Stefan

    Wednesday, October 26, 2016 1:09 PM
  • Hi Oscar!

    Unfortunately the plugin that you suggested did not work. I still get "407 Proxy Authenticatino Required" for the dependent requests.

    BR Stefan

    Wednesday, October 26, 2016 1:13 PM
  • Can you answer the question I asked first this morning: which dependent requests are failing - is it all of them or just some of them?

    In answer to the question about "it is a dependent request or a dependent dependent request", see the explanation in the linked question. Additionally, you can easily tell which dependant requests are (or would be) processed by your plugin and which are not by using a plugin like below, then manually cross checking the output from the plugin against the dependant requests whose times etc are shown in the log. Add it as a new and separate plugin, not as part of the add-proxy plugin. 

    void r_PostRequest(object sender, PostRequestEventArgs e)
    {
        foreach (WebTestRequest r in e.Request.DependentRequests)
        {
            e.WebTest.AddCommentToResult("Found dependant " + r.Url);
        }
    }

    Regards

    Adrian

    Wednesday, October 26, 2016 1:55 PM
  • Hi Adrian

    All dependent requests fails.

    BR Stefan

    Wednesday, October 26, 2016 2:01 PM
  • Hi Stefan

    According to Adrian’s code, I think we may need to use PreWebTestEventArgs instead of PostRequestEventArgs.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 27, 2016 6:33 AM
  • Stefan,

    Yesterday morning I asked whether it was all dependant request that fail, or just some of them. You replied "I think you are on to something" and continued the discussion as if it were just some of the requests. Only when I repeated the question, after many more contributions from myself and others, did you reply that all of the dependant requests are failing. Hence my theory was wrong. I do not mind my theory being wrong but I do mind the waste of time because you failed to answer a clearly stated question.

    Regards

    Adrian

    Thursday, October 27, 2016 8:34 AM
  • Hi Adrian, sorry for being unclear on this, I didn't realize the importance of that answer. So, you think the event handler is not the solution to my problem?

    BR Stefan

    Thursday, October 27, 2016 8:44 AM
  • Hi BR Stefan,

    In my opinion, the first step you need to make sure the dependent requests have been got in web request test plugin, if not, I think there is somethings wrong with your code. After making sure get the dependent request then we could try to add the proxy to it to observe whether it works.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Oscar_Wu Friday, October 28, 2016 9:37 AM
    Friday, October 28, 2016 9:37 AM
  • Hi Oscar, thanks for your respons.

    This plugin adds the header "test" to some of my dependent requests:

    using Microsoft.VisualStudio.TestTools.WebTesting;
    
    public class SetHeaders : WebTestRequestPlugin
    {
        public override void PreRequest(object sender, PreRequestEventArgs e)
        {
            foreach (WebTestRequest r in e.Request.DependentRequests)
            {
                r.Headers.Add(new WebTestRequestHeader("test", "test"));
            }
        }
    }

    As Adrian and Ian argues this could be due to the fact that some of them are dependent dependent requests, however I am not sure. Now, how do I set the proxy instead of the header of a dependent request?

    BR Stefan


    Friday, October 28, 2016 10:41 AM
  • Hi Stefan Stoffe,

    Please use the following code to get the dependent request URL:

            public override void PostRequest(object sender, PostRequestEventArgs e)
            {
                foreach (WebTestRequest r in e.Request.DependentRequests)
                {              
                    MessageBox.Show("dependent request:"+r.Url);
                    //or use
                    //e.WebTest.AddCommentToResult("Found dependent "+r.Url);
                }
            }

    And please share me a screenshot about the specify request that you have added the request plugin to it.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    • Edited by Oscar_Wu Monday, October 31, 2016 8:02 AM
    Monday, October 31, 2016 8:01 AM
  • Hi Oscar, what is the purpose of the code above? What I would like to do is to set the proxy for the dependent requests.

    BR Stefan

    Monday, October 31, 2016 8:26 AM
  • Hi Stefan Stoffe,

    Because you said to add the proxy to dependent request, this code could help us get the URL of the dependent request. And it was tested without any problems in my side.

    After making sure get the dependent request, then we could try to add the proxy to it.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    • Edited by Oscar_Wu Monday, October 31, 2016 8:32 AM
    Monday, October 31, 2016 8:31 AM
  • Hi Oscar, thanks, I have tested that it works on my side too. Unfortunately I don't have permission from my client to share the information so I cannot share a screenshot. Now, How do I add the proxy setting?

    BR Stefan 

    Monday, October 31, 2016 10:17 AM
  • Hi Stefan Stoffe,

    As my opinion, now we could get the dependent request, so we need to verify the proxy works fine in the request plugin.

    I think we need to add the proxy to the PreRequest function first, if the first request passed with the proxy, then we could try to add the proxy to the dependent request.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 1, 2016 8:04 AM
  • Hi Oscar, could you please provide a code example on how you mean?

    BR Stefan

    Tuesday, November 1, 2016 8:26 AM
  • Hi Stefan Stoffe,

    You said in your request contains dependent request, so this first step is to set proxy to the first request, then we could set the proxy to dependent request.

    The code how to set a proxy is in my second reply. And please share me your code that you set the proxy in your code.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    • Edited by Oscar_Wu Tuesday, November 1, 2016 8:42 AM
    Tuesday, November 1, 2016 8:38 AM
  • Hi Oscar,

    so you mean to set the proxy for the parent request.  I have tried the code below but it does not set the parent request proxy so I don't know if it is possible at all to change the proxy from a plugin.

    using Microsoft.VisualStudio.TestTools.WebTesting;
    using System.Net;
    
    
    public class DepedndentRequests : WebTestRequestPlugin
    {
        public class Proxy : WebTestRequestPlugin
        {
            public override void PreRequest(object sender, PreRequestEventArgs e)
            {
                e.WebTest.PreAuthenticate = true;
                e.WebTest.WebProxy = new WebProxy("myproxy");
                e.WebTest.Proxy = "myproxy";
            }
        }
       
    }
    
    BR Stefan

    Tuesday, November 1, 2016 9:14 AM
  • Hi Stefan Stoffe,

    Please use either of “e.WebTest.WebProxy” or “e.WebTest.Proxy”. And please run it in VS2015.

    In addition, in IE remove any proxy set over there.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Oscar_Wu Wednesday, November 2, 2016 7:54 AM
    Wednesday, November 2, 2016 7:44 AM
  • Hi Oscar!

    I have done the tests above with VS2015, none of them works.

    BR Stefan


    Wednesday, November 2, 2016 8:07 AM
  • Hi Stefan Stoffe,

    Above all replies, the problem is that the proxy in web test plugin does not work. But it works in web test property.

    As far as I know, we are general use above code to set proxy in web test plugin, I have not found another way to set proxy in web test plugin.

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 2, 2016 9:07 AM