Udostępnij za pośrednictwem


Masking a 404 error in a dependent request

There are times when your web test may fail with a 404 error in a dependent request (like a css file or gif), but you may not actually care about this error. For example, it may be something that doesn't really impact the layout or content of the page. Or you might file a bug and temporarily want to suppress the error until it is fixed so they can find other errors.

If you get a 404 error in a dependent resource, here's how you can mask it.

Here's a failing web test, it is very simple. If I expand the top request I can see it is failing due to a failed dependent request.

image

To mask the request, right-click on the dependent and hit Copy.

Go to the test, right click on the corresponding request in the test and select "Add Dependent Request". Paste the url on the clipboard into the url property for the dependent request:

image

Now set the expected http status code on the dependent to 404.

image

Rerun the test to see it pass.

image

Hope that helps,

Ed.

Comments

  • Anonymous
    August 06, 2008
    PingBack from http://blog.a-foton.ru/2008/08/masking-a-404-error-in-a-dependent-request/

  • Anonymous
    January 12, 2010
    Hi Ed, The above process for Masking a 404 error was really helpful. But say if the dependent request are dynamic ( by which I mean it keeps changing) and throw a 404 (as image do not exist) then how to mask those error? Thank you in advance. Rgds Prem

  • Anonymous
    June 30, 2010
    Hi Ed, Solved an issue we have been plagued with for a while. Thanks!

  • Anonymous
    September 21, 2010
    Hi Ed, The above solution was really helpful. Thank you very much.

  • Anonymous
    December 07, 2010
    This is a neat undocumented feature. HOWEVER, note that this technique ONLY works on top-level requests.  It DOES NOT work on dependent requests (e.g. when a dependent request itself makes a failing dependent request), and it also does not work on requests within transactions.

  • Anonymous
    January 21, 2011
    This seems really hacky and if you have a CDN that is not delivering all the images you need on a site it would take a lot of manual effort to mask these 404 responses for images.  Is there not a way to do this in a programmatic solution where if the dependency request is an image and the response is a 404 to ignore the dependency request?

  • Anonymous
    January 27, 2011
    You can still go through a webtest plugin and parse all the pages before testing your site: I personally use this before launching a stress test to create empty images for all missing items. <code> public class WebTestDependentFilter : WebTestPlugin    {        public override void PostRequest(object sender, PostRequestEventArgs e)        {            base.PostRequest(sender, e);            foreach (WebTestRequest r in e.Request.DependentRequests)            {                r.PostRequest += new System.EventHandler<PostRequestEventArgs>(r_PostRequest);            }        }        void r_PostRequest(object sender, PostRequestEventArgs e)        {            if(e.Response.StatusCode == System.Net.HttpStatusCode.NotFound)            {                e.Request.Outcome = Outcome.Pass;                System.Diagnostics.Debug.WriteLine("Dependent request not found: " + e.Request.Url);            }        }    } </code>

  • Anonymous
    December 11, 2011
    Dear ED , Your notes is very helpful  for my web test.

  • Anonymous
    April 24, 2012
    Thank you! This was really helpful!

  • Anonymous
    May 31, 2012
    Really great solution.helped me alot.

  • Anonymous
    November 13, 2012
    Hi Rom, could you please explain how to run this plugin to parse all sites before testing?  I already created the plugin and inserted it to my  Web Test Plug-Ins for the webtest level.  but this is doing nothing and the test keeps failing with 404 error.  I am sure I am missing something but I can't find an explanation.   I would appreciate your help

  • Anonymous
    May 19, 2014
    Nice Article and it helped me a lot !!

  • Anonymous
    July 21, 2014
    Hi ED The above process for Masking a 404 error was really helpful. But say if the dependent request are dynamic ( by which I mean it keeps changing) and throw a 404 (as image do not exist) then how to mask those error? Thank you in advance.

  • Anonymous
    August 04, 2014
    It was really useful. Thanks.

  • Anonymous
    August 07, 2014
    @parul, see Rom's request plugin code above. It will handle dynamic dependent requests. Ed.

  • Anonymous
    September 08, 2014
    Its giving an error "Validate Response Code Validation '200 - OK' does not match the expected status '404 - NotFound'."

  • Anonymous
    October 05, 2014
    The comment has been removed

  • Anonymous
    October 20, 2014
    You could change the poperty of Parse dependent requests to false on web requests

  • Anonymous
    November 23, 2015
    I am following the same approach which is described by ED Glas in his screenshot but not able to fix the issue. Anybody can help me how to resolve this one in other way.

  • Anonymous
    January 04, 2016
    This also will not work if you are using variables for servers: I.e. {{server}}/Pops/Styles/font-awesome.css If the dependent calls need to be run the should be recorded with everything else (like jmeter does).  Or perhaps a way to ignore the response codes to dependent calls altogether, but still call them.