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.

2. Add Dependent Request
You can add this request manually and then set the "Expected HTTP Status Code" to 404.
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))
{
DependentToRemove.Add(req);
}
}
foreach (WebTestRequest dependent in DependentToRemove)
{
e.Request.DependentRequests.Remove(dependent);
}
}
}
}