Working with WebTests

Wednesday, September 6th, 2006 | .NET

I have found very few articles on how to make customized WebTest with Visual Studio 2005 Team Edition for Testers or Visual Studio 2005 Team Suite. However, I bumped into this great article that show some of the more advanced techniques for authoring advanced and custom WebTests.

The article had excatly what I needed. My goal is to make a crawler that fetches most of the URL's on a website. This is useful for testing resources on the server when content is cached. Hitting the same page over and over again is not useful for testing memory resources. The test must fill the cache to it's limits and then we can see what performance the users will experience.

If the article is removed (or the server is down), here is the example code I used. I have of course modified it (removed links to external pages, javascripts, CSS/Images, etc.) to match the site I am running the test against, but the core code is the same.

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.VisualStudio.TestTools.WebTesting;

public class LoopingCoded : WebTest

{

public LoopingCoded()

{

}

public override IEnumerator<WebTestRequest> GetRequestEnumerator()

{

// Issue a search for the term "Microsoft"

WebTestRequest request7 = new WebTestRequest("http://testserver/website/Search.aspx");

request7.ThinkTime = 20;

request7.Method = "POST";

FormPostHttpBody request7Body = new FormPostHttpBody();

request7Body.FormPostParameters.Add("txtSearch", "Microsoft");

request7.Body = request7Body;

yield return request7;

// Loop through each anchor tag in the search result and issue a request to each tag's target url (href)

foreach (HtmlTag tag in this.LastResponse.HtmlDocument.GetFilteredHtmlTags("a"))

{

WebTestRequest loopRequest = new WebTestRequest(tag.GetAttributeValueAsString("href"));

yield return loopRequest;

}

}

}


Tags:

No comments yet.

Leave a comment

Search

Knut Hamang

This is the official site for Knut Hamang. I am a professional technical consultant specialized in Microsoft and .NET technologies and platforms. I work as an independent consultant in Norway and have more than 10 years of professional experience. To get in contact with me, please send me an email or check my public profile on View Knut Hamang's profile on LinkedIn