QTP日志实践的几点总结
2007-06-27 09:24
357 查看
作者:风过无息 [b]2007年5月28日[/b]
一起测试网 : 软件质量专家
背景:在日常使用QTP中,因为有QC的存在,导致了QTP的察看结果的功能并不是用的很顺手,所以笔者在脱离开QC的情况下,在工作实践中总结了QTP的日志实现的一些方法。
生成txt文件。这是从开发那边得到的启示。
首先定义一个sub:
Public Sub WriteLineToFile(message)
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
这样就能在txt中直接明了的看到自己的日志了。(个人感觉比看QTP的results好多了了,当然QTP自身的results还有错误图片等等,下面会介绍我的解决方案)
题外话:在实际应用中,我会在sub中增加一个flag,来标志不同的严重等级,在不同的情况下控制输出不一样类型的日志。
使用QTP自身的抓图功能
Public Function capture_desktop()
Dim datestamp
Dim filename
datestamp = Now()
filename = Environment("TestName")&"_"&datestamp&".png"
filename = Replace(filename,"/","")
filename = Replace(filename,":","")
filename = "C:/QTP_ScreenShots"&""&filename
Desktop.CaptureBitmap filename
Reporter.ReportEvent micFail,"image","<img src='" & filename & "'>"
End Function
该函数主要就是用到Desktop.CaptureBitmap的这个方法,把桌面的图片抓下来,这样比较自由的抓下任意时候桌面的图片,方便我们检查结果。
题外话:可以通过Function的返回值和上面提到的方法结合在一起的话,效果会更好的。
使用outlook发送邮件
Public Sub SendEmail(testname,strsubject,stremailcontent,attachment,strrecipient)
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
题外话:假如我们把日志和抓图都结合在一起作为附件发出去的话,在自动化测试中后期会很有用,当然前提是不使用QC的情况下。
这是一个针对上面第3点如何把抓图放在一个doc中。
Set oWord = CreateObject("Word.Application")
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和excel,word结合的不错的,所以在测试中灵活运动,效果会很好的。
总结:毕竟大规模的QTP测试中,需要总结实践的很多,这是笔者是在如何将测试结果的产生中抛砖引玉,学无止境,和大家一起进步。
一起测试网 : 软件质量专家
背景:在日常使用QTP中,因为有QC的存在,导致了QTP的察看结果的功能并不是用的很顺手,所以笔者在脱离开QC的情况下,在工作实践中总结了QTP的日志实现的一些方法。
生成txt文件。这是从开发那边得到的启示。
首先定义一个sub:
Public Sub WriteLineToFile(message)
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
这样就能在txt中直接明了的看到自己的日志了。(个人感觉比看QTP的results好多了了,当然QTP自身的results还有错误图片等等,下面会介绍我的解决方案)
题外话:在实际应用中,我会在sub中增加一个flag,来标志不同的严重等级,在不同的情况下控制输出不一样类型的日志。
使用QTP自身的抓图功能
Public Function capture_desktop()
Dim datestamp
Dim filename
datestamp = Now()
filename = Environment("TestName")&"_"&datestamp&".png"
filename = Replace(filename,"/","")
filename = Replace(filename,":","")
filename = "C:/QTP_ScreenShots"&""&filename
Desktop.CaptureBitmap filename
Reporter.ReportEvent micFail,"image","<img src='" & filename & "'>"
End Function
该函数主要就是用到Desktop.CaptureBitmap的这个方法,把桌面的图片抓下来,这样比较自由的抓下任意时候桌面的图片,方便我们检查结果。
题外话:可以通过Function的返回值和上面提到的方法结合在一起的话,效果会更好的。
使用outlook发送邮件
Public Sub SendEmail(testname,strsubject,stremailcontent,attachment,strrecipient)
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
题外话:假如我们把日志和抓图都结合在一起作为附件发出去的话,在自动化测试中后期会很有用,当然前提是不使用QC的情况下。
这是一个针对上面第3点如何把抓图放在一个doc中。
Set oWord = CreateObject("Word.Application")
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和excel,word结合的不错的,所以在测试中灵活运动,效果会很好的。
总结:毕竟大规模的QTP测试中,需要总结实践的很多,这是笔者是在如何将测试结果的产生中抛砖引玉,学无止境,和大家一起进步。
相关文章推荐
- QTP日志实践的几点总结
- QTP实践总结
- 优秀日志实践准则,你做到了几点
- 基于RabbitMQ使用的几点实践经验总结
- atitit. 日志系统的原则and设计and最佳实践(1)-----原理理论总结.
- Java开发阶段总结(上)——日志、流程与异常、命名的实践
- atitit. 日志系统的原则and设计and最佳实践(1)-----原理理论总结.
- Atitit.log日志技术的最佳实践attilax总结
- 关于日志打印的几点建议以及非最佳实践
- Atitit.log日志技术的最佳实践attilax总结
- QTP场景恢复的实践和总结
- Atitit.log日志技术的最佳实践attilax总结
- 基于RabbitMQ使用的几点实践经验总结
- 【腾讯TMQ】自动化测试平台实践几点经验总结
- SQL Server日志文件总结及日志满的处理
- App后台开发运维和架构实践学习总结(9)——三种常见的API设计错误及解决方案
- 接口测试实践与总结
- 日志文件的操作部分总结
- mysql乐观锁总结和实践
- 使用flume进行日志收集的总结(1)