http://blog.sina.com.cn/s/blog_5007d1b10100ly5c.html
最近浏览中突然发现,”运行QTP测试脚本后,将编译结果写入指定文件“ 系列中没有附上 Print的脚本,再次补充上。大家可以按一下顺序阅读,希望对大家能有帮助。
'*************************************************************'
'声明一个类
'*************************************************************'
Class RunLog
Dim ver_pass
Dim ver_fail
'Test_Path=left(environment.Value("TestDir"),Instr(1, environment.Value("TestDir"), "测试脚本", 0)-1)
'*************************************************************'
'函数/过程名称:ini_class
'函数/过程的目的:初始化日志系统
'假设:无
'影响:创建日志文件,初始化日志中的变量
'输入:无
'返回值:无
'创建者:lee
'创建时间:2010/09/11
'修改者:
'修改原因:
'修改时间:
'*************************************************************'
Public Sub ini_class ()
ver_pass=0
ver_fail=0
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fileSystemObj, fileSpec
Dim currentTime
currentDate = Date
currentTime = Time
testName = environment.Value("TestName")
Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
fileSpec =Test_Path&"测试记录\"&testName& ".txt"
If Not (fileSystemObj.FileExists(filespec)) Then
'ForWriting是否需要,OpenWriting
'Set logFile = fileSystemObj.CreateTextFile(fileSpec, ForWriting, True)
Set logFile = fileSystemObj.OpenTextFile(fileSpec, ForWriting, True)
'Set logFile = fileSystemObj.CreateTextFile(fileSpec,True)
logFile.Close
Set logFile = Nothing
End If
End Sub
'*************************************************************'
'函数/过程名称:Verficaiton
'函数/过程的目的:对比实际值和期望值,并输出信息
'假设:无
'影响:写入日志系统
'输入:期望值,实际值,成功信息,失败信息
'返回值:无
'创建者:lee
'创建时间:2010/09/11
'修改者:
'修改原因:
'修改时间:
'elog.Verficaiton ("True",CStr(sFlag),"达到短信息最大数,错误信息输出正确。","达到短信息最大数,错误信息输出正确。")
'*************************************************************'
Public Sub Verficaiton(sExpect ,sAct,sSuccess,sFail)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fileSystemObj, fileSpec
Dim currentTime
currentDate = Date
currentTime = Time
testName = environment.Value("TestName")
Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
fileSpec =Test_Path&"测试记录\"&testName& ".txt"
Set logFile = fileSystemObj.OpenTextFile(fileSpec, ForWriting, False, True)
If sExpect=sAct Then
logFile.WriteLine ("Successful:" & sSuccess)
logFile.WriteLine ("******" )
logFile.writeFile ("******")
LogFile.writeFile ("####被测对象:注册页面#####")
logFile.writeFile ("######测试者:某某某 ######")
logFile.writeFile ("##### 测试日期: " + cstr(currentDate) + cstr(currentTime) + " ####")
logFile.writeFile ("######################")
ver_pass=ver_pass+1
else
logFile.WriteLine ("######被测对象:注册页面######")
logFile.WriteLine ("#####测试者:某某某########")
logFile.WriteLine ("Fail:"&environment.Value("TestName")&">>"¤tDate& currentTime )
logFile.WriteLine (">>>>The error message>>>> : " & sFail)
logFile.WriteLine (">>>>The expect result is>>>> : " & sExpect)
logFile.WriteLine (">>>>The actual result is :>>> " & sAct)
logFile.WriteLine ("******************************" )
ver_fail=ver_fail+1
End If
logFile.Close
Set logFile = Nothing
Set fileSystemObj = Nothing
End Sub
'*************************************************************'
'函数/过程名称:class_terminate
'函数/过程的目的:打印执行情况
'假设:无
'影响:得到成功和失败的测试点
'输入:无
'返回值:无
'创建者:lee
'创建时间:2010/09/11
'修改者:
'修改原因:
'修改时间:
'*************************************************************'
Sub class_terminate ()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fileSystemObj, fileSpec
Dim currentTime
currentDate = Date
currentTime = Time
testName =environment.Value("TestName")
Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
fileSpec =Test_Path&"测试记录\"&testName& ".txt"
Set logFile = fileSystemObj.OpenTextFile(fileSpec, ForAppending, False, True)
logFile.WriteLine ("#######################################################################")
logFile.WriteLine (currentDate & currentTime & " Test: " & environment.Value("TestName") )
logFile.WriteLine ("The successful check point is>> " & ver_pass)
logFile.WriteLine ("The fail check point is >>" & ver_fail)
logFile.WriteLine ("#######################################################################")
logFile.Close
Set logFile = Nothing
Set fileSystemObj = Nothing
End Sub
End Class
set elog=new RunLog
本文转自hblxp32151CTO博客,原文链接:http://blog.51cto.com/starpoint/584052,如需转载请自行联系原作者