Timestamps in Report instead of duration

Ranorex Studio, Spy, Recorder, and Driver.
segfault
Posts: 2
Joined: Mon Jan 06, 2014 11:36 pm

Timestamps in Report instead of duration

Post by segfault » Wed Apr 02, 2014 10:32 pm

I am trying to search to generate reports to use actual timestamps of operations instead of duration. I came across a forum posting which mentions about using

Code: Select all

    Report.Info("Old Report format!");  
But an additional comment is added in there that this is not recommended and will not be supported in future Ranorex versions. I went through the User Guide to create custom reports but it is still not detailed enough. Is there any other guide or forum to point me in the right direction??

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

Re: Timestamps in Report instead of duration

Post by Support Team » Mon Apr 07, 2014 12:03 pm

Hi,

displaying the starting time (timestamp) of a test case instead of the duration could be realized with the help of the ActivityStack. The ActivityStack provides information about test steps for the report allowing to add custom information ("CustomProperties"). Ranorex will add this information to the report data file, it will not be visible by default but it can be displayed with a simple modification in the transformation file (xslt).

First step - get starting time of Test Suite:
Note: Edited on 2015-08-27; Works for Ranorex Version >= 5.3:
// Get Starting Time
System.DateTime timestamp = Ranorex.Core.Reporting.ActivityStack.Current.BeginTime;
Now, run through all test cases in ActivityStack, calculate the starting time of each test case and add it as a the custom field:
// Iterate through all test cases, calculate starting time and add a custom field
Ranorex.Core.Reporting.ActivityStack.Instance.VisitAll(a =>
{
    if(a.GetType().Name=="TestCaseActivity")
    {			                                						                                		  
        System.DateTime startTime = System.DateTime.Now - (a as Activity).ElapsedTime;
        Report.Info (string.Format ("Started: {0:H:mm:ss}",startTime ));
        (a as Activity).CustomProperties.Add("CustomFieldStartingTime", string.Format ("Started: {0:H:mm:ss}",startTime ));
    }
    return true;
});
Note: (Added on May 9,2014): If you additionally want to have the starting time next to each iteration of a loop, simply enhance the conditional statement and use the following one:
if (a.GetType().Name=="TestCaseActivity" || a.GetType().Name=="TestIterationActivity") ...
Important: Don't forget to update the ActivityStack:
Ranorex.Core.Reporting.ActivityStack.Update();

A final modification needs to be done in the transformation file (xslt):
Line 335: simply replace:
<span class="duration"><xsl:value-of select="./@duration"/></span>
with
<span class="duration"><xsl:value-of select=".//@CustomFieldStartingTime"/></span>
Updated 2014/05/05: closing span-tag has been added in the second line (Roland E)

Note (Added May 9, 2014): To additionally print out the starting time for every iteration in a loop please got to line 392 (in XSL-file)
<xsl:value-of select="./@duration"/>
and use
<xsl:value-of select=".//@CustomFieldStartingTime"/>
instead.

**********************************

Summary:
1.) Download the code module
AddStartTimeToReport.cs
2.) Add the code module "AddStartTimeToReport" to your test suite and place it in the "global" Teardown container
ActivityStack-TestSuite.gif
3.) Activate custom reporting in your Ranorex Solution. More details on custom reporting can be found here: http://www.ranorex.com/support/user-gui ... html#c4898

4.) Download the zip archive, extract the sample xsl-file to your custom report folder (and overwrite the existing one):
RanorexReport5.zip
Your report should look like this now:
ActivityStack-Report.gif
Please let us know in case there are any additional questions!

With kind regards
Ranorex Team
Roland (E)
You do not have the required permissions to view the files attached to this post.

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: Timestamps in Report instead of duration

Post by carsonw » Thu Apr 17, 2014 5:32 pm

Hi Roland! I'm getting Data File or transformation file is missing when trying to implement this.

I've done the custom report template as you said by:

1. Going to the General Settings of the test suite and clicking custom report
2. Letting it create the default folder (.\NewCustomTemplate1\)
3. And then updating the RanorexReport5.xsl file by finding/replacing the items you mentioned (three occurrences).

I think I've missed a step somewhere...

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

Re: Timestamps in Report instead of duration

Post by Support Team » Wed Apr 23, 2014 10:15 am

Hi Carson,

thanks for posting the issue. I guess the problem is based on the modifications you did in the XSLT-file.
"And then updating the RanorexReport5.xsl file by finding/replacing the items you mentioned (three occurrences)."

- Please only replace the first occurrence or simply download and use the xslt-file provided
http://www.ranorex.com/forum/download/file.php?id=2445

It would be very nice if you could quickly let us know whether this was able to solve your issue. Thank you!

Kind regards
Roland (E)
Ranorex Team

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: Timestamps in Report instead of duration

Post by carsonw » Wed Apr 23, 2014 6:12 pm

Hi Roland, I made the changes as you suggested with the same result... so I downloaded your sample, used that and still the result was the same.

I'm running the code module in a test case at the end, this is the contents of the module (pretty sure it's just a copy/paste):

Code: Select all

void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;
                        
            // Read out Starting Time from XML Document
            Ranorex.Core.FastXml.XmlDoc xmlDoc = new Ranorex.Core.FastXml.XmlDoc("dummyRoot", false);
            Ranorex.Core.FastXml.XmlNode xmlNode = Ranorex.Core.Reporting.ActivityStack.Instance.RootActivity.ToXmlNode(xmlDoc);
            string sTimestamp = xmlNode["timestamp"];
            System.DateTime timestamp = Convert.ToDateTime (sTimestamp);
                         
            // Iterate through all test cases, calculate starting time and add custom field
            Ranorex.Core.Reporting.ActivityStack.Instance.VisitAll(a =>
				                                {
				                                	if(a.GetType().Name=="TestCaseActivity")
				                                	{
				                                		
				                                		System.DateTime startTime = System.DateTime.Now - (a as Activity).ElapsedTime;
				                                		Report.Info (string.Format ("Started: {0:H:mm:ss}",startTime ));
				                                		(a as Activity).CustomProperties.Add("CustomFieldStartingTime", string.Format ("Started: {0:H:mm:ss}",startTime ));
			                                		
				                                	}
				                                	return true;
				                                });
				
            Ranorex.Core.Reporting.ActivityStack.Update();            	
        }       

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

Re: Timestamps in Report instead of duration

Post by Support Team » Thu Apr 24, 2014 7:56 am

Hi Carson,

the first thing I would verify is whether the newly created field "CustomFieldStartingTime" does actually exist in the report file (*.rxlog.data).

You can find my Ranorex demo solution here:
DemoActivityStack.zip
and see whether this demo works for you - this might be a good point to start with debugging your project.

Please let us know in case there is any progress.

Thank you
Roland (E)
Ranorex Team
You do not have the required permissions to view the files attached to this post.

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

Re: Timestamps in Report instead of duration

Post by Support Team » Mon May 05, 2014 1:51 pm

Please note: the XML-Code in my original reply has been updated since a closing span-tag was missing there.
Thanks to Carson for providing me additional information!

Kind regards
Roland (E)
Ranorex Team

macgowan
Posts: 14
Joined: Mon Jun 23, 2014 9:20 pm

Re: Timestamps in Report instead of duration

Post by macgowan » Thu Oct 09, 2014 5:55 pm

Hey -

WOW - this timestamp configruation should be a setup parameter for the test - provided by Ranorex. Kinda a usability deal. I hope you add that in the next release.

THAnks,
Chris

BCTest
Posts: 127
Joined: Tue Jun 03, 2014 10:15 am
Location: Hamburg, Germany

Re: Timestamps in Report instead of duration

Post by BCTest » Tue Jun 30, 2015 10:08 am

Hi Ranorex-Team,

looks complex and "manually" for me too. Just a suggestion: Maybe the access on this information could be easier when the timestamp will be written in the data-file together with the duration?

Regards,
Thomas.

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

Re: Timestamps in Report instead of duration

Post by odklizec » Tue Jun 30, 2015 10:15 am

Hi Thomas,

This complicated workaround should soon become obsolete. Ranorex 5.4 should have an option to use time stamps instead of duration in reports. See this post... http://www.ranorex.com/forum/been-askin ... tml#p32853
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

BCTest
Posts: 127
Joined: Tue Jun 03, 2014 10:15 am
Location: Hamburg, Germany

Re: Timestamps in Report instead of duration

Post by BCTest » Tue Jun 30, 2015 10:24 am

odklizec wrote:Hi Thomas,

This complicated workaround should soon become obsolete. Ranorex 5.4 should have an option to use time stamps instead of duration in reports. See this post... http://www.ranorex.com/forum/been-askin ... tml#p32853
Thanks for your quick answer, I'm looking forward on version 5.4.

Regards,
Thomas

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

Re: Timestamps in Report instead of duration

Post by Support Team » Thu Jul 02, 2015 4:06 pm

Hi all,

With Ranorex 5.4 it is also possible to change the format of the timestamp of the reported actions. It is now possible to show the Wall clock (machine time) instead of the duration. In order to also show the wall clock/machine time for the test cases, modules and iterations we can offer two workarounds.

Prerequisite for this solutions will be Ranorex 5.4 and additionally you have to set up “Wall clock (machine time)” as report timestamp.
report_properties.png
First solution: Use customized report template
CustomizeLoggingTimeTemplate_Solution_1.zip
1) Load customized template “CustomizeLoggingTimeTemplate_Solution_1” provided by Ranorex.
Open Test Suite properties – Choose “Report”-tab – Press button “Choose Custom Template”.
report_template.png
2) If you are already using a custom template you need to perform the changes manually. Otherwise your current file state will be overwritten.
a. Open the .xsl-file
b. Replace attribute ‘duration’ with the configuration mentioned below
c. Repeat this action for every occurrence of the duration-attribute in your configuration file (except on test suite level; please have a look below)

Example:
Old configuration: <span class="duration"><xsl:value-of select="./@duration"/></span>
New configuration: <span class="duration"><xsl:value-of select=".//@timeWallClock"/></span>

Do not change the duration value on test suite level.
<xsl:when test="./activity[@type='test suite']">
<i class="field">
Duration <b>
<xsl:value-of select="./activity[@type='test suite']/./@duration"/>
</b>
</i>

After replacing and editing the file, the machine time should be logged.

For further information on custom reports please take a look at http://www.ranorex.com/support/user-gui ... html#c4898
report_example.png
Second solution: Use customized report template and code module
CustomizeLoggingTimeTemplate_Solution_2.zip
CustomizeLoggingTime.cs
1) Add the provided code module CustomizeLoggingTime.cs to your global TEARDOWN-section
2) Use customized template CustomizeLoggingTimeTemplate_Solution_2 for your test suite
3) Add the template to your test suite like described above for the first solution.

In this case you have to use the attribute value “./custom/@ActivityStartTime” instead of ".//@timeWallClock".
teardown_section.PNG
Both solutions will fulfill the requirements. The second solution has the advantage to be more precisely. In this case the exact module start time is logged to the report file.

When using the first solution, the next available action-timestamp within the module will be logged as the module start time. If no actions are logged (depending on the current report level) no time would be available for the module.

Regards,
Johannes
You do not have the required permissions to view the files attached to this post.