This post refers to a thought provoking question which was asked on QTP forum. In this query jp@QTP is looking for ways to optimize UFT/QTP scripts for best performance. As you are aware, we use automated testing tools to optimize our testing process. Unless we make full use of the capability of the tool and unless a tool is used sensibly and with proper planning, it would not yield any results. Just record-and-playback is never the solution for any project. We need to go deep inside to understand the intricacies of any tool. Any software testing tool is only as good as the test engineer using it. On those thoughts, I feel this was one of the best questions asked in the forums of late.

Well, here are some of my tips and tricks to optimize UFT/QTP scripts and make them run faster:

  1. Launch UFT/QTP using a .vbs file and not the QTP desktop icon. You will notice a substantial increase in speed. [Refer the earlier post on How to open QTP using vbs file? ,you just need the 1st point of that post]
  2. Load only the add-ins that are required for your Application Under Test – don’t load unnecessary add-ins in the Add-in Manager when UFT/QTP starts. This has an effect on record time as well as run time performance.
  3. Reduce default time-out settings for Object synchronization timeout and Browser navigation timeout.   qtp-object-sync-time-out qtp-browser-navigation-timeout
  4. For large tests, always define variables, function in an external .vbs file and not inside a reusable action. Attach these files with your test scripts. If you define a variable or a function in an action, on every iteration of your test run, memory(RAM) will be allocated to those variables/functions and would not be released. Now as your script starts consuming more and more RAM, your System Under Test (SUT) will tend to become slower.
  5. Disable Smart Identification for production environment. Smart identification can be used effectively at script creation time where you can use it for object identification issues. Once all object identification issues are sorted out, disable Smart identification from File > Settings > Run.
  6. When using a concurrent license server, create the variable LSFORCEHOST to force QTP/UFT to search the license in specific machine. This will stop QTP/UFT from searching for license machines every time you open UFT. Read more on LSFORCEHOST and QTP licensing issues.
  7. While running, UFT/QTP consumes a lot of memory by itself. It is always advisable to have lots of available RAM( much more than what is recommended by HP) and good processor speed on a system where you intend to install QTP. When you have tests (and hence QTP) running for a prolonged period if time, there are chances of memory leaks. To avoid memory leakage always restart QTP at some intervals of time. Using AOM you can automate this process. [If you want to go into details of effect of RAM on speed of computer read the post on RAM, Memory Usage thoroughly]
  8. Avoid using hard coded Wait(x) statement. Wait statement waits for full x seconds, even if the event has already occurred. Instead use .sync or .exist statement. While using .exist statement always have a value inside it.
    For example: .Exist(10) Here QTP will wait maximum till 10 seconds and if it finds the object in (say) 3 seconds , it will resume the execution immediately thereby saving your precious time. On the other hand if you leave the parenthesis blank, QTP would wait for object synchronization timeoutyou have mentioned under File > Test Settings > Run Tab.
  9. Make full use of what HP-QTP has provided you in the tool IDE. Use “Automatically Generate “With” statements after recording” option present under Tools > Options > General Tab. This will not only make your code look neater but also make your scripts perform better.
  10. Make your own judgment whether you want to go for Descriptive Programming or Object Repository or mixed approach. Each approach has it own pros and cons that in turn is related to UFT/QTP performance.
  11. Unless absolutely required, uncheck the options “Save still image capture to results” and “Save movie to results” present under Tools > Options > Run tab. These options definitely have some bearing on UFT/QTP run time performance.
  12. To prevent unnecessary bloat of your results folder while debugging scripts, save the run results to a temporary folder. Disk space tends to fill up fast when you debug scripts.
  13. Make the Run Mode as “fast”. This setting is present under Tool > Options > Run tab. Note: If you intend to run your scripts from ALM/QC no need to worry about this option, as the scripts WILL run in fast mode whether you want or not.
  14. HP recommends not more than a few dozen actions per test. You go more than that and your UFT/QTP scripts performance may suffer.
  15. Pure functions (that is the functions which doesn’t contain any call to object repository or objects) should be stored in a function library and not in reusable actions.
  16. Hiding Active Screen (by right clicking the Active Screen pane > Hide) may help with editing response time.
  17. If you are new to automation or UFT/QTP. Read this beginner article on Automation Object Model (AOM). AOM simplifies many aspects of QTP scripting. It can help you in controlling QTP from an external file.
  18. As fas as possible, save your UFT/QTP tests on a file system instead of a network drive.
  19. Make use of relative paths while calling reusable actions in your script. Using relative path would make your script portable and easy to manage. We have covered in detail how to’s and why’s of using relative paths in this post.

So what do you do to optimize your scripts? Let us know through the comments below.

If you want to keep track of further articles on UFT (QTP). I recommend you to subscribe by Email and have new UFT articles sent directly to your inbox.

Subscribe to get free updates on UFT!

LearnQTP is the most popular site on UFT (formerly QTP).

Enter your first name and email address below to instantly subscribe and download an eBook on Optimizing UFT Scripts. In future, we will make sure you get new tips & tricks on UFT delivered direct to your email box.

Please check your email and confirm free subscription!