How to change format of duration in report?

Best practices, code snippets for common functionality, examples, and guidelines.
BCTest
Posts: 88
Joined: Tue Jun 03, 2014 10:15 am
Location: Hamburg, Germany

How to change format of duration in report?

Post by BCTest » Wed Feb 04, 2015 8:15 am

I found two interesting lines in a "standard.html.data"-file

Code: Select all

duration="1.1h"
durationms="4122722"
and it looks like those values can be used in xml-stylesheet "RanorexReport5.xsl":

Code: Select all

<span class="duration"><xsl:value-of select="./@duration"/></span>
Is it possible to display the duration instead of "1.1h" in minutes like "68:42,722min"?

It would be fantastic, if this format could also be used for short tests, e.g.

Code: Select all

duration="358ms"
durationms="358"
displayed as "00:00,358min" instead of "358ms".

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

Re: How to change format of duration in report?

Post by Support Team » Fri Feb 06, 2015 4:20 pm

Hello BCTest,

Unfortunately there is no simple setting, but I can try the workaround below.

1) Create a custom report template
2) Modify RanorexReport5.xsl
<i class="field">
                Duration <b class="customDuration">   /* <-- Add class  */
       <xsl:value-of select="./activity[@type='test suite']/./@durationms"/>   /* <-- Changed to durationms */
       </b>
    </i>

3) In View.rxlog add:
$(document).ready(function() {                                
                var str_durationms = $('.customDuration')[0].innerHTML;            
                $('.customDuration')[0].innerHTML = str_durationms.toHHMMSSmmm();
});

String.prototype.toHHMMSSmmm = function () {
                var totalms = parseInt(this, 10);                 
                var ms = totalms % 1000;
                var sec_num = Math.floor(totalms / 1000);
                var hours   = Math.floor(sec_num / 3600);
                var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
                var seconds = sec_num - (hours * 3600) - (minutes * 60);

                if (hours   < 10) {hours   = "0"+hours;}
                if (minutes < 10) {minutes = "0"+minutes;}
                if (seconds < 10) {seconds = "0"+seconds;}
                if (ms < 100) { ms = "0"+ms; }
                if (ms < 10) { ms = "0"+ms; }
                
                var time = hours+':'+minutes+':'+seconds+'.'+ms;
                return time;
}
I hope this is what you need.

Regards,
Bernhard
.
Image

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

Re: How to change format of duration in report?

Post by BCTest » Mon Feb 09, 2015 6:00 pm

Support Team wrote:
$(document).ready(function() {                                
                var str_durationms = $('.customDuration')[0].innerHTML;            
                $('.customDuration')[0].innerHTML = str_durationms.toHHMMSSmmm();
});

String.prototype.toHHMMSSmmm = function () {
                var totalms = parseInt(this, 10);                 
                var ms = totalms % 1000;
                var sec_num = Math.floor(totalms / 1000);
                var hours   = Math.floor(sec_num / 3600);
                var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
                var seconds = sec_num - (hours * 3600) - (minutes * 60);

                if (hours   < 10) {hours   = "0"+hours;}
                if (minutes < 10) {minutes = "0"+minutes;}
                if (seconds < 10) {seconds = "0"+seconds;}
                if (ms < 100) { ms = "0"+ms; }
                if (ms < 10) { ms = "0"+ms; }
                
                var time = hours+':'+minutes+':'+seconds+'.'+ms;
                return time;
}
I hope this is what you need.

Regards,
Bernhard
Sadly there seems to be a problem :(
I modified a report that was generated today:
- first the "RanorexReport5.xsl"-file (the report can still be displayed in Waterfox and IE) and
- afterwards the "Standard.html"-file (the report can still be displayed in Waterfox and IE if I add only the function)

In my "standard.html"-file your function is already implemented, so I add only those two lines:
$(document).ready(function ()
    {
        tb_init('a.thickbox, area.thickbox, input.thickbox'); //pass where to apply thickbox
        imgLoader = new Image(); // preload image
        imgLoader.src = tb_pathToImage;


	var str_durationms = $('.customDuration')[0].innerHTML;              
	$('.customDuration')[0].innerHTML = str_durationms.toHHMMSSmmm();  
    });
Can I not modify a report that was generated to test your workaround?

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to change format of duration in report?

Post by krstcs » Mon Feb 09, 2015 6:12 pm

I believe the report has to be generated with the function Bernhard mentioned or it won't work as expected.

You are changing the template with these things, not the report itself. The report has to be generated with the template or the functionality won't work.
Shortcuts usually aren't...

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

Re: How to change format of duration in report?

Post by BCTest » Tue Feb 10, 2015 8:22 am

krstcs wrote:I believe the report has to be generated with the function Bernhard mentioned or it won't work as expected.
Thanks for your answer,
krstcs.

As you mentioned I made a new test-project using Windows-Notepad Three little test-cases are included:
  • - Start Notepad
    - Verify Notepad is visible and type something
    - Close Notepad
I modified those two files described as in the post from Bernhard. But it still won't works: the report is empty - what am I doing wrong? :roll: :oops: :(
Can you please help me?
I attached my whole test-project (made with version 5.2.2) including the solution, the template and some reports.
TestReport.zip
TestReport - Test-project
(650 KiB) Downloaded 102 times

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

Re: How to change format of duration in report?

Post by Support Team » Fri Feb 13, 2015 1:32 pm

Hi BCTest,

Sorry, there are multiple document.onload functions registered. The code should be executed after the Report initialization. Please move the code to a separate location .
$(document).ready(function() {                                  
                var str_durationms = $('.customDuration')[0].innerHTML;              
                $('.customDuration')[0].innerHTML = str_durationms.toHHMMSSmmm();  
});
At the bottom of the document is the best location (so it gets registered last).
Another way is to add the lines after the initialization (see attached View.rxlog).

You can also just use the attached *.rxlog file instead :-).
RXLOG.zip
(157 KiB) Downloaded 74 times
I hope it works now.

Regards,
Bernhard
.
Image

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

Re: How to change format of duration in report?

Post by BCTest » Fri Feb 13, 2015 3:15 pm

Support Team wrote:I hope it works now.

Regards,
Bernhard
Yes, thanks!
Looks much better now.

Just one more little question at the end:
Can/How can I use this format also in the steps of the test?

When I change "the value-of-select"
<span class="duration"><xsl:value-of select="./@duration"/></span>
from "duration" to "durationms" the time is always displayed in milliseconds. It would be great if the same format could be used at this place like in the heading.
Regards,
Thomas

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

Re: How to change format of duration in report?

Post by Support Team » Tue Feb 17, 2015 10:04 am

Hello Thomas,

You will need to do the following:

1) XSL: add customDuration as class and select durationms for all occurences of the select

Code: Select all

<span class="duration customDuration"><xsl:value-of select="./@durationms"/></span>
2) View.rxlog format all durations

Code: Select all

$(document).ready(function() {  
  ApplyCustomFormat();
 });
 
function ApplyCustomFormat()
{
 $('.customDuration').each( 
  function() 
  { 
   var str_durationms = this.innerHTML; 
   if (!IsAlreadyFormated(str_durationms))
   {
    this.innerHTML = str_durationms.toHHMMSS();
   }
  } 
 );
}

function IsAlreadyFormated(str)
{
 return str.indexOf(':') >= 0;
}
3) View.rxlog format when data is dynamically loaded:

Code: Select all

function OnLoadContentDynamic(rId, objectType, thisObject)
{
    ...
 ApplyCustomFormat();
}
Hope this information helps.

Regards,
Robert
Attachments
ModifiedFiles.zip
(166.41 KiB) Downloaded 73 times
.
Image

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

Re: How to change format of duration in report?

Post by BCTest » Wed Feb 18, 2015 8:02 am

Duration.png
Duration
Duration.png (31.21 KiB) Viewed 1395 times
Thanks for your solution and patience, this is exactly what we wanted.
We store each test report and now those reports can be better compared because the duration is always displayed in the same measurement unit.
Support Team wrote:Unfortunately there is no simple setting, but I can try the workaround below.
I agree: it's surprisingly difficult. Maybe your developer team will think about a simpler way to modify the duration display in the test reports?
For my case your solution is a great improvement.

Regards,
Thomas.

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

Re: How to change format of duration in report?

Post by Support Team » Thu Feb 19, 2015 10:46 am

Hello Thomas,

I'm very pleased to hear that.

In order to raise and discuss feature requests may I ask you to send an email [email protected]? We want to handle feature request via email in order to avoid misunderstandings.

Regards,
Robert
.
Image