Search code examples
c#visual-studio-2015httprequestwebtest

Cannot find a dependent request in webtest


I have recorded a test with my webtest recorder in VS2015. When I am rerunning the test,at one point it fails at a dependent GET request of a .css file. The url in the webtest result shows something like this https://mycompany/blah/Style%20Guides/Global_CSS.css The error is a simple 404 error. Now I go to the main request and search for this particular dependent request so that I can set its Parse_Dependent_Request option as False or set the Extected_Http_Status_Code as 404, which ever works is fine for me. But I am not able to find this particular dependent request under the main or any other request.

I have tried to change all the Parse_Dependent_Request option of all the dependent requests to false and understand which one actually sends the Get request, but none of them worked.I did a generate code from the webtest and literally did a page search but in vain.Do how do I get the request?


Solution

  • Many dependent requests (DRs) are not explicit in the web test. When parse dependent requests of the main request is true, Visual Studio processes the HTML response of that main request to find the DRs and they are added to the list of DRs. Any DR responses that are HTML may also be parsed and their DRs added to the list.

    One technique to handle missing or problematic DRs is to run a plugin that modifies the list of DRs. The code below is based on the WebTestDependentFilter on page 189 of the "Visual Studio Performance Testing Quick Reference Guide" (Version 3.6) available from Codeplex. The Codeplex document has lots of other good information about web and load testing.

    public class WebTestDependentFilter : WebTestPlugin
    {
        public string FilterDependentRequestsThatStartWith { get; set; }
        public string FilterDependentRequestsThatEndWith { get; set; }
        public override void PostRequest(object sender, PostRequestEventArgs e)
        {
            WebTestRequestCollection depsToRemove = new WebTestRequestCollection();
            // Note, you can't modify the collection inside a foreach, hence the second collection
            // requests to remove.
            foreach (WebTestRequest r in e.Request.DependentRequests)
            {
                if (!string.IsNullOrEmpty(FilterDependentRequestsThatStartWith))
                {
                    if (r.Url.StartsWith(FilterDependentRequestsThatStartWith))
                    {
                        depsToRemove.Add(r);
                    }
                }
                else if (!string.IsNullOrEmpty(FilterDependentRequestsThatEndWith))
                {
                    if (r.Url.EndsWith(FilterDependentRequestsThatEndWith))
                    {
                        depsToRemove.Add(r);
                    }
                }
            }
            foreach (WebTestRequest r in depsToRemove)
            {
                e.WebTest.AddCommentToResult(string.Format("Removing dependent: {0}", r.Url));
                e.Request.DependentRequests.Remove(r);
            }
        }
    }
    

    The search criteria in the above code can easily be modified to (for example) check the middle parts of the URL.

    Another variation is to set the expected response code of some DRs to other values. This might make a more accurate performance test than deleting the failing DRs as the server is still required to handle the request and return a response.