Automation Testing, Manual Testing, QTP/UFT 11 , QC/ALM 11 ,SAP TAO, Unix, Selenium, Oracle SQL, Shell Scripting and For Online Trinings to contact me : Cell:+91-8897972059 , Email Id : quicktestprotech@gmail.com

Thursday, November 4, 2010

QTP Optimizations

Introduction:
This paper presents best practices for script optimization and maintenance in HP-QTP. These best practices are relevant for any project that uses QTP as its test automation tool.
The topics covered are:

  • Relative path in QTP 
  • Optimizing scripts by reducing function calls to the object repository 
  • Wait statements and why should we avoid them 
  • QTP IDE options

Audience:

  • Software Testers with exposure to QTP 
  • Senior Automation Testers using QTP 
  • Test Leads 
  • Test Managers

Area of Application:
These best practices should be incorporated in any project that uses HP-QTP; they are relevant for any QTP framework.
Benefits:

  • Scripts optimization
  •  Maintainability of reports 
  • Portable scripts


Table of Contents
ABSTRACT: ................................................................................................... 1
1.0 INTRODUCTION ..................................................................................... 3
2.0 CONTENT ............................................................................................... 3
3.0 CONCLUSION ....................................................................................... 10
4.0 DEFINITIONS, ABBREVIATION AND ACRONYMS .................................. 10
5.0 REFERENCES ........................................................................................ 10
BIOGRAPHY OF THE AUTHOR ..................................................................... 10


1.0 Introduction
QuickTest Professional is one of the most widely used functional and regression testing tools. It is seen that while the tool is used adequately to meet its objectives, aspects such as optimization, maintainability and portability of scripts are often ignored.
This paper discusses points on how to optimize run-time performance of QTP scripts, and to develop scripts that are portable and maintainable.

 2.0 Content
Make use of relative paths while calling reusable actions in a script


What is relative path?
There can be two types of path in your file System, absolute and relative.
 A full path or absolute path is a path that points to the same location on one file system regardless of the working directory. Example of a full path: C:\Program Files\Mercury Interactive\QuickTest Professional\Tests while
A relative path is a path relative to the current working directory, so the full absolute path may not need to be given.
 Example of a relative path: Say your current working directory is QuickTest Professional as shown above so the relative path for the folder Mercury Interactive which is one level up would be ..\..\Mercury Interactive similarly folder which is on same level can be referenced by ..\Some Folder
The benefits of using relative paths in QTP become evident now. Suppose you have a test where you need to call a reusable action that was created in a

different test. The normal steps we follow would be: Insert > Call to existing Action
and then we select the reusable action from the drop down list.


The major drawback with this approach is that if you need to shift your files to another computer where an identical path does not exist, you will have to do a lot of rework and map the reusable actions all again.
To get over this problem, we can use relative path. In the Select Action box as shown below instead of selecting the test just type in ..\Test1. If there is a test named "Test1" in the current directory, action drop down box would automatically populate the list of reusable actions under it.


Reduce as many function calls to the object repository as possible
Example of a function call is Window("Flight Reservation").WinEdit("Name:").Set "Thirupathi". In this example there are two calls to the object repository Window() and WinEdit().
Here is an experiment with the windows-based flight reservation sample application.
The example below shows the usage of With statement that helps in reducing a function call.

Dim StartTime, EndTime, StartTime1, EndTime1 SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"

With Dialog("Login") .WinEdit("Agent Name:").Set "mercury"
.WinEdit("Agent Name:").Type micTab
.WinEdit("Password:").SetSecure "4864ede3f3f8f30757cf694e3e100d29bf1ea9b9" .WinEdit("Password:").Type micReturn
End With
StartTime = Timer
With Window("Flight Reservation")
For i=1 to 1000 .WinEdit("Name:").Set "Thirupathi"
Next
End With
 EndTime = Timer
Msgbox EndTime - StartTime


This was iterated 1000 times. QTP took 41.71875 seconds to complete these many iterations.
The example below shows the usage without With statement.

Window("Flight Reservation").Close SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
With Dialog("Login") .WinEdit("Agent Name:").Set "mercury"
 .WinEdit("Agent Name:").Type micTab .
WinEdit("Password:").SetSecure "4864ede3f3f8f30757cf694e3e100d29bf1ea9b9" .WinEdit("Password:").Type micReturn
End With
StartTime1 = Timer
For i=1 to 1000
Window("Flight Reservation").WinEdit("Name:").Set "Thirupathi"


Next
EndTime1 = Timer
msgbox EndTime1 - StartTime1



The above test was iterated 1000 times. QTP took 45.85938 seconds to
complete these many iterations.
This experiment was carried out on a machine which has 2GB RAM. With 1000
iterations the diff is > 4 sec. The effect (performance degradation) would be
much more pronounced on larger tests that have a higher number of function
calls involved, and/or if it is carried out on machines that have configuration
just on threshold (512MB, the minimum RAM recommended by HP).
The graph below shows effect of time on the two line graphs, as we increase
the number of iterations.


Avoid using hard coded wait (x) statement
Wait statement waits for ‘x’ seconds, even if the event has already occurred. Instead use .Sync or .Exist statement. While using exist statement, specify 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 execution time. On the other hand if you leave the parenthesis blank, QTP would wait for object synchronization timeout that has been mentioned under File > Test Settings > Run Tab.


QTP IDE options
QTP IDE provides many useful options. It is seen that people tend to overlook these. Below are some of these options that can help you in optimizing the script run time and ensure robustness of the script.

  • Uncheck the options "Save still image capture to results" and "Save movie to results" present under Tools > Options > Run tab.
  •  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 you need not worry about this option, as the scripts WILL run in fast mode whether you want it to or not.




3.0 Conclusion
The points discussed above are framework-independent. It is recommended that these should be incorporated in every project that employs HP-QTP as a test automation tool.

 4.0 Definitions, Abbreviation and Acronyms
Acronym                 Description
QTP                    QuickTest Professional
HP                       Hewlett Packard
IDE                     Integrated Development Environment

5.0 References
Item                                      Description
QTP Documentation               HP QTP reference manual

0 comments:

Post a Comment

Loading...