Quick Resource Box
The technique described in the post exploits fantastic Custom Extraction Rule extensibility options in Visual Studio 2008. It also proves once more endless usefulness of Fiddler.
The Challenge – Web Test Does Not Record File Upload
Our main scenario required to upload files to the web server. Quick search on the web revealed Ed Glas’ post How to upload a file in a Web test. The future looked great. When we followed the steps outlined in the post our Web Test kept failing in recording the file to be uploaded preventing the automation of the load test.
and then add the Web Test to the solution in Visual Studio (right click on the Project in Solution Explorer-> Add-> Existing Item…).
Creating Custom Extract Rule
When we inspected the capture in Visual Studio we observed the following String Body header that actually was the uploaded file’s contents:
We decided to create custom Extraction Rule that would first extract the user name – the name of the files included user name – and based on it look up related file, then read its contents into context parameter. Later on we used the context parameter to dynamically add the file contents to the request:
The rule itself looked similar to this:
public class FileContentExtractorData : ExtractionRule