51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1088|回复: 0
打印 上一主题 下一主题

[资料] 【seagull1985-QTP】EXCEL测试报告生成二

[复制链接]
  • TA的每日心情
    奋斗
    2018-8-27 15:56
  • 签到天数: 322 天

    连续签到: 1 天

    [LV.8]测试军长

    跳转到指定楼层
    1#
    发表于 2016-8-5 09:44:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

    2. Dim TestcaseName
    3. Dim Row, TCRow, NewTC

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

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


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


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

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


    27. Select Case sStatus
    28. Case "Fail"
    29. .Range("C" & TCRow).Font.ColorIndex = 3       
    30. .Range("F" & TCRow).Value = "1"
    31. Case "Pass"
    32. .Range("C" & TCRow).Font.ColorIndex = 50       
    33. .Range("E" & TCRow).Value = "1"       
    34. Case "Warning"
    35. .Range("C" & TCRow).Font.ColorIndex = 46
    36. .Range("G" & TCRow).Value = "1"
    37. End Select


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

    40. NewTC = True

    41. 'it is a new Testcase

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

    43. 'Set the Borders for the Result Header
    44. .Range("B" & TCRow & ":G" & TCRow).Borders(1).LineStyle = 1
    45. .Range("B" & TCRow & ":G" & TCRow).Borders(2).LineStyle = 1
    46. .Range("B" & TCRow & ":G" & TCRow).Borders(3).LineStyle = 1
    47. .Range("B" & TCRow & ":G" & TCRow).Borders(4).LineStyle = 1
    48. 'Set color and Fonts for the Header
    49. .Range("B" & TCRow & ":G" & TCRow).Interior.ColorIndex = 2
    50. .Range("B" & TCRow).Font.ColorIndex = 23
    51. .Range("B" & TCRow & ":G" & TCRow).Font.Bold = True


    52. '====NOT A NEW CASE================================================================

    53. Else
    54. .Range("D" & TCRow-1).Value = .Range("D" & TCRow-1).Value + 1
    55. Select Case sStatus
    56. Case "Fail"       
    57. .Range("F" & TCRow-1).Value = .Range("F" & TCRow-1).Value +1
    58. Case "Pass"       
    59. .Range("E" & TCRow-1).Value = .Range("E" & TCRow-1).Value +1       
    60. Case "Warning"       
    61. .Range("G" & TCRow-1).Value = .Range("G" & TCRow-1).Value +1       
    62. End Select
    63. End If

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

    67. End If

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

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

    73. End If


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

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

    81. 'Select the Result Sheet
    82. Set objSheet = oEngine.Sheets("Test_Result")
    83. oEngine.Sheets("Test_Result").Select
    84. With objSheet
    85. 'Enter the Result
    86. If NewTC Then
    87. .Range("A" & Row & ":E" & Row).Interior.ColorIndex = 37
    88. .Range("A" & Row & ":E" & Row).Merge
    89. Row = Row + 1
    90. .Range("A" & Row & ":E" & Row).Merge       
    91. .Range("A" & Row).Value = TestcaseName
    92. 'Set color and Fonts for the Header
    93. .Range("A" & Row & ":E" & Row).Interior.ColorIndex = 2
    94. .Range("A" & Row & ":E" & Row).Font.ColorIndex = 23
    95. .Range("A" & Row & ":E" & Row).Font.Bold = True
    96. Row = Row + 1
    97. End If
    98. .Range("A" & Row).Value = sStepName
    99. 'oEngine.Selection.ShapeRange.ScaleWidth 1.72, msoFalse, msoScaleFromTopLeft
    100. 'oEngine.Selection.ShapeRange.ScaleHeight 1.81, msoFalse, msoScaleFromTopLeft

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

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

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

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

    110. End Select

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

    115. 'Set the Borders
    116. .Range("A" & Row & ":E" & Row).Borders(1).LineStyle = 1
    117. .Range("A" & Row & ":E" & Row).Borders(2).LineStyle = 1
    118. .Range("A" & Row & ":E" & Row).Borders(3).LineStyle = 1
    119. .Range("A" & Row & ":E" & Row).Borders(4).LineStyle = 1
    120. .Range("A" & Row & ":E" & Row).VerticalAlignment = -4160

    121. End With
    122. oEngine.Sheets("Test_Summary").Select
    123. oEngine.Sheets("Test_Summary").Range("B1").Select
    124. 'Save the Workbook
    125. objWorkBook.Save


    126. End Sub

    127. End Class

    128. Set oReporterManager = new excelreporterengine
    复制代码


    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏1
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-24 16:16 , Processed in 0.066232 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表