I l @ ve RuBoard |
The following sections offer a quick reference to a few common tasks that you'll most likely want to do in your ACT test once you've decided that you want to customize it. You can easily use these functions in your own tests. Inserting Random Delay into Your TestsUsing random delays is an important part of performance testing. It allows the test to provide a more even loading of a site under test. Without adding delays, you'd generate many simultaneous, and possibly identical, requests . This would be an unrealistic way to stress a site and would increase the possibility of hitting a "hot spot" in your database, leading you to chase down performance " bugs " that are not very interesting. (Who cares if your application performs poorly if a single user generates the same 1000 requests simultaneously ? It's just not realistic.) Spreading out your requests provides a more realistic stimulus for your application. The following code sample demonstrates how you can implement a sub that produces a random delay in a test (within certain boundaries specified by the MIN_DELAY and MAX_DELAY constants). ConstMAX_DELAY=500 ConstMIN_DELAY=0 DimInitRand SubDelay() IfInitRandThen Randomize() InitRand=false EndIf Test.Sleep((MAX_DELAY-MIN_DELAY)*Rnd())+MIN_DELAY EndSub Extracting ASP.NET ViewState from the Response ObjectViewState is an important component of ASP.NET WebForm objects. The ViewState is contained in the HTML of a Web page within a hidden form field with the name __VIEWSTATE . The following code shows you how to extract the ViewState from the Response object. You can then use this information when you create a post-back request to the WebForm . FunctionGetViewState(oResponse) DimPos,PosStart,PosEnd If(oResponseIsNothing)Then Test.Trace "TheresponsewasNothing" &vbcrlf Else Pos=InStr(oResponse.Body, "__VIEWSTATE") IfPos>0Then PosStart=InStr(Pos,oResponse.Body, "value=""") PosStart=PosStart+Len("value=""") PosEnd=InStr(PosStart,oResponse.Body, """") GetViewState=Mid(oResponse.Body,PosStart,PosEnd-PosStart) EndIf EndIf EndSub Appending ASP.NET ViewState to a RequestThe following code sample shows you how to insert the ViewState into the contents of the Request object: SubSetViewState(oRequest,viewState) If(oRequestIsNothing)Then Test.Trace "TherequestobjectwasNothing" &vbcrlf Else oRequest.Body=oRequest.Body&vbcrlf&_ "__VIEWSTATE=" &viewState&vbcrlf EndIf EndSub |
I l @ ve RuBoard |