'参数: ReportExcelFile 报告输出的路径
Dim ReportExcelFile
'ReportExcelFile = Environment ("TestDir")& "\" & " 测试结果" & Date & "-"& Hour(Now) & Minute(Now)& Second(Now) & ".xls"
ReportExcelFile = "D:\exp.xls"
'这个要放在脚本的前面先run
'描述:GetIP 捕获运行脚本的电脑IP
Public Function GetIP
ComputerName="."
Dim objWMIService,colItems,objItem,objAddress
Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
For Each objAddress in objItem.IPAddress
If objAddress <> "" then
GetIP = objAddress
Exit Function
End If
Next
Next
End Function
'从Report分离的写excel函数
'参数: sStatus 报告的状态分别为FAIL和PASS
'参数: sDetails 注释,用来形容测试内容
'add and modify by dyliu 2009
Public Function WriteRep(sStatus,sDetails)
Dim fso
Dim oExcel
Dim ExcelFile
Dim TestcaseName
Dim objWorkBook
Dim objSheet
Dim NewTC
Dim Status
Set fso = CreateObject("scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application")
If TestcaseName <> objSheet.Cells(Environment("Row")-1,2).value Then
.Cells(Environment("Row"),2).value = TestcaseName
.Cells(Environment("Row"), 3).Value = Status
.Cells(Environment("Row"), 4).value = sDetails
Select Case Status
Case "FAIL"
.Range("C" & Environment("Row")).Font.ColorIndex = 3
Case "PASS"
.Range("C" & Environment("Row")).Font.ColorIndex = 50
Case "WARNING"
.Range("C" & Environment("Row")).Font.ColorIndex = 5
End Select
If (Not NewTC) And (Status = "FAIL") Then
.Cells(Environment("Row"), 3).Value = "Fail"
.Range("C" & Environment("Row")).Font.ColorIndex = 3
end If
'更新结束时间
.Range("C5").Value = Time
.Columns("B:D").Select
'.Columns("B:D").Autofit
End With
oExcel.ActiveWindow.FreezePanes = True
'保存结果
objWorkBook.Save
oExcel.Quit
Set objSheet = Nothing
Set objWorkBook = Nothing
Set oExcel = Nothing
Set fso = Nothing
End Function
'描述:Report 报告函数
'用于创建excel文件
Public Function Report()
'定义变量
Dim fso
Dim oExcel
Dim ExcelFile
Dim TestcaseName
Dim objWorkBook
Dim objSheet
Dim NewTC
Set fso = CreateObject("scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = false 'True
'设置Excel报告样式
If Not fso.FileExists(ReportExcelFile)Then
oExcel.Workbooks.Add
'获取工作簿的第一个Sheet页
Set objSheet = oExcel.Sheets.Item(1)
oExcel.Sheets.Item(1).Select