Working with WebTests
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;
}
}
}
No comments yet.
Leave a comment
Search
Knut Hamang
Recent Posts
Recent Comments
- Lori on Html to Pdf in .NET
- Susan on Html to Pdf in .NET
- Susan on Html to Pdf in .NET
- Ananth on Html to Pdf in .NET
- Tim M on Passing an object to ObjectDataSource