QTP best Practises

QTP Best Practices


  •  Just record-and-playback is never the solution for any project.
  • Launch QTP using a .vbs file and not the QTP desktop icon. You will notice a substantial increase in speed.
  • 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.
  • While running, 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 leakages 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]
  • 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 exists statement always has a value inside it.
  • For ex: .Exist(10) Here QTP will wait max till 10 seconds and if it finds the object at (say) 3 secs , 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 timeout you have mentioned under File > Test Settings > Run Tab.
  • 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.
  • 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 QTP performance.
  • 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 QTP run time performance.
  • Make the Run Mode as “fast”. This setting is present under Tool > Options > Run tab. Note: If you intend to run your scripts from QC no need to worry about this option, as the scripts WILL run in fast mode whether you want or not.
  • Make use of relative paths while calling reusable actions in your script. Using relative path would make your script portable and easy to manage. I will cover in detail how to’s and why’s of using relative paths in my next post. 

Comments