10 Performance Tips to Help Optimize Your QuickTest Professional Code

QTP/UFT Published on:
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:

1.

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.

2.

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.

3.

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.

4.

Use Commmon Usage

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

5.

Use local variables

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

6.

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.

7.

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:

Browser("CF").Page("CF").Frame("WorkSpace").SwfObject("IEController")
or:
Browser("CF").Page("CF").Frame("WorkSpace").SwfObject("IEController").ActiveX("ICW")

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:

8.

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
Else
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
else
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”.

24 responses to “10 Performance Tips to Help Optimize Your QuickTest Professional Code”

    • 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

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

  1. 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

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

    • 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.

  3. 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.

  4. 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). :-)
    Thanks!

  5. Hi,

    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.

    Thanks,
    Shilu

  6. 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?

  7. 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!!!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Performance Test Tool