Ask a Question

Send test result via e-mail in subject

SOLVED
Mia
Contributor

Send test result via e-mail in subject

Hello,



I need to run my test project in TestComplete10 every night, and I need to be able to send result (Succeded/Error(s) occurred) as a part of a email subject.



I run the test project through command line (or I should say batch files) and I also use command line to send emails. First I thought that I always send the .mht file as an attachment, but it is to large even after compression, so I cannot use this solution. I read some other threads about this and everybody solves this using TestCompletes SendMail method. So I just wonder if there is some way to get the result from commandline.



Thanks!

Miriam
20 REPLIES 20
Marsha_R
Champion Level 3

You can send the email as part of the project that you are running from the command line.   This article should help.





http://support.smartbear.com/viewarticle/56306
chrisb
Regular Contributor

Note that if you couldn't send the .mht file via email but are trying to send it through the same SMTP server using SendMail you may still be unable to send it if you exceed the file size limit on the SMTP server. TC log files can get pretty large quite quickly.

If you do have this issue then try sending a summary of test results via email and writing the .mht log file to somewhere such as the testing machine or a network drive.
Mia
Contributor

Thanks for answers. I tried to send emails in the project itself, but I don't actually need that. I need to get some one-word result into the email subject. I don't want to sent whole .mht file in that e-mail.

Maybe sending just some summary in the body of e-mail will suffice, but that I don't know how to get. Is there any way to get the summary from TestComplete and then sending it in email? No matter if it's using the SendMail method in TestComplete or using command line.
Colin_McCrae
Community Hero

I e-mail out my results (not log files - I write my own custom built files) if required at the end of a test run.



I use a script unit function to do this.



What language are you scripting in? I use VBScript and a CDO object to generate mail. Details here: http://www.paulsadowski.com/wsh/cdo.htm



It's pretty simple to set up. I just pass the relevant info to go into the email (who to send to, subject, text, attachment locations etc) into my function and it does the rest.
Mia
Contributor

Hi Colin,



I use JScript. I guess I am able to write function for sending e-mail using the CDO or at least rewrite it from VB.  But what do you mean by writing your own build files?
chrisb
Regular Contributor

In JScript and assuming you dont need to do authentication on the SMTP server...



function sendResults(message) {



var emailRecipients = "firstperson@yoursite.com,secondperson@yoursite.com";


SendMail(emailRecipients, "yoursmtp.yoursite.com", "QA", "", "Test Results", message);




}





Write an additional script that generates your message to pass to the function.



The way I generate a message is to use project suite variables to keep count of the passing and failing tests and then insert these metrics into the email message. I also write the .mht file to a network drive location and include a URL in the message body that links to the log file location on the network drive. 





There is a Jscript example for CDO in TC documentation: http://support.smartbear.com/viewarticle/56308/#CDO





 

Mia
Contributor

Hi Chris,



can you please tell me how you get the count of failed/passed test items? And the example of how to upload the mht file to some location and how to generate the URL would be also usefull 🙂



Thanks!
Colin_McCrae
Community Hero

"But what do you mean by writing your own build files?"



All my stuff runs within a framework built using script extensions. I have three layers of detail in the output (2 levels of results - high and low level - and a layer of logging) from any given test and how much of it, where it gets stored, and who gets e-mailed, is all controlled by switches in the tests.
marin
Frequent Contributor

Hello Miriam,



we had a similar requirement and here's how we tackled this:



1. Create a global variable (e.g. "strTestResult")  that would hold the global test result. This is what will appear in your eMail subject later

2. Override GeneralEvent_OnStopTest and  add sth. like this




/*

Function: GeneralEvents_OnStopTest()

This method assigns global test result (FAILED, WARNING, OK) to test project according to single test results.

 

Bubbles up to higher severity level, i.e. if WARNING is recorded in any of test cases and no FAILED recorded anywhere,

global test outcome is WARNING. If FAILED is recorded in any test case, global result will be FAILED.

*/

function GeneralEvents_OnStopTest(Sender)

{

  if (Log.ErrCount > 0)

    strTestResult = "FAILED";

  else if (Log.WrnCount > 0 && Log.ErrCount == 0)

    strTestResult = strTestResult != "FAILED" ? "WARNING" : "FAILED";

  else

    strTestResult = strTestResult != "FAILED" ?

                      (strTestResult != "WARNING" ? "OK" : "WARNING") : "FAILED";

}








3. Export the test results from TestComplete to a temprary file after the run and then parse it for desired attributes.

We have following method to do this, the output will be a small HTML table with a quick summary





function GetTestSummary()

{

  var tempFolder = "C:\\temp\\" + GetTickCount() + "\\";

 

  if (0 != aqFileSystem.CreateFolder(tempFolder))

  {

    Log.Error("The " + tempFolder + " temp folder was not created");

    return "";

  }

 

  Log.SaveResultsAs(tempFolder, lsXML);

 

  var xDoc = Sys.OleObject("MSXML2.DOMDocument.4.0");

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

  // Warning count  

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

  //Error count  

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

  //Execution time  

  var startTime = parseFloat(xDoc.selectSingleNode('Nodes/Node[@name="root"]/Prp[@name="start time"]/@value').text);  

  var stopTime = parseFloat(xDoc.selectSingleNode('Nodes/Node[@name="root"]/Prp[@name="stop time"]/@value').text);      

 

  aqFileSystem.DeleteFolder(tempFolder, true);  

 

  var cellStyle = "style=\"padding-left:5px; padding-right:5px";

  var errCntCellBg = "; background-color:" + (errC > 0 ?  "#FF704D\"" : "#ACD630\"");

  var wrnCntCellBg = "; background-color:" + (wrnC > 0 ?  "#FFFF75\"" : "#ACD630\"");

 

  var res = "<table border =\"1\">" +

            "<tr><td " + cellStyle + "\">Errors: </td><td " + cellStyle + errCntCellBg + "\">" + errC + "</td></tr>" +     

            "<tr><td " + cellStyle + "\">Warnings: </td><td " + cellStyle +  wrnCntCellBg + "\">" + wrnC + "</td></tr>" +    

            "<tr><td " + cellStyle + "\">Start Time: </td><td " + cellStyle + "\">" + aqConvert.DateTimeToStr(startTime) + "</td></tr>" +    

            "<tr><td " + cellStyle + "\">Stop Time: </td><td " + cellStyle + "\">" + aqConvert.DateTimeToStr(stopTime) + "</td></tr>" +    

            "<tr><td " + cellStyle + "\">Run Time: </td><td " + cellStyle + "\">" + aqConvert.DateTimeToFormatStr(stopTime - startTime, "%H:%M:%S") + "</td></tr>" +

            "</table>";

              

 

  return res;   

 

}







4. Then call the method above and save the HTML output to a variable (see "strTestSummary"). Also save the .mht file to a directory of your choice on the server and store the path in the variable -> this will be the link to the file in the automatic eMail sent later (see below):





function SaveAndEmailTestResults()

{

  var FileName, NowValue, strNowValue, strTestSummary;

 

  strTestSummary = GetTestSummary();

 

 

  // Obtain the current date and time

  NowValue=aqDateTime.Now();

 

  // Convert the returned date/time value to string value

  strNowValue = aqConvert.DateTimeToFormatStr(NowValue, "%Y%m%d%H%M%S");

 

  FileName = strLogFilePath + "\\" + strNowValue + ".mht";

  Log.SaveResultsAs(FileName, 2);

 

     

   //Send eMail

   SendCDOEmail(strTestResult, strTestSummary, strAppVersionInfo, FileName);

  

   //re-initialize global test result flag

   strTestResult="";

 

}











5. Invoke automatic sending of eMail (see "SendCDOEmail" call above). Make sure to supply the correct input parameters (SMTP credentials etc.) :







function SendCDOEmail(testResult,resultSummary, versionInfo, file)

{

  var i, schema, mConfig, mMessage, mSubject, mBody;

 

  var strTestServerIP = "\\\\10.20.30.40";

 

  var strFileLink = aqString.Replace(file,"C:",strTestServerIP);

 

  mBody="Application " + versionInfo + "<br><br>" + resultSummary + "<br>Log file: <a href =\"" + strFileLink + "\">" + strFileLink + "</a>";

  mSubject= "Automated test notification: " + testResult;

  try

  {

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

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

    mConfig.Fields.Item(schema + "sendusing") = 2; // cdoSendUsingPort

    mConfig.Fields.Item(schema + "smtpserver") = strLogSMTPServer; // SMTP server

    mConfig.Fields.Item(schema + "smtpserverport") = 25; // Port number

    mConfig.Fields.Item(schema + "MailboxURL")= strLogMailBoxUrl;

    //mConfig.Fields.Item(schema + "sendusername") = "user"; // User name (if needed)

    //mConfig.Fields.Item(schema + "sendpassword") = "pwd"; // User password (if needed)

    mConfig.Fields.Update();

 

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

    mMessage.MimeFormatted = true;

    mMessage.Configuration = mConfig;

    mMessage.From = strLogSenderName;

    mMessage.To = strLogRecipientAddress;

    mMessage.Subject = mSubject;

    mMessage.HTMLBody = mBody;

   

   

    mMessage.Send();

   

  }

  catch (exception)

  {

    Log.Error("E-mail cannot be sent", exception.description);

    return false;

  }

  Log.Message("Message to <" + strLogRecipientAddress + "> was successfully sent");

 

 

  return true;

}





 

Hope this helps to point you to the right direction.



Marin


cancel
Showing results for 
Search instead for 
Did you mean: