Thursday 5 April 2012

QTP Script Performance Tips:

QTP script optimization techniques. It covers ideal QTP settings and VBScript coding best practices to improve script execution performance.

1.Always set QTP to run in Fast mode instead of Normal mode

QTP scripts can be executed in two modes Normal and Fast.

Normal (displays execution marker)—Runs your test or component with the execution arrow to the left of the Keyword View or Expert View, marking each step or statement as it is performed. If the test contains multiple actions, the tree in the Keyword View Item column expands to display the steps, and the Expert View displays the script, of the currently running action.

Fast—Runs your test or component without the execution arrow to the left of the Keyword View or Expert View (for tests) and does not expand the item tree or display the script of each action as it runs. This option requires fewer system resources.

We can save the time which QTP takes to display execution marker and enhance the performance of our scripts.

2. Always disable smart identification.

If QTP is unable to find an object using the learner object description it uses the smart identification mechanism for object identification. The Smart Identification mechanism takes more time to identify objects in case of failures as it checks all candidate objects and tries to find a match based on base and optional filter properties. If we turn off the Smart Identification mechanism then we can improve script performance in case of failures.

3. Always release all objects /variables after usage.

Function PrintValue()

Dim a

x=100

Print x

x=Null

End Function

The Nothing keyword in VBScript is used to disassociate an object variable from any actual object. Use the Set statement to assign Nothing to an object variable. For example: Set MyObject = Nothing

4. Use QTP's inbuilt dictionary object instead of arrays for storing values wherever possible.

5. Always use WaitProperty statements instead of hardcoded wait.

A wait statement will halt the script execution for the specified time irrespective of whether the object we are waiting for has loaded or not. On the other hand Wait Property waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step.

6. Provide a specific time limit for the exist command.

7. Set Global sync time to 1 sec

8. Launch QTP by creating a script that uses the Automation Object model. The script can be used to launch QTP with the required add-ins and QTP settings.

9. Create object references for frequently used objects in scripts.

e.g: Set UName = Browser("Br").Page("Pg").WebEdit("login").Object

10. Use select case construct instead of if.. elseif where it is possible to convert the if..elseif into the select case.

11. Use with statements to combine statements into a group that use the same parent hierarchy.

12. If we need to use the data stored in an excel file we should use code to connect to excel as a database and query on it as you would any other database rather than using the QTP datatable object.

13. Use custom error/exception handling instead of Recovery scenarios to handle exceptions in scripts

14. Use a judicious mix of Actions and functions

15. Declare all variables and functions in a separate .vbs file and associate it with your action.

16. Turn off image downloads incase they are not validated.

17. Tune your object identification settings for the environments and objects you are dealing with to best reflect your application objects identification.


No comments:

Post a Comment