Forum Discussion

ratner's avatar
ratner
Occasional Contributor
11 years ago

Exporting/emailing test results

I created a keyword driven test case, which runs automatically every night. The test is on a different PC. How do I export my results, say into a nice readable format (.pdf would be nice, but anything parsable such as .xml will do), and then email the results to myself after test execution, automatically of course? Could someone provide a working example for me? Thanks in advance.

7 Replies

  • Ravik's avatar
    Ravik
    Super Contributor
    Hi Vlad,



    I am also looking such a utility that can sen me test script result, after the execution complete, I have try one sample but it was not work !



    If you found any solution or idea about it, could you please share with us.



    I am attching one solution please see it, if is there any thing is missing, informed me also.







    --




    Sub MainTest



    MainTest

    If SendEmaill("anil.yadrami@in4velocity.com", "anil.yadrami@in4velocity.com", "Subject", _



    "Message body", "") Then



    ' Message was sent



    Log.Message "sent"



    Else



    ' Message was not sent



    Log.Message "not sent" 'I'm getting this message in the log test results this time



    End If



    End Sub



     



    '================================================================================================

    Function SendEmaill(mFrom, mTo, mSubject, mBody, mAttachment)





    Err.Clear



    On Error Resume Next



    schema = "http://schemas.microsoft.com/cdo/configuration/"



    Set mConfig = Sys.OleObject("CDO.Configuration")



    mConfig.Fields.Item(schema + "sendusing") = 587 ' cdoSendUsingPort



     





    mConfig.Fields.Item(schema + "smtpserver") = "smtp.gmail.com" ' SMTP server



     





    mConfig.Fields.Item(schema + "smtpserverport") = 80 ' Port number



     





    mConfig.Fields.Item(schema + "sendusername") = "anil.yadrami" ' User name (if needed)



     





    mConfig.Fields.Item(schema + "sendpassword") = "adsf" ' User password (if needed)



     





    mConfig.Fields.Update()



    Set mMessage = Sys.OleObject("CDO.Message")



    mMessage.Configuration = mConfig



    mMessage.From = "anil.yadrami@in4velocity.com"



    mMessage.To = "anil.yadrami@in4velocity.com"



    mMessage.Subject = "Automation: Testing"



    mMessage.HTMLBody = "Email Received"



    aqString.ListSeparator = ","



    For i = 0 To aqString.GetListLength(mAttachment) - 1



    mMessage.AddAttachment aqString.GetListItem(mAttachment, i)



    Next



    mMessage.Send



    If Err.Number > 0 Then



    Log.Error "E-mail cannot be sent", Err.Description



    SendEMail = False



     



    Else



    Log.Message "Message to <" + mTo + "> was successfully sent"



    SendEMail = True



     



    End If End Function




  • ratner's avatar
    ratner
    Occasional Contributor
    "Spasibo" - Thank you. I looked at the help files, and it does seem to provide some useful information. I also found a nice VB script (see below) that is pretty much exactly what I was looking for. A follow-up question: My test was recorded in the keyword driven format. How would I insert this script into it? Is there a way to convert it to a VB or a J script on a fly? I'd really hate to re-record my test as it's pretty complex, and took me a fair amount of time/tweaking to get it just right. Thanks again for all your help.



    Sub EmailLogResults()

        Dim  tempFolder, xDoc, wrnC, errC

        tempFolder = "C:\temp\tclog1\"

        ' Remove the old folder   

        Call aqFileSystem.DeleteFolder(tempFolder, True)

        ' Prepare a temporary folder

        aqFileSystem.CreateFolder(tempFolder)

        ' Save results to an .xml file

        Call Log.SaveResultsAs(tempFolder, IsXML, True)

        ' Create an XMLDocument

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

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

        ' 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 Sub          

        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

        ' Save results to an .mht file

        Call Log.SaveResultsAs(tempFolder & "TestLogRun1.mht",2)

         ' Send email

        If SendMail(me@domain.com, "smtp.domain.local", "Overnight Test Run 1", "from@domain.com", "Errors = " & errC & "   Warnings = " & wrnC, "Link to log:   \\mycomputer\temp\tclog1\TestLogRun1.mht") Then

          Log.Message "email was sent"

        Else

          Log.Warning "email was not sent"

        End If

    End Sub
  • mtilly's avatar
    mtilly
    Occasional Contributor
    Like the original poster, I am looking for a way to email keyword test results from a keyword test. 
  • Once we export reults from TestExecute, would it be possible to take this in any format like PDF, Excel, Word?
  • karkadil's avatar
    karkadil
    Valued Contributor
    Not by TestComplete means, but you can use any external tools to achieve what you need.