10 Performance Tips to Help Optimize Your QuickTest Professional Code

10 Performance Tips to Help Optimize Your QuickTest Professional Code

Performance Test Tool

Are your QTP scripts running slower than you’d like? Is your function library slowing you down? Try these ten performance tips to help optimize your QuickTest Professional code:


Dim your variables

. Declared variables are faster than variables that are not declared. Once a variable is declared it is assigned an ordinal at runtime, but an undeclared variable is referenced by name every time it is used, which slows it down considerably.


Use Option Explicit

at the beginning of all your scripts. Setting Option Explicit forces variable declaration. This is a good thing, as we saw in Tip #1. Also –Option Explicit has the added benefit of helping to debug, since it can point out any misspelled variable references.


Use Sync

For screen/object synchronization, use the Exist statement or Sync rather than the Wait statement. A Wait statement tells QTP to pause for the full amount of time you’ve entered. Wait(10) will pause for exactly ten seconds — even if the object you are waiting for appears sooner. But an Exist(10) will only wait up to ten seconds. That means that if the object appears in two seconds, the Exist will continue after only two seconds rather then wait the full ten.


Use Commmon Usage

If you are using functions with keywords, place them in order of common usage rather than alphabetically.


Use local variables

rather than global variables for functions. Local variables are faster than global variables, so use local whenever possible.


Use Run Mode

Set QuickTest’s ‘Run Mode’ to Fast. To set in QTP, go to Options\Run. This setting changes the script’s run behavior so that it will run without the execution arrow to the left of the Expert view (or Keyword view). The test will also not expand the item tree, nor display the script of each action as it runs. Also, this setting requires fewer system resources. Also if you don’t care about capturing images in the result –on an error– you could un-check ‘Save still image captures to results’ under Run\Screen Capture.  Same thing for the ‘Save movie to results ‘ setting.


Use the Object Repository (OR)

. Scripts run faster if all the objects are in the QTP OR as opposed to using straight descriptive programming. However, I’ve also seen extremely large object repositories create performance issues; especially in Business Process Tests. What I prefer to do is use a mix of both. In my applications, all objects live under one of the following two main paths:




So — I only have the bare essential objects in my OR. For everything else, I use a combination of the path that is in the OR and a descriptive for my objects. For example, I have a function for all of the different object types — textbox, Combobox, Buttons, etc. — my application contains. In each object function, I use a Set Statement to assign an object reference to the OR path. I then pass it a descriptive definition to enable it to recognize the specific object. A simple example would look something like this:


Use If Exists

If your test has a dynamic object that sometimes appears use the ChildObjects method to check if it exists rather than use the Exist statement.

So, rather than this:

Set strDlgPath = Browser("CF").SwfWindow("swfname path:=ModalForm")
If strDlgPath.Exist(5) Then
strDialogExistFlag = True
strBrowserDialogExistFlag = True
DialogAW = "False"
Exit Function
End If

I would do something like this:

Set strDlgPath = Browser("CF")
Set dlgObjDesc = Description.Create()
dlgObjDesc("swfname path").Value = "ModalForm"
set nowDialog = strDlgPath.ChildObjects(dlgObjDesc)
objFoundCount = nowDialog.count
if objFoundCount = 0 then ' Object Exist
DialogAW = "False"
Exit Function
strDialogExistFlag = True
strBrowserDialogExistFlag = True
end If

9. Destroy Objects

10. Turn off Active Screen

Turn off QTP’s ‘Active Screen’ option.  If you are recording against an application and it appears that either QTP or the APP (or both) are slow or appear to hang disable Active screen. This behavior can appear if you are recording against a screen that has a large number of objects or have deep object hierarchies.

To disable go to Tools\Options\Active Screen and set the Capture Level to “None”.

Chanikya - May 6, 2011

Nice post

    Joe Colantonio - May 6, 2011

    Chanikya » Thanks Chanikya!

TJ - July 15, 2011

Regarding tip #7, how large can the OR before we start to see a perf issue?

    Joe Colantonio - July 15, 2011

    TJ » Hi TJ – good question. HP Claims that For QTP 9 and above that there are “no known size limitations” that would cause performance issues. I know that before 9.0 the limit was around 1.5MB when performance/corruption issues occurred. Also my team saw degradation in performance with any project that was over 1 GB in size in Quality Center. So my best answer is to keep your OR as small (no larger than 500mb)as possible especially if you using Business Process Testing. Cheers ~ Joe

      SJ - January 19, 2015

      To alleviate this OR performance problem, how about mantaining the objects and their identification properties of the entire application in excel?

Anish Pillai - September 12, 2011

Nice List.. I didnt know point 1… ;)

I’ll research more on it… :)

Shalabh Dixit - December 14, 2011

Nice post Joe. Can you please explain more about point 7 & 8.

Scott Knight - March 5, 2012

I experienced slow response with an OR of about 30MB. QTP response really wasn’t too bad, but loading the OR from Quality Center using BTP testing was miserably slow. Using descriptive programming and some other tricks, I removed a lot of objects from the OR but noticed the size was not reducing. I had to export the objects into a new OR to reduce the size. My OR has now been reduced to 7MB and loads much quicker. My advice is once your OR has matured and you are not adding as many objects, export/import into a new OR to reduce its size. It seems that just removing objects is not enough.

QTP 9.5,10 and 11
QC 10

smadar aminov - May 30, 2012

is there size limitation on the test and library file?
I see slowness in library file (xxx.vbs) with 1 MB

    Joe Colantonio - May 31, 2012

    smadar aminov » I’m not aware of any limitation on the size of the library. It you break the function library up into separate files does performance get better? I will try to ask someone at HP Discover next week if they know of any such limitations.

      Charanpreet - July 18, 2014

      Breaking vbs files into multiple will not make much difference. It is logical break only.

Venkat Reddy - June 7, 2012

Thanks!!! Nice post…Please post all

    Joe Colantonio - June 9, 2012

    Venkat Reddy » Thanks Venkat!

Govindaraja - October 4, 2012

Nice Post, Good to know all of the above comments

Henry - October 10, 2012

Nice Site Joe,

One trick I use to decrease the size of the OR is to export it and then import it. The OR keeps history of the object so by exporting it, it remove that history making your OR much smaller.

    Joe Colantonio - October 11, 2012

    Henry » Thanks Henry – great tip!

Vijay - October 15, 2012

I tried this import/export options of OR.it is really amazing.! The tsr file before exporting to XML was 8.8MB and post importing the xml file to OR, the size of the OR reduced to 6.8MB (almost 2 MB). :-)

Shilu - March 13, 2013


I am facing some issue which are listed below,

1) I have configured the ALM-QTP for execution, While executing from ALM , connecting to QTP and start the execution is taking more time.How we can reduce this
2) if there is object not found during execution, QTP will wait for that object,How to reduce this waiting time.


JHenry - April 18, 2013

Good list!
DIM all variables – Do you also suggest creating variables for every literal in a subroutine to help with run time or just working variables such as a do loop variable or a calculated variable?

ike - September 26, 2014

Great tips, one simple question why there is in the code , I have seen some ppl use it is it just for reference that it’s a breakpoint of just something u implemented? thx Joe , I’m listening your podcast everyday great job !! that’s only test talk that I found , really amazing!!!

    Joe Colantonio - September 29, 2014

    Thanks! Let me know if there is any topic you would like to hear on an upcoming episode of TestTalks

saunak tarafdar - January 7, 2015

Great site and great article. Lots of new things to learn from the posts and the comments!

4 Things to Try in UFT or QTP in order to improve the execution time of your scripts - Joe Colantonio - Succeeding with Test Automation Awesomeness. I’ll show you how! - July 8, 2015

[…] one of my very first posts on joecolantonio.com I listed10 performance tips to help optimize your QTP code. Today I’d like to share four ways in which you can improve the execution time of your UFT […]

Click here to add a comment

Leave a comment: