几段ACT测试脚本

以下是使用 SendRequest 方法的动态测试的一个示例。这是向服务器发送请求的最简便的方法,因为它在一个调用中创建并发送请求。并且与 Web 服务器的连接是自动打开的。

连接错误或无效的请求将会导致 SendRequest 方法返回一个空对象。在尝试使用 Response 对象属性之前,请先检查有无错误。

Sub SendRequestExample
Dim oResponse
Set oResponse = Test.SendRequest("http://localhost/default.asp")
' check for a bad connection or request
If (oResponse Is Nothing) Then
Test.Trace("Error: invalid request or host not found ")
Else
'Process the response
If oResponse.ResultCode <> "200" Then
Call Test.Trace("The Response time was " & CStr(oResponse.TTFB))
End If
End If
End Sub
Sub SendRequest34()
    Dim oConnection, oRequest, oResponse, oHeaders, strStatusCode
    If fEnableDelays = True then Test.Sleep (747)
    Set oConnection = Test.CreateConnection("st-02", 8080, false)
    If (oConnection is Nothing) Then
        Test.Trace "Error: Unable to create connection to st-02"
    Else
        Set oRequest = Test.CreateRequest
        oRequest.Path = "/edudata/dwr/exec/ReportUtil.getStudentList.dwr"
        oRequest.Verb = "POST"
        oRequest.HTTPVersion = "HTTP/1.0"
        oRequest.EncodeBody = False
        set oHeaders = oRequest.Headers
        oHeaders.RemoveAll
        oHeaders.Add "Accept", "*/*"
        oHeaders.Add "Content-Type", "text/plain"
        oHeaders.Add "Referer", "http://st-02:8080/edudata/reportInputAction.do?funcId=300110"
        oHeaders.Add "Accept-Language", "zh-cn"
        oHeaders.Add "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322)"
        'oHeaders.Add "Host", "st-02:8080"
        oHeaders.Add "Host", "(automatic)"
        oHeaders.Add "Pragma", "no-cache"
        'oHeaders.Add "Cookie", "JSESSIONID=BE67380BB76FDAF38800EB91CB2C1452"
        oHeaders.Add "Cookie", "(automatic)"
        oHeaders.Add "Content-Length", "(automatic)"
        oRequest.Body = "callCount=1"+chr(10)+"c0-scriptName=ReportUtil"+chr(10)+"c0-methodName"
        oRequest.Body = oRequest.Body + "=getStudentList"+chr(10)+"c0-id=5571_1153277525765"+chr(10)+"c0-param0"
        oRequest.Body = oRequest.Body + "=string:100022"+chr(10)+"c0-param1=number:0"+chr(10)+"xml=true"+chr(10)
        Set oResponse = oConnection.Send(oRequest)
        If (oResponse is Nothing) Then
            Test.Trace "Error: Failed to receive response for URL to " + "/edudata/dwr/exec/ReportUtil.getStudentList.dwr"
        Else
            strStatusCode = oResponse.ResultCode
        End If
        oConnection.Close
    End If
End Sub
Sub Main()

    call SendRequest34()
End Sub
Main
 

posted on 2006-08-07 10:43  测试者家园  阅读(2169)  评论(0编辑  收藏  举报

导航