作者:風過無息 2007年5月28日
一起測試網 : 軟件質量專家
背景:在日常使用QTP中,因爲有QC的存在,導致了QTP的察看結果的功能並不是用的很順手,所以筆者在脫離開QC的情況下,在工作實踐中總結了QTP的日誌實現的一些方法。
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fileSystemObj, fileSpec
Dim currentTime
currentDate = Date
currentTime = Time
testName = "log"
Set fileSystemObj = CreateObject("scrīpting.FileSystemObject")
fileSpec ="C:/" &testName& ".txt" 'change this according to your directory
If Not (fileSystemObj.FileExists(filespec)) Then
Set logFile = fileSystemObj.CreateTextFile(fileSpec, ForWriting, True)
logFile.WriteLine ("#######################################################################")
logFile.WriteLine (currentDate & currentTime & " Test: " & environment.Value("TestName") )
logFile.WriteLine ("#######################################################################")
logFile.Close
Set logFile = Nothing
End If
Set logFile = fileSystemObj.OpenTextFile(fileSpec, ForAppending, False, True)
logFile.WriteLine (currentDate & currentTime & " " & message)
logFile.Close
Set logFile = Nothing
Set fileSystemObj = Nothing
End Sub
Set out = CreateObject("Outlook.Application")
Set mapi = out.GetNameSpace("MAPI")
Set email = out.CreateItem(0)
email.Recipients.Add(strrecipient)
email.Subject = strsubject
email.Body = stremailcontent
Set oAttachment = email.Attachments.Add(attachment)
email.Send
Set outlook = Nothing
Set mapi = Nothing
End Sub
oWord.DisplayAlerts = False
oWord.Visible = False
oWord.documents.open "testWordDoc.doc"
Set oDoc = oWord.ActiveDocument
Set oRange = oDoc.content
oRange.ParagraphFormat.Alignment = 0
oRange.insertafter vbcrlf '& " " & vbcrlf
oRange.collapse(0)
oRange.InlineShapes.AddPicture "ImagePath.bmp", False, True
oWord.ActiveDocument.Save
oWord.Application.Quit True
Set oRange = Nothing
Set oDoc = Nothing
Set oWord = Nothing
總結:畢竟大規模的QTP測試中,需要總結實踐的很多,這是筆者是在如何將測試結果的產生中拋磚引玉,學無止境,和大家一起進步。