Announcement

Collapse
No announcement yet.

javascript stopwatch for actual test duration

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • javascript stopwatch for actual test duration

    This one is not quite polished yet and a lot more complicated, but it gets the job done... I've written a little javascript 'stopwatch' that will automatically fill in the actual test duration. All you have to do is hit the start button at the beginning of executing the test, and hit the stop button when you're done, and it will fill in the time between button pushes into the actual test duration field. here's the code:

    three global variables (outside the scope of any functions, at the top of the <script> section of the template):

    var startTime;
    var endTime;
    var flagstop = 0;

    the actual function you'll be calling with your new button:

    function StartStop()
    {
    if ( flagstop == 0)
    {
    startTime = new Date();
    var clocktimer = document.getElementById('clock');
    clocktimer.value = startTime.getHours()+":"+startTime.getMinutes();
    document.TLForm.elements.TL_ACTDURATION_EDIT.value = " ";
    var startstop = document.getElementById('startstopbutton');
    flagstop = 1;
    startstop.value = 'Stop';
    return;
    }
    if ( flagstop == 1)
    {
    endTime = new Date();
    var totalHours = endTime.getHours() - startTime.getHours();
    if ( totalHours < 10)
    totalHours = "0" + totalHours;
    var totalMinutes = endTime.getMinutes() - startTime.getMinutes();
    if(totalMinutes < 0)
    totalMinutes = 60 + totalminutes;
    if( totalMinutes < 10)
    totalMinutes = "0" + totalMinutes;
    document.TLForm.elements.TL_ACTDURATION_EDIT.value = totalHours+":"+totalMinutes;
    flagstop = 0;
    var startstop = document.getElementById('startstopbutton');
    startstop.value = 'Start';
    return;
    }
    return;
    }

    in the table where the actual duration is listed, replace:

    <td class=TestCaseData><!--TL_ACTDURATION_EDIT--></td>

    with:
    <td class=TestCaseData><!--TL_ACTDURATION_EDIT--> <input id="clock" type="text" value="00:00" size=3 readonly> <input id="startstopbutton" type=button value="Start" onClick=StartStop()></td>

    (add the two input's after the <!--TL_ACTDURATION_EDIT-->)

    I'm hoping to figure out why an actual stopwatch won't work here. I tried using someone else's stopwatch code, but I couldn't get it to actually count, so instead it just displays the start time in the clock field.

  • #2
    there were some problems handing tests that crossed hour boundaries (a test that started at 1:45 and ended at 2:15)... i fixed those, and here's the new and improved startstop function:

    function StartStop()
    {
    if ( flagstop == 0)
    {
    startTime = new Date();
    var clocktimer = document.getElementById('clock');
    clocktimer.value = startTime.getHours()+":"+startTime.getMinutes();
    document.TLForm.elements.TL_ACTDURATION_EDIT.value = " ";
    var startstop = document.getElementById('startstopbutton');
    flagstop = 1;
    startstop.value = 'Stop';
    return;
    }
    if ( flagstop == 1)
    {
    endTime = new Date();
    var totalHours = endTime.getHours() - startTime.getHours();
    if(endTime.getMinutes() < startTime.getMinutes())
    {
    totalMinutes = 60 - startTime.getMinutes() + endTime.getMinutes();
    totalHours = totalHours - 1;
    }
    if(endTime.getMinutes() >= startTime.getMinutes())
    {
    var totalMinutes = endTime.getMinutes() - startTime.getMinutes();
    }
    if ( totalMinutes < 0)
    {
    totalMinutes = 60 + totalminutes;
    }
    if ( totalHours < 10)
    {
    totalHours = "0" + totalHours;
    }
    if( totalMinutes < 10)
    {
    totalMinutes = "0" + totalMinutes;
    }
    document.TLForm.elements.TL_ACTDURATION_EDIT.value =totalHours+":"+totalMinutes;
    flagstop = 0;
    var startstop = document.getElementById('startstopbutton');
    startstop.value = 'Start';
    return;
    }
    return;
    }

    Comment


    • #3
      I'm guessing this displays the timer buttons in the web-based version, not the client version? Regardless, PassMark should pay you for coming up with these cool hacks!

      Currently, I use TaskBlaze to track how long I spend on various tasks, including individual test cases. Bonus: it integrates with Outlook and can automatically record time spent on tasks in your calendar.

      Requires the .NET framework.

      Comment


      • #4
        yeah, any javascript i've been posting is all for the web-based app... for our use case, all our testers are using the web app, and only the admin's are using the standalone software. We do this so that we (the admin's) have more control over what goes into the test cases, and how they are updated, instead of just letting everyone be able to edit all the test cases without any trackability of the changes. I've been trying to make the job of our testers easier by hacking together some javascript (which i only can do because it's so similar to java/c#/c++, in which i have a little more experience, and we use c# in our company).

        I figured if it helped us, it might help somone else, so why not share with the testlog community?

        Comment


        • #5
          Product Evaluation

          We are currently looking at TestLog and I was looking for feedback from current users as to the tools Web Capability. You seem to be a focused user. Your thougts?

          Comment

          Working...
          X