seagull1985 发表于 2016-8-5 09:44:59

【seagull1985-QTP】EXCEL测试报告生成二


接 【seagull1985-QTP】EXCEL测试报告生成一      因为代码过长,导致贴子字符数过长,所以分开2个贴子发。

代码PART2   衔接代码PART1
Public Sub Report (sStatus, sStepName,sExpected,sActual, sDetails)

Dim TestcaseName
Dim Row, TCRow, NewTC

'TestcaseName = Environment("ActionName") & " > Iteration (Test-Action) = " & Environment("TestIteration") & "-" & Environment("ActionIteration")
TestcaseName = sStepName & " > Iteration (Test-Action) = " & Environment("TestIteration") & "-" & Environment("ActionIteration")

'Open the Result file
' Set objWorkBook = oEngine.Workbooks.Open (oSettings("File"))
'Select the Summery Sheet
Set objSheet = oEngine.Sheets("Test_Summary")
oEngine.Sheets("Test_Summary").Select


With objSheet
'Note the Row No. on which to Report the result
Row = .Range("C8").Value + 2*.Range("C7").Value + 2
TCRow = .Range("C7").Value + 11
NewTC = False
.Range("F" & TCRow).Font.ColorIndex = 3
.Range("E" & TCRow).Font.ColorIndex = 50
.Range("G" & TCRow).Font.ColorIndex = 46


'Check if it is a new Tetstcase
If objSheet.Cells(TCRow - 1, 2).Value <> TestcaseName Then
.Cells(TCRow, 2).Value = TestcaseName
oEngine.ActiveSheet.Hyperlinks.Add objSheet.Cells(TCRow, 2), "", "Test_Result!A" & Row+1, TestcaseName

.Cells(TCRow, 3).Value = sStatus
.Range("F" & TCRow).Value = "0"
.Range("E" & TCRow).Value = "0"       
.Range("G" & TCRow).Value = "0"       


Select Case sStatus
Case "Fail"
.Range("C" & TCRow).Font.ColorIndex = 3       
.Range("F" & TCRow).Value = "1"
Case "Pass"
.Range("C" & TCRow).Font.ColorIndex = 50       
.Range("E" & TCRow).Value = "1"       
Case "Warning"
.Range("C" & TCRow).Font.ColorIndex = 46
.Range("G" & TCRow).Value = "1"
End Select


'The first step.
.Cells(TCRow, 4).Value = 1 '(D,11)

NewTC = True

'it is a new Testcase

.Range("C7").Value = .Range("C7").Value + 1 'count the cases.

'Set the Borders for the Result Header
.Range("B" & TCRow & ":G" & TCRow).Borders(1).LineStyle = 1
.Range("B" & TCRow & ":G" & TCRow).Borders(2).LineStyle = 1
.Range("B" & TCRow & ":G" & TCRow).Borders(3).LineStyle = 1
.Range("B" & TCRow & ":G" & TCRow).Borders(4).LineStyle = 1
'Set color and Fonts for the Header
.Range("B" & TCRow & ":G" & TCRow).Interior.ColorIndex = 2
.Range("B" & TCRow).Font.ColorIndex = 23
.Range("B" & TCRow & ":G" & TCRow).Font.Bold = True


'====NOT A NEW CASE================================================================

Else
.Range("D" & TCRow-1).Value = .Range("D" & TCRow-1).Value + 1
Select Case sStatus
Case "Fail"       
.Range("F" & TCRow-1).Value = .Range("F" & TCRow-1).Value +1
Case "Pass"       
.Range("E" & TCRow-1).Value = .Range("E" & TCRow-1).Value +1       
Case "Warning"       
.Range("G" & TCRow-1).Value = .Range("G" & TCRow-1).Value +1       
End Select
End If

If (Not NewTC) And (sStatus = "Fail") Then
.Cells(TCRow-1, 3).Value = "Fail"
.Range("C" & TCRow-1).Font.ColorIndex = 3

End If

If (Not NewTC) And (sStatus = "Warning") Then

If .Cells(TCRow-1, 3).Value = "Pass" Then
.Cells(TCRow-1, 3).Value = "Warning"
.Range("C" & TCRow-1).Font.ColorIndex = 46
End If

End If


.Range("C8").Value = .Range("C8").Value + 1
'Update the End Time
.Range("C5").Value = Time

'Set Column width
.Columns("B:D").Select
.Columns("B:D").Autofit
End With

'Select the Result Sheet
Set objSheet = oEngine.Sheets("Test_Result")
oEngine.Sheets("Test_Result").Select
With objSheet
'Enter the Result
If NewTC Then
.Range("A" & Row & ":E" & Row).Interior.ColorIndex = 37
.Range("A" & Row & ":E" & Row).Merge
Row = Row + 1
.Range("A" & Row & ":E" & Row).Merge       
.Range("A" & Row).Value = TestcaseName
'Set color and Fonts for the Header
.Range("A" & Row & ":E" & Row).Interior.ColorIndex = 2
.Range("A" & Row & ":E" & Row).Font.ColorIndex = 23
.Range("A" & Row & ":E" & Row).Font.Bold = True
Row = Row + 1
End If
.Range("A" & Row).Value = sStepName
'oEngine.Selection.ShapeRange.ScaleWidth 1.72, msoFalse, msoScaleFromTopLeft
'oEngine.Selection.ShapeRange.ScaleHeight 1.81, msoFalse, msoScaleFromTopLeft

.Range("B" & Row).Value = sStatus
.Range("B" & Row).Font.Bold = True       

Select Case sStatus
Case "Pass"
.Range("A" & Row & ":E" & Row).Font.ColorIndex = 50

Case "Fail"
.Range("A" & Row & ":E" & Row).Font.ColorIndex = 3

Case "Warning"
.Range("A" & Row & ":E" & Row).Font.ColorIndex = 46

End Select

.Range("B" & Row).Font.Bold = True
.Range("C" & Row).Value = sExpected
.Range("D" & Row).Value = sActual
.Range("E" & Row).Value = sDetails

'Set the Borders
.Range("A" & Row & ":E" & Row).Borders(1).LineStyle = 1
.Range("A" & Row & ":E" & Row).Borders(2).LineStyle = 1
.Range("A" & Row & ":E" & Row).Borders(3).LineStyle = 1
.Range("A" & Row & ":E" & Row).Borders(4).LineStyle = 1
.Range("A" & Row & ":E" & Row).VerticalAlignment = -4160

End With
oEngine.Sheets("Test_Summary").Select
oEngine.Sheets("Test_Summary").Range("B1").Select
'Save the Workbook
objWorkBook.Save


End Sub

End Class

Set oReporterManager = new excelreporterengine


页: [1]
查看完整版本: 【seagull1985-QTP】EXCEL测试报告生成二