axmol/tools/JenkinsScript/Windows/win32/qtp_win32/qtrunner.vbs

201 lines
15 KiB
Plaintext
Raw Normal View History

<EFBFBD><EFBFBD>'<00><>nLog<00>e<EFBFBD>N_<EF8D84>S<EFBFBD>e<EFBFBD>N T <0C><>S<EFBFBD>N}T<>NL<4E> OeQ <0C><00>9e:N<1A>Set logFileObj=GetLogObj(argObj(0))
Set logso = CreateObject("Scripting.FileSystemObject")
LogFile = logso.GetAbsolutePathName("Res1\Log\LogFile.html")
PngFile = logso.GetAbsolutePathName("qtp_win32.png")
ResultPath = logso.GetAbsolutePathName("Res1")
TestPath = logso.GetAbsolutePathName("")
projpath = Trim(Left(TestPath,Len(TestPath)-43))
projpath = projpath & "Debug.win32"
projfile = projpath & "\TestCpp.exe"
2012-08-14 16:30:45 +08:00
'Msgbox projpath
'SystemUtil.Run "TestCpp.exe","",projpath
set WshShell = wscript.createobject("wscript.shell")
WshShell.CurrentDirectory = projpath
WshShell.run projfile,1,false
'Set argObj = WScript.Arguments
'Set logFileObj=GetLogObj(argObj(0))
'Set logFileObj=GetLogObj(LogFile)
'Response "--- Start a new batch task at " & Date & " " & Time
'Response "Console logs are saved in " & LogFile
' <00>NM<4E>n<6E>e<EFBFBD>N<EFBFBD><4E>eQT<>y<EFBFBD>Spe
Set ConfigParameters = CreateObject("Scripting.Dictionary")
ConfigFile = "config.ini"
ReadTestsFromConfigFile ConfigFile , ConfigParameters
'Response "Reading Test Configurations From " & ConfigFile
' ЏL<D08F>KmՋ
RunTest
'CloseLogObj logFileObj
' <00>S<01>Email
SendMail LogFile , PngFile
'----------------------------------------------------------------------------------
' <00><><EFBFBD>SM<53>n<6E>e<EFBFBD>N
Function ReadTestsFromConfigFile( ByVal ConfigFile , ByRef ConfigParameters )
Set GetParameters = ConfigParameters
Dim fso, f, lineStr, isValid
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(ConfigFile) Then
Response ConfigFile & " not found"
Exit Function
End If
Dim TestCount
TestCount=0
Set f=fso.OpenTextFile(ConfigFile,1,False)
'Open file for read, if not existed, don't created it.
Do While f.AtEndOfStream <> True
lineStr = f.ReadLine()
lineStr=Trim(lineStr)
If lineStr<>"" Then
'not empty line
'If InStr(1,lineStr,"#") = 1 Then
'begin with "#"
'TestCount = TestCount + 1
'TestPathStr=Trim(Right(lineStr,Len(lineStr)-1))
'GetParameters.Add TestCount, TestPathStr
If InStr(1,lineStr,"smtpserver=") = 1 Then
smtpserver = Trim(Right(lineStr,Len(lineStr)-11))
GetParameters.Add "smtpserver", smtpserver
ElseIf InStr(1,lineStr,"sendusername=") = 1 Then
sendusername = Trim(Right(lineStr,Len(lineStr)-13))
GetParameters.Add "sendusername", sendusername
ElseIf InStr(1,lineStr,"sendpassword=") = 1 Then
sendpassword = Trim(Right(lineStr,Len(lineStr)-13))
GetParameters.Add "sendpassword", sendpassword
ElseIf InStr(1,lineStr,"Email_Address=") = 1 Then
Email_Address = Trim(Right(lineStr,Len(lineStr)-14))
GetParameters.Add "Email_Address", Email_Address
End If
End If
Loop
f.Close
'GetParameters.Add "TestCount", TestCount
Set ReadTestsFromConfigFile = GetParameters
End Function
' <1A>ǏAOM<03>(uQTPgbL<62>KmՋ
Function RunTest
Dim qtApp
Dim qtTest
Dim qtResultsOpt
stime = Now
sdate = Year(stime) & "." & Month(stime) & "." & Day(stime) & "_" & Hour(stime) & "." & Minute(stime) & "." & Second(stime)
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True
Response "Launching QTP..."
'TestCount = ConfigParameters.Item("TestCount")
'For I=1 To TestCount
'TestPath = "L:\cocos2d-x\tools\JenkinsScript\Windows\qtp_win32"
arr = Split(TestPath,";")
testfile = arr(0)
qtApp.Open testfile, True
Set qtTest = qtApp.Test
Response "-------------------------"
Response "Opening Test " & arr(0)
Set oParams = qtApp.Test.ParameterDefinitions.GetParameters()
If UBound(arr) = 1 Then
ParamArr = Split(arr(1),",")
paramCount = UBound(ParamArr)
For K=0 to paramCount
oParam = Split(ParamArr(K),"=")
ParamName = oParam(0)
ParamValue = oParam(1)
oParams.Item(ParamName).Value = ParamValue
Next
End If
'ResultPath = "L:\cocos2d-x\tools\JenkinsScript\Windows\qtp_win32\Res1"
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
qtResultsOpt.ResultsLocation = ResultPath
Response "The Result of Test " & testfile & " will be save in " & ResultPath
qtTest.Run qtResultsOpt, True, oParams ' Run the test
Response "Runing Test " & testfile
Response testfile & "End Running With " & qtTest.LastRunResults.Status & "Status"
Response "Parameter List:"
For P = 1 to oParams.Count
Response oParams.Item(P).Name & "=" & oParams.Item(P).Value
Next
qtTest.Close
Response "Closing Test " & testfile
Response "-------------------------"
qtApp.Quit
Set oParams = Nothing
Set qtResultsOpt = Nothing
Set qtTest = Nothing
Set qtApp = Nothing
End Function
' <00>Q<EFBFBD>e<EFBFBD>_
Function Response(ByVal msg)
' logFileObj.WriteLine Date & " " & Time & ": " & msg
If isRunInCmd Then
WScript.Echo Date & " " & Time & ": " & msg
End If
End Function
' R<>^<5E>e<EFBFBD>_<EFBFBD>e<EFBFBD>N
Function GetLogObj(ByVal cfilePath)
Dim fso, runtimeLog
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(cfilePath) Then
fso.CreateTextFile(cfilePath)
End If
runtimeLog=cfilepath
Set GetLogObj = fso.OpenTextFile(runtimeLog, 8, True) 'open file for appending.
End Function
' sQ<73><51><EFBFBD>e<EFBFBD>_<EFBFBD>e<EFBFBD>N
Function CloseLogObj(ByVal cfile)
cfile.Close
End Function
' <00>S<01><><EFBFBD><EFBFBD>N
Function SendMail(LogFile , PngFile)
Set oMessage=WScript.CreateObject("CDO.Message")
Set oConf=WScript.CreateObject("CDO.Configuration")
Set fso = CreateObject("Scripting.FileSystemObject")
Set pso = CreateObject("Scripting.FileSystemObject")
'R<>^CDO.Configuration<00>[a<>T <0C><00><><EFBFBD><EFBFBD><EFBFBD>n<6E><7F><EFBFBD>N g<>RhV<68>v<EFBFBD>z<EFBFBD>S0(u7b^<5E>SI{<7B>vsQ<73>Oo`
oConf.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
oConf.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.gmail.com"
oConf.Fields("http://schemas.microsoft.com/cdo/configuration/serverport")=25
oConf.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
oConf.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")="redmine@cocos2d-x.org"
oConf.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")="cocos2d-x.org"
oConf.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")=1
oConf.Fields.Update()
'<1A>ǏCDO<00>v Message<00>[a<><61><EFBFBD>n<6E><7F><EFBFBD>N;N<><4E>0D<30><44>N0<>S<01><>NI{<7B>Oo`
oMessage.Configuration = oConf
oMessage.To = "739657621@qq.com"
oMessage.From = "redmine@cocos2d-x.org"
oMessage.Subject = "QTRunner Notification"
file = fso.GetAbsolutePathName(LogFile)
Set fso = Nothing
oMessage.AddAttachment( file )
picture = pso.GetAbsolutePathName(PngFile)
Set pso = Nothing
oMessage.AddAttachment( picture )
TextBody = "QTRunner Finish! See attachment for logs."
oMessage.TextBody = TextBody
oMessage.Send()
End Function