We think about automation to reduce the time been spent on manual testing, the main aim of any automation is to increase the productivity with efficient and effective work.
This makes it extremely essential to come up with an automation which can be trusted and can also perform as expected, a poor automation may result in waste of efforts and may lead to elimination of automation from the project. The only thing that I consider to be the key to have a successful automation is “Planning”. If your plan is perfect you will surely get the perfect automation solution. Soon, we will be discussing the automation planning in details in another article.
Please consider the following points for optimizing QTP’s
I. QTP Settings Based
A. General Settings
B. Run Settings
II. Code Based
A. Option Explicit
Use Option Explicit on top of the script, it will force explicit declaration of all variables in a script. Thereafter, you must explicitly declare all variables
using the Dim, Private, Public, or ReDim statements. Once a variable is assigned it is assigned an ordinal position in memory, on the other hand undeclared variables are referenced by their name, hence every time an undeclared variable is used we lose some time in locating it’s memory location.
B. Avoid Global Variables
We must rely on local variables rather that a global variables, until it’s really required. Having said that doesn’t mean that we shouldn’t use the Global variables but indeed we should define the variables as per the scope required, so that they would vacant the memory when not in use. Keeping the number of global variables low can significantly affect the performance of your script.
C. Fair use of Wait statement
As far as possible do not use a hardcoded wait statement in your script, if you need to wait between the execution it must be based on a condition rather than waiting before checking the condition. This can simply we achieved using “Exist”, “Sync” or “waitproperty” methods instead of
wait. For an example Exist(10) will either wait till the object exists(which
might be 2 seconds) or 10 second(max wait time) laps, but if you use Wait(10) instead, whatever be the case script will wait for 10 seconds.
Still in case you need to used wait statement use Wait(3)
(waiting for 3 seconds is acceptable as per the industry standard)
D. Test Environment
must choose a good test environment with a decent hardware configuration
(RAM/processor speed), which must be something more than the combined system
requirement of you AUT and QTP.
E. Object’s Definition
No matter you whether you use “Descriptive Programming “or “Object Repository” make sure that the objects in AUT are well defined. Sometimes we add objects in OR with a single object identification property and everything seems to be working fine. Though, it should always be considered to keep the object definition as unique as possible, which would make the object recognition easier and faster.
A framework which is complex in nature increases the load /execution time of scripts. Techniques like caching, compiling all code into single library while execution should always be considered
G. Recovery scenarios
Note that the recovery scenarios are not set to triggered on every
H. Use Automation Object Model (AOM)/COM
Control QTP from external files using AOM and use other COM objects within the script.
You may try launching the script using a ”Visual script file” (.vbs) instead of launching QTP and then opening the script.
I. Relative Path
Use relative paths wherever possible, although this will not be decreasing the execution time but saves a lot in maintenance.
J. Object’s Hierarchy
Specially for web applications where in we have a long depth of the
K. Action and Function
Always prefer a function over an Action, if both of them are capable of solving the purpose. Loading and unloading an Action takes a lot of time and memory.
‘Creating an instance of IE
‘Displaying the Browser
‘Navigating to a specific URL