Sample Custom Validation and Extraction Rules for Web Tests in Visual Studio Team System 2008

If you haven't seen Web Tests in Visual Studio 2008 Team Suite and Tester Edition (aka. Visual Studio Team System), you really should do yourself a favor and take a look.  They allow you to write and record unit tests that will exercise and validate a running web application or web site. 

The basic idea is that you record a path though an ASP.NET application and the web test recorder records the requests and responses to/from the server.  Once you have the basic recorded test, you can then customize it to send different data to vary your test and also add validation and extraction rules to check that you're getting the response you expect from the application.

The out-of-the-box validation and extraction rules are pretty good but are really just the start of what you'll need to validate your running app.  If you're going to invest time in creating web tests, you'll definitely need rules other than what comes with VSTS.

Here are some of the custom validation and extraction rules that I've written and use regularly:

  • Validate ASP.NET Label Value
  • Extract ASP.NET Label Value
  • Validate ASP.NET GridView Row Count
  • Extract ASP.NET GridView Row Count
  • Text Exists Inside of HTML Tag

Downloads:

To use the rules in your VSTS Web Tests, download the binaries, and add references from your VSTS Unit Test project to both of the DLLs in the zip: HtmlAgilityPack.dll and Com.Benday.WebTesting.WebTestRules.dll.  Once you've added the reference, these rules should show up in the Add Validation Rule and Add Extraction Rule dialogs.

Here's an image of the Add Validation Rule dialog with the custom rules are circled in red.

image

Here's an image of the Add Extraction Rule dialog with the custom rules are circled in red. 

image 

-Ben

 

If you're looking for help installing or configuring Team Foundation Server or want guidance on using and adopting Visual Studio Team System, please contact me via http://www.benday.com.

posted @ Wednesday, May 28, 2008 11:37 AM

Print

Comments on this entry:

# Slides from VSLive Dallas 2008: WiX, LINQ to SQL Architecture, Web Testing, Windows Azure

Left by Benjamin Day Consulting, Inc.: The Blog at 12/20/2008 7:57 AM
Gravatar
Slides from VSLive Dallas 2008: WiX, LINQ to SQL Architecture, Web Testing, Windows Azure

# re: Sample Custom Validation and Extraction Rules for Web Tests in Visual Studio Team System 2008

Left by Quoc Thanh at 2/22/2009 9:55 PM
Gravatar
Hi Benjamin, your example is very useful for me. Can you help me some more by let me know how I can generate web test and use this code for NUnit test. I can generate one webtest ( file aaa.webtest) to code ( file aaa.cs). But I don't know how to validate on this code and get result via NUnit test. Please send me example. Thanks so much.
Quoc Thanh

# re: Sample Custom Validation and Extraction Rules for Web Tests in Visual Studio Team System 2008

Left by Quoc Thanh at 3/3/2009 11:24 PM
Gravatar
Hi Benjamin,
Thanks for your reply. Have you any advance example about the validate and extractor. I'm investigating how to retrieve the value in form post parameter.
Please help me. Thanks so much.

# New Features in Visual Studio Team System 2010 (VSTS2010) Web Tests

Left by Benjamin Day Consulting, Inc.: The Blog at 6/27/2009 10:38 AM
Gravatar
New Features in Visual Studio Team System 2010 (VSTS2010) Web Tests

# re: Sample Custom Validation and Extraction Rules for Web Tests in Visual Studio Team System 2008

Left by Rick at 10/1/2009 3:19 PM
Gravatar
Hi Benjamin,

Your "Sample web app with web tests, custom web test rules, plus source code" solution has problem opening in my box(VSTS 2008/SQLEXPRESS 2005/XP PRO), will you mind email me with the instruction on how to do the initial setup/config, or any prerequirement notes can be really helpful to me:

2 Projects unable to open properly: Com.Benday.WebTesting.Database & Com.Benday.WebTesting.WebUI

Thanks a lot,
-Rick

Your comment:



 (will not be displayed)


 
 
 
Please add 7 and 4 and type the answer here:
 

Live Comment Preview:

 
«March»
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910