I've been working with Team System to try and do some load testing against some 1.1 Framework code we have under development
I created a new webTest (recorded) against our development site. I was pleasantly surprised at how well it worked. I decided I wasn't
going to be able to use the default test because it didn't give me enough control over the request/response. I needed to pull some information out of one response to pass to the next request. Looking at the
WebTest tab (form?) I found a couple of buttons:
Add Test Callout
Add Request Callout
That sounded interesting. Unfortunately both throw an error when you click them:
There were no classes implementing IWebTestCallbacks found in any of the following assemblies
The error goes on to list the assemblies it searched for the interface. I fired up Reflector and verified that it couldn't find the interface either (which it didn't).
The interface is declared in: Microsoft.VisualStudio.QualityTools.LoadTest.dll which lives:
\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies
The interface defines two methods:
void PostWebTestCallback(PostWebTestEventArgs e);
void PreWebTestCallback(PreWebTestEventArgs e);
PostWebTestEventArgs also looks interesting:
It contains a Context property returning a Hashtable
and a WebTest properties which returns (naturally) a WebTest
There are number of intruiging assemblies in this folder along with the PublicAssemblies folder. I haven't had time to go through all of them yet. I still hadn't found an answer to my problem so I decided to try a different tact.
If you look at the webTest folder (form?) and right click on any given request you get a context menu with a number of features. One of which was Add Extraction Rule. If you select this one and then click on the Class property in the
property page you get a pop-up asking for a class. Your options are:
ExtractionRuleAttributeValue
ExtractionRuleHeader
Neither one of these gave me what I wanted so I removed them and kept looking.
One of the features of this part of Team System is the ability to generate the test code. Click on the Generate Code button and a class is automatically created for you with the test code.
What is really interesting about this class is that it is just the request specific information. It uses the Generics feature(s) of the 2.0 framework and the new yield keyword to create and
return a WebTestRequest object.
public overrideIEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest request1 = new WebTestRequest("http://testSite/login.aspx");
request1.ThinkTime = 11;
yield return request1;
WebTestRequest request2 =repeat for next request . . .
}
WebRequest has two promising looking events: PostRequest and PreRequest.
I hooked up the PostRequest:
request1.PostRequest+= new PostRequestEventHandler(PostRequest1);
declared as:
private void PostRequest1(PostRequestEventArgs e)
The PostRequestEventArgs object has accessors to both the Request and Response objects. At that point I can get any information from
the post Response that I wanted.
Debugging your test code
I couldn't get the IDE to launch into something I could debug so in order to debug my custom test code I did the following:
- Compiled the test project
- Moved the assembly to \Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies folder
- Set a breakpoint inside my event (PostRequest1)
- Started the Test -- immediately hit pause as soon as the pause button was enabled
To start a test use the test explorer and select (check) the custom test code
Make sure you check the Execute Test run in a separate process check box on the Deployment tab of the dialog that pops up
- Debug -> Attached to Process -->vsTestHost.exe You might have to check show all processes
It definately isn't the ideal way to get into a good debug state. If anyone has a better way I'd love to hear about it.
|