New in Orcas! Filtering Dependent Requests
The relevant order of execution in the web test engine with regards to dependent filtering looks like this:
- Top Level Request Runs
- DependentRequests collection on the Request is populated now
- Top Level Requests PostRequest event is fired
- Dependent Requests Run.
So if you want to filter requests you actually have to do it in the Top level requests PostRequest event handler rather than the PreRequest which may seem more intuitive at first.
Now on to the code sample, below is a very simple coded web test. It has one request which is against www.msn.com. As you can imagine this site loads a bunch of dependent requests but in my example below I’ll iterate over the dependent requests and remove all the gif and jpg requests from the collection. The code should probably be cleaned up a bit and could be written more efficiently for use in a Loadtest I’m sure but as a quick sample it should demonstrate the concept.
public class WebTest1Coded : WebTest
this.PreAuthenticate = true;
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
WebTestRequest request1 = new WebTestRequest("http://www.msn.com/");
request1.ThinkTime = 1;
request1.PostRequest += new EventHandler<PostRequestEventArgs>(request1_PostRequest);
yield return request1;
request1 = null;
void request1_PostRequest(object sender, PostRequestEventArgs e)
//I'll store the index within the collection for each dependent I
//want to remove from the collection.
List<int> dependentsToRemoveByIndex = new List<int>();
//Now we'll iterate over the DependentRequests collection and
//Examine each one and decide whether we want to remove it
//or not, in this example I'm removing anything that has a
//url that ends with .gif or .jpg.
for(int i=0; i < e.Request.DependentRequests.Count; i++)
string requestUrl = e.Request.DependentRequests[i].Url;
if (requestUrl.EndsWith(".gif") || requestUrl.EndsWith(".jpg"))
//Now I'll iterate over my collection of indexes to remove and
//remove them from the DependentRequests collection.
for (int i = dependentsToRemoveByIndex.Count - 1; i >= 0; i--)