October 7, 2010

Automatically Emailing TestTrack Reports

Helix ALM
I wrote a sample application that can send a TestTrack report to one or more email addresses. This is a console application, so you can create a batch file and use Windows Scheduler to run it at pre-determined times. The application is written in C# using the .NET framework version 3.5. The email is sent using the System.Net.Mail namespace, specifically, the SmtpClient class.  If you're not sure whether this will work in your environment, you can find more information here. If the report consists of a single file, the HTML file will be attached to the email. If the report includes images and consists of more than one file, all the corresponding files will be zipped and attached to the email. To zip the files, I used the free library available here. Keep the following in mind:
  • This application will not support an SMTP host that requires authentication.
  • This is a sample application that is not supported by Seapine. I tested it on my computer but variations, such as the version of TestTrack or .NET you are using, may reveal a bug that I am not aware of. The sample source code is provided in case you run into any issues and want to modify it.
  • The application is written in C# using .NET libraries for sending emails and zipping the files. A different approach may be needed for something like Java, PERL, or Python. However, the TestTrack SOAP portion of the code should serve as a model to translate this into your favorite language.
  • To run reports via SOAP, you need to configure an alternate temporary path due to an issue between the SOAP CGI and IIS. In TestTrack 2011 and later, you can configure a separate temp directory for the SOAP CGI using the TestTrack registry utility. Start the TestTrack registry utility on the computer the TestTrack web server was installed on. Under CGI Options you will find a new SOAP Options section that will allow you to configure an alternate temporary path.
The download includes a binary and the source code (in case you want to modify the sample application). It also includes a sample configuration file. The application takes two parameters:
  • The TestTrack Report Name
  • The email addresses to send the report to; if more than one address is used, use a semi colon as a delimiter
Here is an example:
TTEmailReport "Most Reported" "joe@wysicorp.com;raj@wyiscorp.com"
The application gets the remaining information it needs from the configuration file, which contains the following information:
  • TestTrack username
  • TestTrack password
  • TestTrack SOAP URL
  • TestTrack Project name
  • Return Address
  • Return Display Name
  • SMTP host
The configuration file has to reside in the same directory as the executable. If you have multiple projects, copy the executable and place it in the separate folders, each with its own configuration file. The application will also create a log file in the same directory if an error is detected. This information is stored in a text file, so you should follow the best practice of creating a dedicated account to run this. You may want to place this user in its own security group that has just enough permissions to run the reports (will need access to login via SOAP and the report will have to be accessible to this user). If you are not sure of what permissions the user needs, start with the minimum permissions I mentioned, and then try to run the application. The error log should contain any errors due to lack of permissions. You could always temporarily allow the user to log in via the native TestTrack client.  If you can log in as this user in the native client and run the report, then the user should be able to run the report via SOAP. For more information on setting up security groups, review Appendix D in TestTrack User Guide, which describes all the permissions in detail.