Generic Http waitFor() function.

Jul 8, 2010 at 10:58 PM
Edited Jul 12, 2010 at 8:50 PM

I recently created a really useful async WaitFor() functionality built around fiddler core that can be used to wait for a specific http traffic. I would be happy to share the source code. I think it would be a super helpful function to have built into Test API. It would require a hard dependency on fiddler core though.

I'll post a couple example usages... I'm mainly using an overload that takes a partial string match but you can create your own parse delegate and have the class call you with URL's until you find what your looking for. So it's extremly generic.

Example usage: Subscribe to an event, do an action to trigger a web response and wait for the url.

 ITdrEvent webTrends = Common.Utilities.Tdr.SubscribeToEvent(TdrExposedEvents.BeforeResponse, "webtrends");

//Do action to trigger URL, then wait for the url.

 Uri webTrendsUrl = webTrends.Wait(TimeSpan.FromSeconds(30));

Example usage: Wait for Multiple URL's Subscribe to an event, do an action to trigger a web response and wait for the url.

 ITdrEvent webTrends = Common.Utilities.Tdr.SubscribeToEvents(TdrExposedEvents.BeforeRequest, 3, "m.webtrends");

 ITdrEvent sqm = Common.Utilities.Tdr.SubscribeToEvents(TdrExposedEvents.BeforeRequest,"sqm.microsoft.com");

UserExperience.Client.Start();

List<Uri> webTrendsUrls = webTrends.Wait();

Uri sqmUrl = sqm.Wait();

UserExperience.Client.Close();

Common.Verify.IsTrue(webTrendsUrls.Count == 3, "webTrendsUrls Should be 3!");

Common.Verify.IsNotNull(sqmUrl), "sqmUrls Should not be null!");

Example usage: anon delegate callback. Basically works like a light switch. It keeps feeding you URL's until you return true or time out.

        ITdrEvent webTrends = Common.Utilities.Tdr.SubscribeToEvent(delegate(Uri url) { return url.OriginalString.Contains("PartialTextImLookingFor"); });

 //Do action to trigger URL, then wait for the url.

Uri webTrendsUrl = webTrends.Wait(TimeSpan.FromSeconds(30));

 

 

Jul 12, 2010 at 12:01 AM

Oliman,

Thanks for the idea! We'll look into whether we can take a dependency on Fiddler.

Ivo

Jul 12, 2010 at 8:49 PM

Just a quick note. You would only need to take a dependency on Fiddler Core which is a single dll that exposes the core functionality of Fiddler.

Jul 15, 2010 at 11:22 PM
oliman wrote:

Just a quick note. You would only need to take a dependency on Fiddler Core which is a single dll that exposes the core functionality of Fiddler.

Thanks Oliman.

We will look into it (obviously part of the complexity here is releasing Fiddler Core's source code too)

Ivo