Forum Discussion

tlalok's avatar
tlalok
Contributor
16 years ago

How to get the total number of errors at the end of a sequence of tests

Hi,



I run a number of tests (organized via "organize tests") and want to report the total sum of errors and warnings (five tests are run automatically one after another).



However, in my script Log.ErrCount reports the number of errors in the last test only.



I found "Log.FolderErrCount(FolderID)" which might do it - but I don't know where to get the current FolderID.



Is there a property avaliable?



Regards,



- Carsten



8 Replies


  • Hi Carsten,





    I am sending you the code which you can use to count errors and warnings:







    function GetSum(sType);

    var tempFolder, xDoc, wrnC, errC;

    begin





        tempFolder := aqEnvironment.GetEnvironmentVariable('temp')+'\'+IntToStr(Random(10000))+'\';





        aqFileSystem.CreateFolder(tempFolder);

        Log.SaveResultsAs(tempFolder, lsXML);

      

        xDoc := Sys.OleObject('MSXML2.DOMDocument.4.0');

        xDoc.load(tempFolder + 'Description.tcLog');





        //Warning count

        wrnC := VarToInteger(xDoc.selectSingleNode('Nodes/Node[@name="root"]/Prp[@name="warning count"]/@value').text);





        //Error count

        errC := VarToInteger(xDoc.selectSingleNode('Nodes/Node[@name="root"]/Prp[@name="error count"]/@value').text);





        aqFileSystem.DeleteFolder(tempFolder, True);

        

        case sType of

            'w': result := IntToStr(wrnC);

            'e': result := IntToStr(errC);

        else

            result := 'Wrong parameter';  

        end;

      

    end;





    procedure PostSum;

    begin

      Log.Message('Warning count: ' + GetSum('w'));

    end;







    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 PostSum) 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.
  • Hello David,



    thanks a lot for the code, it works nicely and I just ran the whole test suite and got the result I expected.



    Now I can inform the team automatically by e-mail about the result of the tests. I included file version in the mail header so everyone knows what version the testlog is about.



    I don't think I would have figured that one out myself ;-).



    Best regards,



    - Carsten
  • Hi all,



    I have tried to migrate this code to VisualBasic.

    However, I do have an error when opening the file (error -1072896636).

    Does anybody know which the cause could be?



    I attach the code I have done:



    Function GetSum(sType)

    Dim  tempFolder, xDoc, wrnC, errC



        tempFolder = aqEnvironment.GetEnvironmentVariable("temp") & "\" & IntToStr(10000) & "\"



        aqFileSystem.CreateFolder(tempFolder)

        Call Log.SaveResultsAs(tempFolder, lsXML, True)

        

        Set xDoc = Sys.OleObject("MSXML2.DOMDocument.6.0")





        Call xDoc.load(tempFolder & "Description.tcLog")

        

      ' tested with

    '    Call xDoc.loadXML(tempFolder & "Description.tcLog")

      ' and result id the same





        Log.Message ("File load result: " & xDoc.parseError.errorCode)



        ' Warning count

        Set wrnC = VarToInteger(xDoc.selectSingleNode("Nodes/Node[@name='root']/Prp[@name='warning count']/@value").text)





        ' Error count

        Set errC = VarToInteger(xDoc.selectSingleNode("Nodes/Node[@name='root']/Prp[@name='error count']/@value").text)

        



        Call aqFileSystem.DeleteFolder(tempFolder, True)

        

        Select Case sType

            Case w: result = IntToStr(wrnC)

            Case e: result = IntToStr(errC)

            Case Else result = "Wrong parameter"  

        End Select



          

    End Function





    I have tested in using .load .loadXML methods.

    I have tested again with a static file to be loaded in another path in Windows Explorer.



    In all the cases, I get the same error.





    Thank you very much,





    Raul
  • Raul,


    This error occurs because the XML parser was unable to process the DOCTYPE instruction in the xml file storing results.

    Try using this code:




    Function GetSum(sType)

        Dim  tempFolder, xDoc, wrnC, errC


        ' Prepare a temporary folder

        tempFolder = aqEnvironment.GetEnvironmentVariable("temp") & "\" & IntToStr(10000) & "\"

        aqFileSystem.CreateFolder(tempFolder)

       

        ' Save results to an .xml file

        Call Log.SaveResultsAs(tempFolder, lsXML, True)

       

        ' Create an XMLDocument

        Set xDoc = Sys.OleObject("MSXML2.DOMDocument.4.0")

        ' Set xDoc = Sys.OleObject("MSXML2.DOMDocument.6.0")

        ' xDoc.validateOnParse = false


        ' Load the file

        Call xDoc.load(tempFolder & "Description.tcLog")

       

        ' Check the load result

        If xDoc.parseError.errorCode <> 0 Then 

          Log.Message "File load result: "& xDoc.parseError.errorCode, _

                      "Error code: "      & xDoc.parseError.errorCode & Chr(13) & Chr(10) & _ 

                      "Description: "     & xDoc.parseError.reason & Chr(13) & Chr(10) & _

                      "Line No: "         & xDoc.parseError.line & Chr(13) & Chr(10) & _

                      "Column: "          & xDoc.parseError.linepos & Chr(13) & Chr(10) & _

                      "Source text: "     & xDoc.parseError.srcText

          Exit Function           

        End If                           


        ' Count warnings

        wrnC = xDoc.selectSingleNode("Nodes/Node[@name='root']/Prp[@name='warning count']/@value").text


        ' Count errors

        errC = xDoc.selectSingleNode("Nodes/Node[@name='root']/Prp[@name='error count']/@value").text

       

        ' Remove the temporary folder   

        Call aqFileSystem.DeleteFolder(tempFolder, True)

       

        ' Return the result

        Select Case sType

          Case "w" : GetSum = CStr(wrnC)

          Case "e" : GetSum = CStr(errC)

          Case Else

            GetSum = "Wrong parameter"

        End Select

         

    End Function

  • Alex,



    I have tried your vbscript function but I get the following when I call it from my keyword test...




    Error code: -1072896636

    Description: DTD is prohibited.



    Line No: 2

    Column: 11

    Source text: <!DOCTYPE Nodes [


    Can you suggest what I could try to resolve this?



    Thanks,  Jim

  • Hi Jim,


     


    As far as I understand from your support request, changing 


    Set xDoc = Sys.OleObject("MSXML2.DOMDocument.3.0")




    to 


    Set xDoc = Sys.OleObject("MSXML2.DOMDocument.6.0")




    solved the issue, right?