Forum Discussion
Hi,
Somewhere in time this code was created with the help of Support. Hope, it will help you.
'-----------------------------------------------------------------------------
'-----------------------------------------------------------------------------
' From: http://www.automatedqa.com/forums/forum/post/?mode=singleThread&thread=c5788c98-32ee-4d52-b6c7-ea7347d6ab07
' Code that counts errors and warnings
' Note that if you run a project, you need to get the summary of errors and
' warnings using the GetSum function in a routine (in this case, it is LogPostSummaryInfo)
' set as the last test item of the project. If you run a project suite,
' you need to add a project to the end of the test item list of the project suite.
' This project should contain the only test item calling the routine that uses the GetSum function.
Function LogGetErrorsSum(logFolder) ' : OleVariant;
Const cProcName = "LogGetErrorsSum"
Dim cProcNameMsgPrefix : cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "
Dim itemsInfo : itemsInfo = BuiltIn.CreateVariantArray(0, 1) ' errorsCount, warningsCount
Dim tempFolder, xDoc
Dim wrnC, errC
itemsInfo(0) = -1
itemsInfo(1) = -1
tempFolder = logFolder
Set xDoc = Sys.OleObject("MSXML2.DOMDocument")
xDoc.load(tempFolder & "Description.tcLog")
' Warning count
wrnC = VarToInteger(xDoc.selectSingleNode( _
"Nodes/Node[@name='root']/Prp[@name='warning count']/@value").text)
itemsInfo(1) = wrnC
' Error count
errC = VarToInteger(xDoc.selectSingleNode( _
"Nodes/Node[@name='root']/Prp[@name='error count']/@value").text)
itemsInfo(0) = errC
LogGetErrorsSum = itemsInfo
End Function
'-----------------------------------------------------------------------------
Function LogGetSummaryInfo(logFolder) ' : OleVariant;
Const cProcName = "LogGetSummaryInfo"
Dim cProcNameMsgPrefix : cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "
Dim itemsInfo : itemsInfo = BuiltIn.CreateVariantArray(0, 3) ' total, executed, passed, failed
Dim tempFolder, xDoc, rootItem, summaryNode
itemsInfo(0) = -1
itemsInfo(1) = -1
itemsInfo(2) = -1
itemsInfo(3) = -1
tempFolder = aqFileSystem.IncludeTrailingBackSlash(logFolder)
Set xDoc = Sys.OleObject("MSXML2.DOMDocument")
xDoc.load(tempFolder & "RootLogData.dat")
' find the name of the file with the root log node
rootItem = xDoc.selectSingleNode("Nodes/Node/Node[@name='item 0']/Prp[@name='filename']/@value").text
xDoc.load(tempFolder & rootItem)
' find the summary node
Set summaryNode = xDoc.selectSingleNode("Nodes/Node/Node[@name='summary']")
If (summaryNode.hasChildNodes) Then
' commented line fails for some reason with this error:
' Unknown method. Node[@name='total']/Prp[-->starts-with(@<--name, 'total')]/@value
' http://stackoverflow.com/questions/10801399/how-to-select-nodes-by-attribute-that-starts-with-in-c-sharp
' http://support2.microsoft.com/kb/303516
' itemsInfo(0) = VarToInteger(summaryNode.selectSingleNode("Node[@name='total']/Prp[starts-with(@name, 'total')]/@value").text)
itemsInfo(0) = VarToInteger(summaryNode.selectSingleNode("Node[@name='total']/Prp[@name='total (sum)']/@value").text)
itemsInfo(1) = VarToInteger(summaryNode.selectSingleNode("Node[@name='executed']/Prp[@name='total (sum)']/@value").text)
itemsInfo(2) = VarToInteger(summaryNode.selectSingleNode("Node[@name='passed']/Prp[@name='total (sum)']/@value").text)
itemsInfo(3) = VarToInteger(summaryNode.selectSingleNode("Node[@name='failed']/Prp[@name='total (sum)']/@value").text)
End If
LogGetSummaryInfo = itemsInfo
End Function
'-----------------------------------------------------------------------------
' Function counts the number of groups and testitems (enabled/disabled) in the project
' From: http://www.automatedqa.com/forums/forum/post/?mode=singleThread&thread=609e4fae-3925-40d2-b637-20a53f993681
Function LogGetTestItemsInfo(testItems) ': integer;
Const cProcName = "LogGetTestItemsInfo"
Dim cProcNameMsgPrefix : cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "
Dim itemsInfo : itemsInfo = BuiltIn.CreateVariantArray(0, 2) ' groupsCount, itemsCount, enabledItemsCount
Dim i, testItem
Dim childItemsInfo : childItemsInfo = BuiltIn.CreateVariantArray(0, 2) ' groupsCount, itemsCount, enabledItemsCount
itemsInfo(0) = 0
itemsInfo(1) = 0
itemsInfo(2) = 0
For i = 0 To testItems.ItemCount - 1
Set testItem = testItems.TestItem(i)
If (testItem.ElementToBeRun Is Nothing) Then _
itemsInfo(0) = itemsInfo(0) + 1
If (testItem.ItemCount <> 0) Then
childItemsInfo = LogGetTestItemsInfo(testItem)
itemsInfo(0) = itemsInfo(0) + childItemsInfo(0)
itemsInfo(1) = itemsInfo(1) + childItemsInfo(1)
If (testItem.Enabled) Then _
itemsInfo(2) = itemsInfo(2) + childItemsInfo(2)
Else
itemsInfo(1) = itemsInfo(1) + 1
If (testItem.Enabled) Then _
itemsInfo(2) = itemsInfo(2) + 1
End If
Next ' i
LogGetTestItemsInfo = itemsInfo
End Function
'-----------------------------------------------------------------------------
Sub LogPostSummaryInfo
Const cProcName = "LogPostSummaryInfo"
Dim cProcNameMsgPrefix : cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "
Dim itemsInfo : itemsInfo = BuiltIn.CreateVariantArray(0, 3) ' total, executed, passed, failed
Dim itemsErrorsInfo : itemsErrorsInfo = BuiltIn.CreateVariantArray(0, 1) ' errorsCount, warningsCount
Dim itemsProjectInfo : itemsProjectInfo = BuiltIn.CreateVariantArray(0, 2) ' groupsCount, itemsCount, enabledItemsCount
Dim tempFolder
tempFolder = aqString.Format("%s~TC%s\", _
aqFileSystem.IncludeTrailingBackSlash( _
aqEnvironment.GetEnvironmentVariable("temp")), _
aqConvert.DateTimeToFormatStr(aqDateTime.Now, "%Y%m%d_%H%M%S"))
Call aqFileSystem.CreateFolder(tempFolder)
Call Log.SaveResultsAs(tempFolder, lsXML)
itemsInfo = LogGetSummaryInfo(tempFolder)
itemsErrorsInfo = LogGetErrorsSum(tempFolder)
itemsProjectInfo = LogGetTestItemsInfo(Project.TestItems)
Call aqFileSystem.DeleteFolder(tempFolder, True)
Call Log.Message("Test Summary Information (see Additional Info log tab)", _
"Total number of test items been ran: " & VarToStr(itemsInfo(0)) & vbCrLf & _
"Executed project test items: " & VarToStr(itemsInfo(1)) & _
aqString.Format(" (%.2f%%)", VarToInt(itemsInfo(1)) / VarToInt(itemsInfo(0)) * 100) & vbCrLf & _
"Project test items executed successfully: " & VarToStr(itemsInfo(2)) & _
aqString.Format(" (%.2f%%)", VarToInt(itemsInfo(2)) / VarToInt(itemsInfo(1)) * 100) & vbCrLf & _
"Failed project test items: " & VarToStr(itemsInfo(3)) & _
aqString.Format(" (%.2f%%)", VarToInt(itemsInfo(3)) / VarToInt(itemsInfo(1)) * 100) & vbCrLf & _
"Errors count: " & VarToStr(itemsErrorsInfo(0)) & vbCrLf & _
"Warnings count: " & VarToStr(itemsErrorsInfo(1)) & vbCrLf & _
vbCrLf & _
"# of Test Item Groups (total): " & VarToStr(itemsProjectInfo(0)) + vbCrLf & _
"Project Test Items (total): " & VarToStr(itemsProjectInfo(1)) + vbCrLf & _
"Enabled Project Test Items (total): " & VarToStr(itemsProjectInfo(2)) & _
aqString.Format(" (%.2f%%)", VarToInt(itemsProjectInfo(2)) / VarToInt(itemsProjectInfo(1)) * 100) _
)
End Sub
'-----------------------------------------------------------------------------
'-----------------------------------------------------------------------------
- kaiiii5 years agoRegular Contributor
Hi AlexKaras
Thanks for your reply.
I tried that code shared by you but when execution go on(Check below code) , I'm getting error that summaryNode object is required and execution failed. Can you please help me how can I fix this?Want to inform you, I tried to check values in summaryNode object but it's not showing what is internal.
' find the summary node Set summaryNode = xDoc.selectSingleNode("Nodes/Node/Node[@name='summary']") If (summaryNode.hasChildNodes) Then- AlexKaras5 years agoCommunity Hero
Hi,
The code I have posted worked several years ago and it looks like test log format and internal structure was changed since that time.
It looks like that now the information that you are looking for can be found in the Summary.dat file. (If the file is absent it means that tests were executed not as a set started using Test Items tree but as a regular test/routine.)
Examine this file in any text editor and use techniques provided in the previous code to extract information that you need.