(Update August 5, 2014: The latest version now has the ability to do math as part of your web performance and load tests.)
I’ve been doing a lot of work with Visual Studio 2012 Web Performance Tests and as part of that, I’ve written a handful of custom Validation Rules and Extraction Rules. I think they’re pretty useful so I figured I’d share them out.
In the zip file for this blog post, you’ll find a very simple sample application and a Web & Load Test project that contains a web test that uses all of these rules. The sample web test is called SampleWebTest.webtest. The screenshot below shows you the validation rules and extraction rules in this web test.
Validation Rule: SleepValidationRule
This rule doesn’t actually do any validation but it hooks into the WPT execution and causes the WPT to wait for a given number of milliseconds. Under the surface, it’s executing a C# Thread.Sleep() call. This is helpful for slowing down your test a little (or a lot) for when you’re trying to test asynchronous logic. In the Properties dialog below, the validation rule will sleep for ‘1000’ milliseconds.
Validation Rule: TableColumnValueValidator
Looks at a <table> and verifies that a value exists in a table in a given column. The Properties dialog below will look for a table with an id of ‘m_grid’ and check to see if the ‘Artist’ column contains the value ‘Branford Marsalis’ in one of the rows.
Extraction Rule: ExtractRandomValueFromTable
This extraction rule looks the columns in an html <table> and extracts a column value from a random row. This is helpful for Load Tests where you want to simulate multiple users clicking through your application and viewing different data. This helps you to avoid hardcoding the same records over and over again and gives some variety to which records are being worked with by your Load Test’s virtual users. In the Properties dialog below, the rule will look for a table with an id of ‘m_grid’ and randomly pull a value from the ‘Id’ column and put it into the ‘RandomIdValue’ context parameter.
Extraction Rule: ExtractResponseContainsString
This extraction rule looks at the text of the HTTP Response for the Web Test and looks to see if a particular value exists. If the value exists, it will set the context parameter to be ‘true’. If it doesn’t exist, it will set the context parameter to ‘false’. In the Properties dialog below, this will look in the response for the string ‘Crazy’ and set true or false into the ‘DoesCrazyExistInTheResponse’ context parameter variable.
Extraction Rule: ExtractResponseUrlFilename
This rule looks at the URL for the web test request and extracts the filename portion of the URL. This is helpful for verifying the name of the file where the web performance test ends up after following a number of HTTP redirects. In the Properties dialog below, this request will extract the filename from the URL to a context parameter named ResponseFilename.
Extraction Rule: LabelValueExtractor
This extraction rule will extract the value of an ASP.NET Web Forms Label control and put the value into a context parameter. In the Properties dialog below, the rule will look for a Label control named ‘m_labelRowCount’ and store the value in a context parameter named ‘RecordCount’.
I hope you find this useful.
— Got performance problems in your application? Need some help creating load tests with Visual Studio 2012? Want some training on how to create Web Performance Tests and Load Tests with Visual Studio 2012 or Visual Studio 2013? Drop us a line at email@example.com.