Sending an email of Test Results

Ask general questions here.
smalldoorman
Posts: 14
Joined: Thu Aug 12, 2010 10:37 pm

Sending an email of Test Results

Post by smalldoorman » Tue Oct 12, 2010 5:55 pm

I have a solo system that is for Ranorex and it runs our test while I do other work on my machine. So far I have it execute several solutions back to back which can take anywhere between 30 min to several hours.

Is there any way to have Ranorex send me an email after each solution where the subject line will name the solution and then tell me if it passed or failed. Or even just tell me that that the solution (or whole battery of tests) has completed? I would need to send through an SMTP that requires authentication but im not sure how to go about any of this.

Is it even possible to have email's sent upon completion let alone making a subject line dependent on the outcome of a test?

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Sending an email of Test Results

Post by sdaly » Wed Oct 13, 2010 10:04 am

It is possible using .net, I use the method below to send emails, the test log can be added as an attachment too.

This method only works with an open SMTP server.....

Public Sub sendEmail(strSubject As String, strBody As String, strAttachmentPath As String)
If TestRunner.getSetting("emailEnable") = True Then
Try
'create new mail class with passed in params
Dim insMail As New system.Net.mail.MailMessage(New system.Net.Mail.MailAddress(TestRunner.getSetting("emailAddressFrom")), New system.net.Mail.MailAddress(TestRunner.getSetting("emailAddressTo")))
With insMail
'set the subject
.Subject = strSubject
'set the body
.Body = strBody
'add attachment
If strAttachmentPath <> "" and file.Exists(strAttachmentPath) Then .Attachments.Add(New system.Net.Mail.Attachment(strAttachmentPath))
End With
Dim smtp As New System.Net.Mail.SmtpClient
smtp.Host = TestRunner.getSetting("emailHost")
smtp.Port = 25
smtp.Send(insMail)
report.Info("Email", "Sent")
Catch ex As System.Exception
report.Failure("Email", ex.Message.ToString)
Throw New Exception("Exception")
End Try
End If
End Sub



If you need SMTP authentication take a look at sending emails using CDO - http://www.google.co.uk/search?sourceid ... %2enet+cdo

Hope this helps
Scott

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Sending an email of Test Results

Post by Support Team » Wed Oct 13, 2010 10:08 am

Hi,

Of course it is possible to customize your Report. Many of our customers use its own Reports. Please take a look to following blog for your issue. In this blog will be explained "How to customize your Report and send it via mail". http://www.ranorex.com/blog/customizing-ranorex-reports

Regards,
Peter
Ranorex Team

smalldoorman
Posts: 14
Joined: Thu Aug 12, 2010 10:37 pm

Re: Sending an email of Test Results

Post by smalldoorman » Wed Oct 13, 2010 3:34 pm

Peter,
I ran across that tutorial after I posted this. Thing is, I'm still learning C# as I go and the tutorials written, although concise, do not help with telling me where each snippet is supposed to go.

For example I'm told to "right click on IReportLogger and select “MailLogger -> Implement Interface (implicit) -> IReportLogger” and Ranorex Studio will create stubs for the interface methods for you." But I cannot find the IReportLogger in the Studio and nothing comes up for IReport on the Ranorex website.

Are there anymore detailed steps as to what needs to go into what files at least?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Sending an email of Test Results

Post by Support Team » Thu Oct 14, 2010 1:00 pm

Hi,

Please take a look at the sample project how we implemented the Custom Logger. Please click following link (link is also available in the blog):
http://www.ranorex.com/blog/wp-content/ ... ogging.zip
Save the zip file to your hard drive and extract it. Then please open the Ranorex Solution Project and take a look at the implementation.

Regards,
Peter
Ranorex Team

Pixi6s
Posts: 92
Joined: Tue Jun 28, 2011 8:57 pm

Re: Sending an email of Test Results

Post by Pixi6s » Thu Jun 28, 2012 2:39 pm

Hello,

This is great but I require to send a boolean for secureSSL to use our SMTP. How do I do that?

Thanks

Error:
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at CustomLogging.MailLogger.End() in c:\temp\CustomLogging\CustomLogging\MailLogger.cs:line 242

Pixi6s
Posts: 92
Joined: Tue Jun 28, 2011 8:57 pm

Re: Sending an email of Test Results

Post by Pixi6s » Thu Jun 28, 2012 9:38 pm

If you have any ideas please share, but it might be the way we smtp setup. I needed to use a specific email address (configured for smtp) and give email a password. So if you have no ideas, no worries. :)

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Sending an email of Test Results

Post by sdaly » Fri Jun 29, 2012 8:09 am

In c#

NetworkCredential credentials = new NetworkCredential("username", "Password");
smtp.Credentials = credentials;

//for ssl
smtp.EnableSsl = true;

jchou
Posts: 26
Joined: Tue Apr 24, 2012 11:19 pm

Re: Sending an email of Test Results

Post by jchou » Fri Sep 28, 2012 3:22 am

Is there a way to access test result (failed or successful) at the end of a test case (or a test suite), so that I can put some data in email accordingly. Thanks.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Sending an email of Test Results

Post by Support Team » Fri Sep 28, 2012 1:47 pm

Hi,

I created a solution for you where you can see how you can send the zipped report as attachment and how you can send a summary of the test run in the email body.
The Recording1 executes some actions on the Windows Calculator which should also run on your machine.
You have to edit the following files:
Program.cs: Enter the email address where you want to send the email from and where you want to send the email to and you have to specify which messages should be logged to the email body, for instance:
MailLogger.ReportLevelMail = ReportLevel.Success;
MailLogger: You have to change the network credentials in the PrepareAndSendMail method.

The Recording2 also checks in the CheckState method if the current test case failed.
I hope this will help you solve the issue!

Regards,
Markus
Ranorex Support Team
You do not have the required permissions to view the files attached to this post.

jchou
Posts: 26
Joined: Tue Apr 24, 2012 11:19 pm

Re: Sending an email of Test Results

Post by jchou » Mon Oct 01, 2012 7:39 am

Thanks, Markus. I used your sample code (modified the test case to use one of mine), and it did send an email with test results, and also attached the report to the email.
One question: in my test case, I need to run multiple iterations (to cover different test sites). Currently, when one iteration failed, the whole execution stopped. (I saw some console messages saying closing down logger, etc.. Is there a way to continue to finish all iterations regardless some of them failed? My test case error behavior is set to continue with siblings when an iteration fails, but that did not seem to help.

Also, could you point me to the APIs of report contents? For example, if I want to print out the test site's URL (targetUrl?), where do I get it?

Thanks.

Joe

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Sending an email of Test Results

Post by Support Team » Tue Oct 02, 2012 12:00 pm

Hi,

You can set the "Error Behavior" of the test case to "Continue with iteration".
Please take a look at the following link: Test Case Settings.
You can print html content with the following code:

Code: Select all

// add some custom HTML message to the XML report
Report.LogHtml(ReportLevel.Info, "Link", "<a href='http://www.ranorex.com/'>Visit www.ranorex.com!</a>");
you can get the URL of the test page via the WebDocument element:
WebDocument yourWebDoc = "";
Report.LogHtml(ReportLevel.Info, "Link", "<a href='"+yourWebDoc .PageUrl+"'>YourText</a>");
Here are also the links to the Reporting section of the UserGuide and of the Online API:
Lesson 8: Reporting
Report Class.
I hope this will help you solve the issue!

Regards,
Markus
Ranorex Support Team

jchou
Posts: 26
Joined: Tue Apr 24, 2012 11:19 pm

Re: Sending an email of Test Results

Post by jchou » Mon Oct 22, 2012 7:54 am

Thanks, Marcus, that (continue with iterations) worked.
One more question: I tried to implement your emailing code to a new project by porting MailLogger.cs and part of Program.cs (the code that calls MailLogger methods) to the new project. The email part seemed to work fine, but the zipped report was not generated. How is the zipped report file (.rxzlog) got generated? Or where is the code that compress the report file into a zipped file? What did I miss to create a compressed report file before it could be attached to email to be sent?

Thanks.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Sending an email of Test Results

Post by Support Team » Mon Oct 22, 2012 10:43 am

Hi,

You find the setting in the properties window of the test suite, see attached screenshot.
ZippedReport.png
Regards,
Markus
Ranorex Support Team
You do not have the required permissions to view the files attached to this post.

jchou
Posts: 26
Joined: Tue Apr 24, 2012 11:19 pm

Re: Sending an email of Test Results

Post by jchou » Tue Nov 06, 2012 3:33 am

Thanks a lot, Markus. That simple checking of Compressed Copy does the trick (I was about to copy my original project over and then add all the test cases to it. So glad to know that one click in the Compressed Copy check box saved all that replication work!)
Now here is a new problem (always one thing leads to another, right?): some receivers of my compressed copy of reports through email could not open the report, since they had not installed Ranorex on their machines. What can they do to be able to open the compressed report without installing Ranorex?