Test reports through email

Ask general questions here.
satishmohan
Posts: 56
Joined: Wed Jun 10, 2015 4:35 pm

Test reports through email

Post by satishmohan » Wed Jun 17, 2015 2:37 pm

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.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3937
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Test reports through email

Post by odklizec » Wed Jun 17, 2015 2:50 pm

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.
Pavel Kudrys
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

satishmohan
Posts: 56
Joined: Wed Jun 10, 2015 4:35 pm

Re: Test reports through email

Post by satishmohan » Thu Jun 18, 2015 4:39 pm

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());
}
}
}
}
Attachments
Ranorex.jpg
Ranorex.jpg (213.07 KiB) Viewed 1205 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3937
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Test reports through email

Post by odklizec » Fri Jun 19, 2015 8:07 am

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 (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?
Attachments
CompressedCopy.png
CompressedCopy.png (6.23 KiB) Viewed 1190 times
Pavel Kudrys
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

satishmohan
Posts: 56
Joined: Wed Jun 10, 2015 4:35 pm

Re: Test reports through email

Post by satishmohan » Fri Jun 19, 2015 10:20 am

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;
}
}
}

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3937
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Test reports through email

Post by odklizec » Fri Jun 19, 2015 10:57 am

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.
If it does not enter the "if" block, then the report file most probably does not exists?
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.
From where do you call SendMail module in your project? It must be called from the very end of Program.cs, like this...
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 Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

satishmohan
Posts: 56
Joined: Wed Jun 10, 2015 4:35 pm

Re: Test reports through email

Post by satishmohan » Fri Jun 19, 2015 12:12 pm

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.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3937
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Test reports through email

Post by odklizec » Fri Jun 19, 2015 12:27 pm

I believe you must call it like this:

Code: Select all

SendMail.SendMail();  
First SendMail points to SendMail.cs, second SendMail points to SendMail() method ;)
Pavel Kudrys
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

satishmohan
Posts: 56
Joined: Wed Jun 10, 2015 4:35 pm

Re: Test reports through email

Post by satishmohan » Fri Jun 19, 2015 12:39 pm

Yes :D . I called it by the Classname.methodname ( SendMail.Sendmail(); )

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3937
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Test reports through email

Post by odklizec » Fri Jun 19, 2015 12:45 pm

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 Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

satishmohan
Posts: 56
Joined: Wed Jun 10, 2015 4:35 pm

Re: Test reports through email

Post by satishmohan » Fri Jun 19, 2015 1:14 pm

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.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3937
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Test reports through email

Post by odklizec » Fri Jun 19, 2015 1:25 pm

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...
UploadFile.png
UploadFile.png (8.99 KiB) Viewed 1169 times
Pavel Kudrys
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

satishmohan
Posts: 56
Joined: Wed Jun 10, 2015 4:35 pm

Re: Test reports through email

Post by satishmohan » Fri Jun 19, 2015 1:35 pm

Thank you. Followed as suggested :)
Attachments
Mail_2.zip
(69.76 KiB) Downloaded 60 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3937
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Test reports through email

Post by odklizec » Fri Jun 19, 2015 2:08 pm

Here you go. Now it should work ;)
Mail_2_pku.zip
(60.58 KiB) Downloaded 92 times

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?
Pavel Kudrys
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

satishmohan
Posts: 56
Joined: Wed Jun 10, 2015 4:35 pm

Re: Test reports through email

Post by satishmohan » Fri Jun 19, 2015 2:33 pm

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.