1

In our RIA application, created using ExtJs, we need to capture the time consumed by a user action.

For example, user clicked at a button 'Open' which opens a window, then the time consumed in opening of the window needs to be captured.

We have tried using Selenium IDE, but it only records the actions and executes them back and doesn't log the time consumed in the commands.

We have also tried using 'Profiler' feature of browsers (start profiling before action and stop profiling after action is over), but then that is manual.

Thus, could someone guide at - how to capture the time taken by a user action in Javascript in an automated manner?

Thanks for any help in advance.

netemp
  • 4,115
  • 12
  • 43
  • 63
  • Your answer lies here: http://stackoverflow.com/questions/1210701/compute-elapsed-time-in-javascript –  Feb 01 '13 at 13:35

1 Answers1

0

This is a rough sketch of a global event tracking function:

(function() {

var pairs = {};

eventLogger = function(e) {
    var ts = new Date().getTime();

    if (pairs[e]) {
        var taken = ts - pairs[e],
        img = new Image();
        img.onload = function() { };
        img.src = '/path/to/logger?evt=' + encodeURIComponent(e) + '&t=' + encodeURIComponent(taken);

        delete pairs[e];
    } else {
        pairs[e] = ts;
    }
}

}());

It matches pairs of event names; first one starts the timer, second one makes a server request to log the time taken for that event.

Then, you would log events like these:

eventLogger('loadContacts');
// start code that loads contacts
// ...
// later
eventLogger('loadContacts'); // done loading

It doesn't distinguish between start and stop events, so if you may have overlapping start and stop times, you may need to make some tweaks.

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309