Test reports through email
-
- Posts: 56
- Joined: Wed Jun 10, 2015 4:35 pm
Test reports through email
Hi,
I have gone through the post on mailing where you have suggested using the example of CustomLogging. I am unable to follow this example. could you please suggest how to anaylze the same. I just see there is a MailLogger.cs file included. How do I include this if required in my Test case and what are the next steps.
I have gone through the post on mailing where you have suggested using the example of CustomLogging. I am unable to follow this example. could you please suggest how to anaylze the same. I just see there is a MailLogger.cs file included. How do I include this if required in my Test case and what are the next steps.
Re: Test reports through email
Hi,
I would suggest you to follow this discussion.
http://www.ranorex.com/forum/send-mail- ... t2356.html
The SendMail.cs discussed there is still valid and works OK with Ranorex 5.x.
I would suggest you to follow this discussion.
http://www.ranorex.com/forum/send-mail- ... t2356.html
The SendMail.cs discussed there is still valid and works OK with Ranorex 5.x.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 56
- Joined: Wed Jun 10, 2015 4:35 pm
Re: Test reports through email
Hi,
Thanks for earlier response. I am able to send the mail but the report log ( .rxzlog) is not being attached. The sendMail() is the last part of code. Please find below on how to add attachments. Also looked at other disucssions on this topic, but could not complete attachment. Also attached snapshot.
SendMail.cs file
--------------------
/*
* Created by Ranorex
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Net.Mail;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
namespace Ranorex.Modules
{
/// <summary>
/// Use this module at any position of your test suite to get informed about test runs by email.
/// This is especially useful for overnight test executions on runtime machines.
/// </summary>
[TestModule("EEE7C8D8-D950-40EF-B24A-1A9A87C0DA21", ModuleType.UserCode, 1)]
public class SendMailModule : ITestModule
{
/// <summary>
/// Constructs a new instance.
/// </summary>
public SendMailModule()
{
// Do not delete SendMailModule method - a parameterless constructor is required!
// If the Mail Server requires basic authentication where windows authentication is not sufficient//
// SmtpClient smtp = new SmtpClient(ServerHostname, int.Parse(ServerPort));
// smtp.Credentials = new System.Net.NetworkCredential("userName", "password");
// smtp.Send(mail);
}
#region Variables
string _to = "[email protected]";
[TestVariable("D089186D-7919-4023-8165-B68F9151C6A7")]
public string To
{
get { return _to; }
set { _to = value; }
}
string _from = "[email protected]";
[TestVariable("BDB3FC8C-1E51-448F-9049-AEF0B247DBDB")]
public string From
{
get { return _from; }
set { _from = value; }
}
string _subject = "Ranorex eMail Module Report";
[TestVariable("398FF772-C15C-4b91-954B-34CC636DEDC9")]
public string Subject
{
get { return _subject; }
set { _subject = value; }
}
string _serverHostName = "Smtp.xxxx.com";
[TestVariable("0EE4CB1E-D738-4DE8-B122-92B3CCE6F70C")]
public string ServerHostname
{
get { return _serverHostName; }
set { _serverHostName = value; }
}
string _serverPort = "25";
[TestVariable("4C6A889D-BACE-4AE1-9EEF-40EA26775574")]
public string ServerPort
{
get { return _serverPort; }
set { _serverPort = value; }
}
string _message = "Ranorex Success email configuration";
[TestVariable("D49672F4-3021-4460-96DA-2EC11AE318A8")]
public string Message
{
get { return _message; }
set { _message = value; }
}
#endregion
void ITestModule.Run()
{
SendMail();
}
void SendMail()
{
// get the zipped report file path
try
{
MailMessage mail = new MailMessage(From, To, Subject, Message);
// Ranorex.Core.Reporting.TestReport.SaveReport();
////////////////////////////////////
// String zipFileName = Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportViewFilePath;
String zipFileName = Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportZipFilePath;
// adds the zipped report to the mail
if (System.IO.File.Exists(zipFileName))
{
System.Net.Mail.Attachment MyReport = new System.Net.Mail.Attachment(zipFileName);
mail.Attachments.Add (MyReport);
}
///////////////////////////////////
SmtpClient smtp = new SmtpClient(ServerHostname, int.Parse(ServerPort));
smtp.Send(mail);
Report.Success("Email has been sent to '" + To + "'.");
}
catch(Exception ex)
{
Report.Failure("Mail Error: " + ex.ToString());
}
}
}
}
Thanks for earlier response. I am able to send the mail but the report log ( .rxzlog) is not being attached. The sendMail() is the last part of code. Please find below on how to add attachments. Also looked at other disucssions on this topic, but could not complete attachment. Also attached snapshot.
SendMail.cs file
--------------------
/*
* Created by Ranorex
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Net.Mail;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
namespace Ranorex.Modules
{
/// <summary>
/// Use this module at any position of your test suite to get informed about test runs by email.
/// This is especially useful for overnight test executions on runtime machines.
/// </summary>
[TestModule("EEE7C8D8-D950-40EF-B24A-1A9A87C0DA21", ModuleType.UserCode, 1)]
public class SendMailModule : ITestModule
{
/// <summary>
/// Constructs a new instance.
/// </summary>
public SendMailModule()
{
// Do not delete SendMailModule method - a parameterless constructor is required!
// If the Mail Server requires basic authentication where windows authentication is not sufficient//
// SmtpClient smtp = new SmtpClient(ServerHostname, int.Parse(ServerPort));
// smtp.Credentials = new System.Net.NetworkCredential("userName", "password");
// smtp.Send(mail);
}
#region Variables
string _to = "[email protected]";
[TestVariable("D089186D-7919-4023-8165-B68F9151C6A7")]
public string To
{
get { return _to; }
set { _to = value; }
}
string _from = "[email protected]";
[TestVariable("BDB3FC8C-1E51-448F-9049-AEF0B247DBDB")]
public string From
{
get { return _from; }
set { _from = value; }
}
string _subject = "Ranorex eMail Module Report";
[TestVariable("398FF772-C15C-4b91-954B-34CC636DEDC9")]
public string Subject
{
get { return _subject; }
set { _subject = value; }
}
string _serverHostName = "Smtp.xxxx.com";
[TestVariable("0EE4CB1E-D738-4DE8-B122-92B3CCE6F70C")]
public string ServerHostname
{
get { return _serverHostName; }
set { _serverHostName = value; }
}
string _serverPort = "25";
[TestVariable("4C6A889D-BACE-4AE1-9EEF-40EA26775574")]
public string ServerPort
{
get { return _serverPort; }
set { _serverPort = value; }
}
string _message = "Ranorex Success email configuration";
[TestVariable("D49672F4-3021-4460-96DA-2EC11AE318A8")]
public string Message
{
get { return _message; }
set { _message = value; }
}
#endregion
void ITestModule.Run()
{
SendMail();
}
void SendMail()
{
// get the zipped report file path
try
{
MailMessage mail = new MailMessage(From, To, Subject, Message);
// Ranorex.Core.Reporting.TestReport.SaveReport();
////////////////////////////////////
// String zipFileName = Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportViewFilePath;
String zipFileName = Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportZipFilePath;
// adds the zipped report to the mail
if (System.IO.File.Exists(zipFileName))
{
System.Net.Mail.Attachment MyReport = new System.Net.Mail.Attachment(zipFileName);
mail.Attachments.Add (MyReport);
}
///////////////////////////////////
SmtpClient smtp = new SmtpClient(ServerHostname, int.Parse(ServerPort));
smtp.Send(mail);
Report.Success("Email has been sent to '" + To + "'.");
}
catch(Exception ex)
{
Report.Failure("Mail Error: " + ex.ToString());
}
}
}
}
You do not have the required permissions to view the files attached to this post.
Re: Test reports through email
Have,
Are you sure you have enabled Compressed copy check and the Sendmail method is the last line in Program.cs (just before "return")?
[attachment=0]CompressedCopy.png[/attachment ]
Also, have you tried to debug the code? I would suggest to add breakpoint at this line:
If none of the above helps, try to add these lines just before sendmail line (in Program.cs)
These lines should complete testcase and force saving report to file. Hope this helps?
Are you sure you have enabled Compressed copy check and the Sendmail method is the last line in Program.cs (just before "return")?
[attachment=0]CompressedCopy.png[/attachment ]
Also, have you tried to debug the code? I would suggest to add breakpoint at this line:
if (System.IO.File.Exists(zipFileName))Then run the project and check if zipFileName exsits and if code goes inside this condition.
If none of the above helps, try to add these lines just before sendmail line (in Program.cs)
Ranorex.Core.Reporting.TestReport.EndTestCase(); Ranorex.Core.Reporting.TestReport.SaveReport();
These lines should complete testcase and force saving report to file. Hope this helps?
You do not have the required permissions to view the files attached to this post.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 56
- Joined: Wed Jun 10, 2015 4:35 pm
Re: Test reports through email
Hi,
I have enabled "Compressed copy" option and also attempted to enter if (System.IO.File.Exists(zipFileName)) . Looks it it not entering the if-block. Not clear on how to insert Sendmail method as the last line in Program.cs (just before "return")?. Please suggest as this is to be resolved asap.
Program.cs
--------------
using System;
using System.Threading;
using System.Drawing;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using WinForms = System.Windows.Forms;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Reporting;
using Ranorex.Core.Testing;
namespace Mail_2
{
class Program
{
[STAThread]
public static int Main(string[] args)
{
// Uncomment the following 2 lines if you want to automate Windows apps
// by starting the test executable directly
//if (Util.IsRestartRequiredForWinAppAccess)
// return Util.RestartWithUiAccess();
Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
int error = 0;
try
{
error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);
}
catch (Exception e)
{
Report.Error("Unexpected exception occurred: " + e.ToString());
error = -1;
}
return error;
}
}
}
I have enabled "Compressed copy" option and also attempted to enter if (System.IO.File.Exists(zipFileName)) . Looks it it not entering the if-block. Not clear on how to insert Sendmail method as the last line in Program.cs (just before "return")?. Please suggest as this is to be resolved asap.
Program.cs
--------------
using System;
using System.Threading;
using System.Drawing;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using WinForms = System.Windows.Forms;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Reporting;
using Ranorex.Core.Testing;
namespace Mail_2
{
class Program
{
[STAThread]
public static int Main(string[] args)
{
// Uncomment the following 2 lines if you want to automate Windows apps
// by starting the test executable directly
//if (Util.IsRestartRequiredForWinAppAccess)
// return Util.RestartWithUiAccess();
Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
int error = 0;
try
{
error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);
}
catch (Exception e)
{
Report.Error("Unexpected exception occurred: " + e.ToString());
error = -1;
}
return error;
}
}
}
Re: Test reports through email
If it does not enter the "if" block, then the report file most probably does not exists?satishmohan wrote:Hi,
I have enabled "Compressed copy" option and also attempted to enter if (System.IO.File.Exists(zipFileName)) . Looks it it not entering the if-block.
From where do you call SendMail module in your project? It must be called from the very end of Program.cs, like this...satishmohan wrote:Not clear on how to insert Sendmail method as the last line in Program.cs (just before "return")?. Please suggest as this is to be resolved asap.
SendMail.SendMail(); return error; } } }If it still does not work, could you please share your project?
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 56
- Joined: Wed Jun 10, 2015 4:35 pm
Re: Test reports through email
Hi,
I called the SendMail() (in Program.cs) method as suggested, but was getting below compile error while executing.
"The name SendMail() does not exist in the current context". Attached Project.
I called the SendMail() (in Program.cs) method as suggested, but was getting below compile error while executing.
"The name SendMail() does not exist in the current context". Attached Project.
Re: Test reports through email
I believe you must call it like this:
First SendMail points to SendMail.cs, second SendMail points to SendMail() method 
Code: Select all
SendMail.SendMail();

Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 56
- Joined: Wed Jun 10, 2015 4:35 pm
Re: Test reports through email
Yes
. I called it by the Classname.methodname ( SendMail.Sendmail(); )

Re: Test reports through email
You mean you called it that way before my previous post? If it still does not work, I would suggest to share your project. There must be something else wrong?
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 56
- Joined: Wed Jun 10, 2015 4:35 pm
Re: Test reports through email
Yes. I had it tried before your suggestion. This is the first time i am in this forum, can you please suggest how to share a project here. Earlier tried attaching the complete project folder C:\Users\satish\Documents\Ranorex\RanorexStudio Projects\Mail_2 which was about 28MB, zipped to 9 MB. not sure if you received it.
Re: Test reports through email
Just delete bin, obj and Reports folders from the solution before packing it. This should reduce the size of zip
Then use interface found under "Upload attachment" tab...

You do not have the required permissions to view the files attached to this post.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 56
- Joined: Wed Jun 10, 2015 4:35 pm
Re: Test reports through email
Thank you. Followed as suggested 

You do not have the required permissions to view the files attached to this post.
Re: Test reports through email
Here you go. Now it should work
There was incorrect namespace in SendMail.cs and missing line before SendMail.SendMail();
Also, SendMail.cs should not be inside the TestSuite structure. Hope this helps?

There was incorrect namespace in SendMail.cs and missing line before SendMail.SendMail();
Also, SendMail.cs should not be inside the TestSuite structure. Hope this helps?
You do not have the required permissions to view the files attached to this post.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 56
- Joined: Wed Jun 10, 2015 4:35 pm
Re: Test reports through email
Hi, Great. Works perfect. I could analyze the difference through diff checker. Class name, public access are some things to be take care by me further. A great thanks to you.