How to track execution time of the script in QTP

Hello Friends,

In this post, we’ll see how to measure the total time taken by a test/script in execution.

It’s easy to get execution time using Timer, but here we will measure the time and convert it to Hr-Min-Sec format. Let’s see how-

Dim StartTime, EndTime
StartTime = Timer
‘enter your script here
For I = 1 To 5
 wait 1
EndTime = Timer
TimeTaken = EndTime – StartTime
msgbox TimeTaken

You have execution time stored in ‘TimeTaken’ variable but it is in milisecond format

Now, let’s convert it to Hr-Min-Sec. It will clearly tell you how many seconds, minutes or hours (if any 🙂 ) have been taken by the script. Following is the function to do the job for us. Just pass the ‘TimeTaken’ to it and chill 🙂

Function func_ExecutionTime(TimeTaken)
If TimeTaken>=3600 Then
 rem1=int(TimeTaken mod 3600)
 str=hr&” hr “
 If rem1>=60 Then
  sec=int(rem1 mod 60)
  str=str&min&” min “&sec&” sec.”
  str=str&sec&” sec.”
 End If
 Else If TimeTaken>=60 Then
 sec=int(TimeTaken mod 60)
 str=str&min&” min “&sec&” sec.”
 str=str&sec&” sec.”
End If
End If
func_ExecutionTime = str
End Function

How to call this function –

TimeTaken_HMS =  func_ExecutionTime(TimeTaken)
msgbox TimeTaken_HMS

If you have multiple actions in your test, you can measure the execution time for every individual action.

Post you comments for any queries/feedback.

1 thought on “How to track execution time of the script in QTP”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top