How can I tell a Web Test to ignore 404 errors?


How can I tell a Web Test to ignore 404 errors?

Some times your web test failed because a missing image or old file that not longer exists in the IIS.

Why the Web Test fail all the test because one missing Image?  Your absolutely Right!

I’ll show 3 different ways to solve this.

1. Expected HTTP Status Code

The First thing you can do is to set “Expected HTTP Status Code” to 404.

But this will not work if the bad request is a dependent request.

Expected HTTP Status Code

2. Add Dependent Request

You can add this request manually and then set the “Expected HTTP Status Code” to 404.

Add Dependent Request

3. Write WebTestPlugin

But if those not working because different requests and other parameters you can use WebTestPlugin

In the sample bellow the Plugin searches for the right dependent and remove it from the WebTest,
like this you can run a web Test with 404 request and still make the WebTest to Pass

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.VisualStudio.TestTools.WebTesting.Rules;

using Microsoft.VisualStudio.TestTools.WebTesting;

using System.ComponentModel;


namespace TestProject


    [DisplayName(“Dependent Request Plugin”)]

    public class DependentPlugin : WebTestPlugin


        string dependent = “badimage.gif”;


        public override void PostRequest(object sender, PostRequestEventArgs e)


            WebTestRequestCollection DependentToRemove = new WebTestRequestCollection();


            foreach (WebTestRequest req in e.Request.DependentRequests)


                if (!string.IsNullOrEmpty(dependent) && r.Url.EndsWith(dependent))






            foreach (WebTestRequest dependent in DependentToRemove)







Add comment
facebook linkedin twitter email

Leave a Reply


  1. Ashok Reddy11/12/2008 ב 04:31

    How do I make web test tool wait till data gets loaded in the web page? I tried by setting the Think Time but it is not working. Could you please advice me on this issue

  2. Shai Raiten11/12/2008 ב 07:24


    What is precisely the problem?

    When you run web test the requests are fired up only after the request before is finished loading.

  3. Lohmar ASHAR15/04/2009 ב 17:44

    Thanks a lot, I’ve found on this page exactly what I’ve needed. You’ve been more helpful than the Microsoft Support.

  4. MIck_at_Oz17/07/2009 ב 02:58

    Dependent requests that tries to hit a dynamically generated JS/CSS file could not be found. I dont want the system to just ignore these, I want the test to simulate the “real world”. Any ideas ?

  5. Shahid07/08/2009 ב 18:53

    This is great – really helped me!

    One error though in your code:

    if (!string.IsNullOrEmpty(dependent) && r.Url.EndsWith(dependent))

    Should read:

    if (!string.IsNullOrEmpty(dependent) && req.Url.EndsWith(dependent))

    Not a C# programmer so a bit hard to work out for me.