Walking Through the ACT Script
In this section, we walk through the script generated by the test wizard earlier today. A request routine is generated for each item on the page being browsed. These requests include the main page and each image, for example. In the simple example you created, you browsed only the main page, which did not contain any other objects and is the first SendRequest1() for the main page.The first thing to note is that this is VBScript and all variables are declared without a data type and re-created as variants, which is the only data type in VBScript.
Option Explicit
Dim fEnableDelays
fEnableDelays = False
Sub SendRequest1()
The Dim also highlights the main objects of interest in ACT, the Connection, Request, Response, and Header objects:
Dim oConnection, oRequest, oResponse, oHeaders, strStatusCode
It's possible to set up delays between each request. Call it "think time" on the part of the client for a more realistic load:
If fEnableDelays = True then Test.Sleep (0)
Connections can fail for various reasons. Before proceeding, always make sure that the connection is created:
Set oConnection = Test.CreateConnection("localhost", 80, false)
If (oConnection is Nothing) Then
Test.Trace "Error: Unable to create connection to www localhost "
Else
This and all the other requests in this example are GET. Other request verbs are OPTIONS, HEAD, POST, PUT, DELETE, TRACE, and CONNECT:
Set oRequest = Test.CreateRequest
oRequest.Path = "/"
oRequest.Verb = "GET"
oRequest.HTTPVersion = "HTTP/1.0"
This section resets the header to accept a list of types, some explicitly and some generic (*/*):
set oHeaders = oRequest.Headers
oHeaders.RemoveAll
oHeaders.Add "Accept", "image/gif, image/x-xbitmap,
image/jpeg, image/pjpeg, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*"
oHeaders.Add "Accept-Language", "en-us"
Cookies that are supported and are under the control of code can be edited and manipulated using the test object. This shows a cookie has been detected but not explicitly manipulated:
'oHeaders.Add "Cookie", "ASP.NET_SessionId=ivzrqjj5vmua2v55foswsti1"
oHeaders.Add "Cookie", "(automatic)"
oHeaders.Add "User-Agent", "Mozilla/4.0 (compatible;
MSIE 6.0; Windows NT 5.0; Q312461;
.NET CLR 1.0.3705; .NET CLR 1.0.2914)"
'oHeaders.Add "Host", "localhost"
oHeaders.Add "Host", "(automatic)"
oHeaders.Add "Cookie", "(automatic)"
A response is expected by executing the Send request of the connection. It's possible that the connection has died or that there's some other reason the target server can't be contacted.
Set oResponse = oConnection.Send(oRequest)
If (oResponse is Nothing) Then
Test.Trace "Error: Failed to receive response for URL to "
+ "/ActWebTest/WebForm1.aspx"
Else
The response codes returned are standard. Table 19.1 lists the return codes and their descriptions.
Return Code Range | Description |
---|---|
100 to 199 | Informational messages |
200 to 299 | Successful request |
300 to 399 | Redirection occurred |
400 to 499 | Client error |
500 to 599 | Server error |
strStatusCode = oResponse.ResultCode
End If
oConnection.Close
End If
End Sub
Sub Main()
call SendRequest1()
End Sub
As you can see, the results in the script are very useful in determining what the macro has recorded and what steps the application is running.
Understanding the Test Environment
For simple regression testing of the functionality of your Web project on a development machine, the test environment isn't critical. But if you want to get repeatable performance results you can build on and compare with future testing, you must carefully set up a testing environment.Some issues you might face are
- Providing enough load
- Isolating test machines
- Identifying bottlenecks in test environment
Here are some general rules for a test environment that will give you consistent results:
- The test environment must be isolated and contain only development or test Web servers. No production servers should be used unless other traffic has been shut off.
- A separate network should be set up so that broadcasts, probes, inadvertent file transfers, and any other unanticipated network traffic don't take place.
- The recommendation for stress testing is that the Web server's processor utilization be driven to at least 80%. This might not be possible using a single client computer.
- You can remove or minimize network bottlenecks by using the fastest possible components and avoiding the use of proxy servers or other protocols that require unnecessary overhead.
- To fully stress a Web application, you must increase the load until the Web server becomes the bottleneck and prevents further increases. If any part of the system is slower than the Web server or Web applications, it's impossible to measure the maximum.
Load Created by an ACT Client
The amount of load created by an ACT client varies and depends on many factors. As an example, the following test environment from the documentation shown in Table 19.2 might provide some guidance for setting up your own system.
Configured Item | Details |
---|---|
Software | Windows 2000 Server |
Processor | 600MHz Pentium III |
Memory | 128MB |
Configured Item | Details |
---|---|
Software | Windows 2000 Advanced Server running IIS 5.0 |
Processor | 650MHz Pentium III |
Memory | 256MB |
Scheduling Tests
Scheduling of tests can be done so that heaving loading can be done off hours and unattended. This is done by writing a Windows Scripting Host (WSH) script and then running it with the AT command.Here's a sample script to run the test you've been working on:
Dim oProject, oController
'
' Create a project based on the existing project we have been working on
'
Set oProject =
OpenMyProject("C:\Inetpub\wwwroot\ACTProject1", "ACTProject1.act")
Set oController = CreateObject("ACT.Controller")
'
' This is the "main" script routine
'
Call RunMyTest(oProject, "ACT-VBSTest1", oController)
Set oController = nothing
Set oProject = nothing
'
' End of main script
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Open ACT project.
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function OpenMyProject(strProjectPath, strProjectFileName)
'
Dim oProject
'
' Ignore all errors
'
On Error Resume Next
'
' Create a new project object
'
Set oProject = CreateObject("ACT.Project")
'
' If it did not get created, report an error (should log this!)
'
If (Not(IsObject(oProject))) Then
WScript.Echo("Error creating project object")
Call WScript.Quit()
Else
'
' Open the our project
'
Call oProject.Open(strProjectPath, strProjectFileName, False)
'
' Check for errors, exit if there are any
'
If (Err.Number > 0) Then
WScript.Echo("Error opening project
Path=" & strProjectPath & ", File=" & strProjectFileName)
Call WScript.Quit()
End If
End If
'
' Return the opened project
'
Set OpenMyProject = oProject
'
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Run Act Test
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub RunMyTest(oProject, strTestName, oController)
Dim oTest, bIsRunning
'
' Make sure that a test is not already running
'
bIsRunning = oController.TestIsRunning
'
If bIsRunning Then
WScript.Echo("ACT is already running a test.")
Else
'
' Get the test out of the tests collection of the project
'
Set oTest = oProject.Tests.Item(strTestName)
WScript.Echo("Test Start")
Call oController.StartTest(oProject, oTest, False)
WScript.Echo("Test End")
End If
End Sub
Now you can use the AT command to schedule the task, as the following code demonstrates:
AT 19:30 /interactive /every:M,T,W,Th,F
cscript.exe "c:\Tests\WeekdayStressTest.vbs"