利用FSO生成QTP测试报告
上一篇文章里只是简单谈了些FSO文本文件系统对象的几个常用的方法。本文将主要介绍FSO怎样生成测试报告。
下面列举了web测试里常见的Edit控件跟button控件的操作。
Function WebEdit_SetValue(obj,val) obj.Set val Const ForAppending = 8 Const ForWriting = 2 Const ForReading = 1 Set fso = CreateObject("Scripting.FileSystemObject") logFileName = cstr(Year(now) & Month(now) & Day(now)) + ".txt" logFilePath = Environment.Value("ResultDir") + "\" + logFileName print logFilePath If not fso.FileExists(logFilePath) Then Set resFile = fso.CreateTextFile (logFilePath,False) Else Set resFile = fso.OpenTextFile(logFilePath,ForAppending,True) End If strLog = cstr(Time) + " Object: [" + obj.getToProperty("micClass") + _ "-" + obj.getToProperty("TestObjName") + "] - Description:" + _ "Set value is: <" + val + ">" resFile.WriteLine strLog Set resFile = Nothing Set fso = Nothing End Function Function WebButton_Click(obj) obj.Click Const ForAppending = 8 Const ForWriting = 2 Const ForReading = 1 Set fso = CreateObject("Scripting.FileSystemObject") logFileName = cstr(Year(now) & Month(now) & Day(now)) + ".txt" logFilePath = Environment.Value("ResultDir") + "\" + logFileName If not fso.FileExists(logFilePath) Then Set resFile = fso.CreateTextFile (logFilePath,False) Else Set resFile = fso.OpenTextFile(logFilePath,ForAppending,True) End If strLog = cstr(Time) + " Object: [" + obj.getToProperty("micClass") + _ "-" + obj.getToProperty("TestObjName") + "] - Description:" + _ "Click object success" resFile.WriteLine strLog Set resFile = Nothing Set fso = Nothing End Function RegisterUserFunc "WebEdit","Set","WebEdit_SetValue" RegisterUserFunc "WebButton","Click","WebButton_Click" With Browser("百度一下,你就知道").Page("百度一下,你就知道") .WebEdit("wd").Set("Hello Mr Sun") .WebButton("百度一下").Click End With
两个Function里其实有很多地方是重复的,可以将他们合并,也可以用到我之前讲过的相对路径的技术。有兴趣的可以试着实现。我会在之后自己写框架时再次具体呈现。
下面的是生成的txt格式的测试报告,看起来也蛮清楚的~txt格式的比较简单,当然也可以是xml格式的或者html格式的,怎样方便怎么写吧,你可以随心所欲地设计你想要的测试报告,我只是抛砖引玉。