Wednesday 24 September 2014

Mercury Timers Object


  1. Mercury Timer object is a  internal timer object that measures the amount of time in milliseconds.

    Mercury Timer Methods

        Continue Method  - Continue counting
        Reset Method - Reset timer
        Start Method - Starts Timer
        Stop Method - Stops Timer

    Mercury Timer Property

        ElapsedTime Property


    Example - 

    MercuryTimers("Timer1").Start
    Wait 2
    MercuryTimers("Timer1").Stop 
    print  MercuryTimers("Timer1").ElapsedTime 

    Thus we can find the elapsed time in milliseconds using mercury timer object.

     
  2.  ###############################################  
  3. '           Mercury Timers & Timer Object   
  4. '###############################################  
  5.   
  6. 'Purpose - To Create a Timer which will work like a stop watch  
  7.   
  8. 'We can create multiple Timers using Mercury Timers Object.  
  9. 'Every Timer can be controlled by Timer Object  
  10. ' It has some facilities to start, stop, continue and reset the Timers  
  11.   
  12. MercuryTimers("Timer1").Start 'Start measuring time using Timer1.   
  13.   
  14. Wait 1   
  15.   
  16. MercuryTimers("Timer1").Stop 'After one second, stop Timer1.   
  17.   
  18. MercuryTimers("Timer2").Start 'Start measuring time usingTimer2.   
  19.   
  20. 'Two seconds later, restart Timer1 (which will continue to measure time from  
  21. 'the time it stopped while Timer2 continues uninterrupted).   
  22.   
  23. Wait 2   
  24.   
  25. MercuryTimers("Timer1").Continue   
  26.   
  27. 'Three seconds later, stop both timers and send a report to the test  
  28. 'results specifying the elapsed time for each of the timer objects  
  29. '(Timer1 ~4000 ms; Timer2 ~5000 ms).   
  30.   
  31. Wait 3   
  32.   
  33. Reporter.ReportEvent micInfo, "Elapsed Time""Timer1: " & MercuryTimers("Timer1").Stop() & "ms, Timer2: " & MercuryTimers("Timer2").Stop() & "ms"   
  34.   
  35. 'Set a transaction manually for each of the timer objects. Convert the   
  36. 'elapsed time for each of the timer objects from milliseconds to seconds so  
  37. 'the elapsed time will be reported correctly in the transaction.   
  38.   
  39. Services.SetTransaction "Timer1",MercuryTimers("Timer1").ElapsedTime / 1000,Pass   
  40.   
  41. Services.SetTransaction "Timer2",MercuryTimers("Timer2").ElapsedTime / 1000,Pass  

No comments:

Post a Comment