Custom Report Log

Class library usage, coding and language questions.
puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Custom Report Log

Post by puntapret » Mon Oct 15, 2012 9:16 am

Hi,

As i'm in learning curve on Ranorex product, i want to do some custom reporting. I will try to describe step by step what i'm doing.

I used the Mail Logger provided in this post : http://www.ranorex.com/blog/customizing-ranorex-reports

And since i only want to log success/failure/error in my custom mail logger. In my IReportLogger.LogData and IReportLogger.LogText, i did the following code to check the report level, to log only the ReportLevel that i want, but I THINK this is not the best method.

Code: Select all

if (level.Equals(ReportLevel.Failure) ||
level.Equals(ReportLevel.Error) ||
level.Equals(ReportLevel.Success))
And i received the mail :

Code: Select all

2012/10/15 09:34:38.215	SUCCESS	Test	Test Module 'OpenBrowser' completed with status 'Success'.
2012/10/15 09:34:39.985	SUCCESS	Validation	Screenshot of item 'PortalRepository.Portal.Container.txt_Connect' does contain the specified image.
2012/10/15 09:34:41.203	SUCCESS	Test	Test Module 'PortalVisualTest' completed with status 'Success'.
2012/10/15 09:34:41.659	SUCCESS	Test	Test Module 'CloseBrowser' completed with status 'Success'.
2012/10/15 09:34:43.732	SUCCESS	Test	Test Module 'WriteErrorMessage' completed with status 'Success'.
2012/10/15 09:34:43.732	SUCCESS	Test	Test Case Iteration #1 completed with status 'Success'.
2012/10/15 09:34:43.732	SUCCESS	Test	Test Case 'PortalVisualResponsiveness' completed with status 'Success'.
2012/10/15 09:34:43.732	SUCCESS	Test	Test Suite 'IntegrationTest' completed with status 'Success'.
I'm not quite satisfied with this, what i want to do actually, is just give a brief reporting without polluting with all the Test Module success information. So the mail result should be like this :

Code: Select all

2012/10/15 09:34:43.732	SUCCESS	Test	Test Case 'PortalVisualResponsiveness' completed with status 'Success'.
2012/10/15 09:34:43.732	SUCCESS	Test	Test Suite 'IntegrationTest' completed with status 'Success'.
Is it possible to achieve simply ? And how can i change the default message : Test Case 'TEST_CASE_NAME' completed with status 'STATUS'. and Test Suite 'TEST_SUITE_NAME' completed with status 'STATUS' ?

I also read this post :
http://www.ranorex.com/forum/ranorex-re ... tml#p11489

They are talking about metainfos in the LogData and LogText, where are they exactly ?

Thanks in advance.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Custom Report Log

Post by Support Team » Tue Oct 16, 2012 5:11 pm

Hi,

You can use the "metaInfos" parameter to determine which kind of messages should be added to the mail.
In order to analyze the metaInfos you could output them in the LogText method of your custom logger:
foreach( KeyValuePair<string, string> kvp in metaInfos )
			{
				Console.WriteLine("Key = {0}, Value = {1}",
				                  kvp.Key, kvp.Value);
			}
The easiest solution would be to use a "custom" Category in order to determine if the message should be logged to the mail or not.
Therefore please take a look at the attached sample, there you will see how it could work.
There is just one if clause, in the LogText method, which will check if the category of the log message if of type "MyCustomCategory", if it is the message will be added otherwise not.
The only thing you have to add to the teardown region of each test case is a CodeModule which should check if the test case was successfully executed.

Do you want to change the style of a log message in the report file (rxlog file) itself or for the logged messages of the email?

Regards,
Markus
Ranorex Support Team
Attachments
SampleSolution.zip
(703.88 KiB) Downloaded 422 times
.
Image

puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Re: Custom Report Log

Post by puntapret » Thu Oct 18, 2012 3:04 pm

Thank you Markus for your time to reply to my question.

I will look to your example thoroughly.

To answer your question.

Yes, i would like to change the style for the logged messages of the email and on the rxlog file.

And where can i find the metainfos, which object that hold this property ?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Custom Report Log

Post by Support Team » Fri Oct 19, 2012 10:53 am

Hi,

You're welcome!
You will find it in the LogData and LogText methods in the MailLogger class.
The style of the mail can also be defined in the MailLogger class as shown in the sample.

Regards,
Markus
Ranorex Support Team
.
Image

jaredmatthews
Posts: 16
Joined: Fri Apr 18, 2014 1:06 pm

Re: Custom Report Log

Post by jaredmatthews » Wed Jul 02, 2014 4:40 pm

Hi Markus,

I have the email sending the custom category only now in the email:
report.png
report.png (17.87 KiB) Viewed 4389 times
The problem is if a test fails the email always says passes. I used this from your example:

Code: Select all

if (category == "User") {
			 //if (ReportLevelMail.Level <= level.Level) {
				CheckSuccess(level);
				mail.Body += string.Format("[{0}][{1, -7}][{2}]: {3}\n", GetTimeStamp(),
				                           level, category, message);
	
				string htmlMessage = escape ? System.Web.HttpUtility.HtmlEncode(message) : message;
				htmlText += String.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",
				                          GetTimeStamp(), level.ToString().ToUpper(), category, htmlMessage);
			}
		}
How do i get it to still use the commented out functionality: //if (ReportLevelMail.Level <= level.Level) . Sorry I do not have much of a coding background.

I only want to report custom category, but if there are failures i want to include them. Any advice?

Am i missing this part: The only thing you have to add to the teardown region of each test case is a CodeModule which should check if the test case was successfully executed.

Do you have an example of this?

Thanks,
Jared
Regards,
Jared

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Custom Report Log

Post by Support Team » Thu Jul 03, 2014 2:37 pm

Hello Jared,

If you want to add failures messages to you report mail you could do something similar to the code below :wink: :
public void LogText(ReportLevel level, string category, string message, bool escape, IDictionary<string, string> metaInfos)
		{
			CheckSuccess(level);
			
			if (ReportLevelMail.Level <= level.Level && success == true) {
				
				if(category.Equals("User"))
			{
				
				mail.Body += string.Format("[{0}][{1, -7}][{2}]: {3}\n", GetTimeStamp(),
				                           level, category, message);
	
				string htmlMessage = escape ? System.Web.HttpUtility.HtmlEncode(message) : message;
				htmlText += String.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",
				                          GetTimeStamp(), level.ToString().ToUpper(), category, htmlMessage);
			}
			}
			else {
			{
					mail.Body += string.Format("[{0}][{1, -7}][{2}]: {3}\n", GetTimeStamp(),
				                           level, category, message);
	
				string htmlMessage = escape ? System.Web.HttpUtility.HtmlEncode(message) : message;
				htmlText += String.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",
				                          GetTimeStamp(), level.ToString().ToUpper(), category, htmlMessage);
				
			}
			}
Regarding your second issue:
The only thing you have to add to the teardown region of each test case is a CodeModule which should check if the test case was successfully executed.
Please add a Code Module with following code snippet to the tear down section of your test cases:
// this code checks if the current test case failed
if (Ranorex.Core.Testing.TestCase.Current.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Failed))
			{
        		Report.Info("The test case failed!");
}
Regards,
Robert
.
Image

jaredmatthews
Posts: 16
Joined: Fri Apr 18, 2014 1:06 pm

Re: Custom Report Log

Post by jaredmatthews » Mon Jul 07, 2014 2:42 pm

Thanks Robert this worked!
Regards,
Jared