Académique Documents
Professionnel Documents
Culture Documents
www.ramupalanki.com
Are you new to HP Quick Test Pro 9.2 (QTP)? Say yes and you are at the right place, at the
right time. This article is for newbie's who want to start their carrier with QTP or have
just started with QTP. The article will give you a brief overview of various features of
QTP, and since it is for newbie's we won't be going into too much details of every feature.
* HP Quick Test Pro 9.2 is a functional automation and regression testing tool
With introduction of QTP 9.5, Trial version of QTP 9.2 is not available. QTP 9.5 does not
have any huge enhancement and hence most of the features discussed in this article will still
hold
Launching QTP
When you launch QTP for the first time, Add-in manager window is displayed
What is Add-in?
2. .NET
1/73
For more QTP Realtime Sripts, visit
www.ramupalanki.com
3. Java
4. SAP
5. Siebel
6. Stingray
7. VisualAge
8. Web Services
* QTP does not require any Add-in to work on Standard windows application
Once the selected Add-ins are loaded, QTP window will show up
Hit the record button to start recording. If you are recording for the first time, the
Record and Run Settings dialog box opens.
What all tabs are shown in above dialog would depend on Add-ins that is loaded. Using
above dialog we can set on what all application should QTP record on.
Note: If QTP does not record anything on your application then make sure you have the
correct settings specified in Record and Run Settings…
Keyword view
The Keyword View enables you to create and view the steps of your test in a keyword-
driven, modular, table format. This is the only view where complete Test flow can be viewed.
Expert View
In Expert View, QTP displays each operation performed on the application in the form of a
script, comprised of VBScript statements. Complete test flow is not available/visible in
this view.
* The actual object in the AUT which is identified for a Test Object is called the
Run-time object.
2/73
For more QTP Realtime Sripts, visit
www.ramupalanki.com
Object Spy
Object Spy is a tool that can be used to spy Test and run time object for looking at
properties and methods supported by object being spied
Object Identification
2. Assistive – Learn in case Mandatory properties are not enough to identify the object
uniquely
3. Ordinal identifiers – Learn in case both mandatory and assistive properties are not
able to recognize the objects correctly
Here we can Add/Remove properties from/to Mandatory and Assistive properties. Objects
in application represent certain special characteristics which allow QTP to map them QTP
Test object. For window objects this characteristic is mostly define by "regexpwndclass" .
In case application developers don't use standard class names while creating object QTP
won't be able to identify the object correctly. Below is a checkbox in Search window
recognized by QTP as WinObject
By clicking on the "User Defined…" button on Object identification settings window, we can
add such objects and map. Once added QTP will now be able to recognize the object
correctly
Object Hierarchy
3/73
For more QTP Realtime Sripts, visit
www.ramupalanki.com
* QTP only adds those objects from hierarchy which are necessary for it to
identify the object later.
* All objects on which user takes an action while recording are automatically
added to object repository
* "Browser", "Google", "q" are three different objects that would be present in OR
for the below generated statement
* Copying and pasting code from one script to another script does not work in QTP
as the OR does not get copied to the new script
1. Shared OR: Can be used by multiple scripts. A central location to store all objects
* Default repository
* Cannot be reused
Action
4/73
For more QTP Realtime Sripts, visit
www.ramupalanki.com
* Have their own Data Table and Object Repository (in case of per-action
object repository)
* TestFlow represent the top level action. Complete test flow can only be viewed in
Keyword views
Inserting Actions
· Insert Call to New… - Creates a new action and adds a call to the same. Pfrovide
the name "Cancel Ticket" in the "Name" field and click on OK button.
* Adds below line to the code
* This inserts the call to the existing action. In case the action in present in some
other test case then a read only copy of action is inserted
* Actions cannot be deleted from a Test from Expert view. To delete a action
one must go to the keyword view and delete the action
5/73
For more QTP Realtime Sripts, visit
www.ramupalanki.com
Action Iterations
An action can be run for 1 or more rows from its Local Data Table.
* Similar to Action, a test can also be run for multiple iterations from Global Data
Table
Why Parameterization?
* Usage of data drivers allows us to use the same data for various input boxes.
Data Table
* Data Table is excel like spreadsheet which can be user for parameterizing a
test case
* DataTable are of two types:
a) DataTable(" ",dtGlobalSheet)
b) DataTable(""
,dtLocalSheet)
c)DataTable( "","")
* Any changes made to Data table during run-time is stored in run-time data
table.
Environment Variables
6/73
For more QTP Realtime Sripts, visit
www.ramupalanki.com
1. Built-in
2. User-Defined
* Built in environment variables give information about the system and the
current test
* Environment variables can be loaded at run-time from a XML file using the
below code Environment. LoadFromFile "C:\TestEnvironment .xml"
APP_URL
Parameters
* Parameters provide another way of parameterizing the test cases
1. Test parameters
2. Action parameters
Action Parameters
* Output parameters can only be used when Action is being called for a single
iteration
Parameter("ParamNam e " )
Resources
* In case of multiple files QTP combines all the files into a single one and
executes the code. The files are combine in bottom to top order
Checkpoints
– Built-in checkpoints
– Custom checkpoints
4. Bitmap checkpoint
5. Accessibility checkpoint
For more QTP Realtime Sripts, visit
www.ramupalanki.com
6. Database checkpoint
7. XML Checkpoint
* Rest all checkpoints can only be added during Recording or through Active
screens.
* Checkpoint code
TextBox_Standard" )
Custom Checkpoints
8/73
* Custom checkpoint can be made flexible based on implementation and are preferred
over Built-in checkpoints
Test Results
1. Passed
2. Failed
3. Done
4. Warning
5. Information
Descriptive Programming
* Alternate way of writing test cases without having objects in object repository
* String description DP
* Description objects can also be used to get all child objects matching a criterion. Ex –
9/73
* When using string description all regular expression must be used with
escape character for literal meaning. Ex - …Link("text:= Logout \
(Piyush\)") .Click
* Code can be copied from one script to another without copying the object
repository
obj.Click
Action is a thing specific to QTP while functions are a generic thing which is a feature of
VB Scripting. Action can have a object repository associated with it while a function
can't. A function is just lines of code with some/none parameters and a single return value
while an action can have more than one output parameters.
Recovery scenarios are used when you cannot predict at what step the error can occur or when
you know that error won't occur in your QTP script but could occur in the world outside QTP,
again the example would be "out of paper", as this error is caused by printer device driver. "On
error resume next" should be used when you know if an error is expected and dont want to raise
it, you may want to have different actions depending upon the error that occurred. Use
err.number & err.description to get more details about the error.
A simple defintion could be… it is a variable which can be used across the reusable actions
and is not limited to one reusable action.
10/73
2. Built-in
We can retrieve the value of any environment variable. But we can set the value of
only user-defined environment variables.
Example
The following example creates a new internal user-defined variable named MyVariable with a
value of 10, and then retrieves the variable value and stores it in the MyValue variable.
Environment. Value("MyVariable")=10
MyValue=Environment .Value("MyVariable")
The files and folders hold binary and text data that are required for the test to
run successfully.
The following table provides a description, the type, and comments regarding the files that
make up a QuickTest Professional test.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
parameters
r n information
supportEmptyParas]–
Action (See other >
Load test
file
Load test
file
11/73
Load test
Do not
Default.usp configuration Text edit
file
Load test
Do not
.usr configuration Text edit
file
Load test
Do not
Thick_usr.dat configuration Text edit
file
Load test
Do not
Thin_usr.dat configuration Text edit
file
Resource.mt
r Object Repository Binary Do not edit
.LCK Locked
Example:
In the above example, the user would like to change the name of the CheckPoint object
from "Edit" to something more meaningful.
Note:
4. Click . The name of the checkpoint object will be updated within the script.
Example:
12/73
Note:
You must use the QuickTest Professional user interface to change the name of the
checkpoint. If you manually change the name of the checkpoint in the script, QuickTest
Professional will generate an error during replay. The error message will be similar to the
following:
"The "" CheckPoint object was not found in the Object Repository. Check the Object
Repository to confirm that the object exists or to find the correct name for the object."
The CheckPoint object is not a visible object within the object repository, so if you
manually modify the name, you may need to recreate the checkpoint to resolve the error.
QuickTest Professional 9.1 supports Microsoft Internet Explorer 7.0 Beta 3. Internet
Explorer version 7.0 is now certified to work and to be tested with QuickTest Professional
version 9.1.
QuickTest Professional 8.2 and below do not include support for Internet Explorer 7.0.
QuickTest Professional 9.1 provides replay support for Mozilla Firefox 1.5 and
Mozilla Firefox 2.0 Alpha 3 (Alpha-level support for Bon Echo 2.0a3).
For more QTP Realtime Sripts, visit
www.ramupalanki.com
Notes:
QuickTest Professional 9.1 will not record on FireFox. You can record a test on Microsoft
Internet Explorer and run it on any other supported browser, such as FireFox.
QuickTest Professional 9.0 will not record on FireFox. You can record a test on
Microsoft Internet Explorer and run it on any other supported browser, such as FireFox.
13/73
QuickTest Professional 8.2 and below
QuickTest Professional 8.2 and below do not have support for Firefox.
12) Problem
After Quick Test Professional is started, Windows Media will not start. It returns the
error message "wmplayer.exe has generated errors and will be closed by Windows. You
will need to restart the program. An error log is being created."
If you start Window's Media Player first, it will continue to work normally after starting
QuickTest Professional.
Solution:
Include the Windows Media Player's executable in the NoBBTApps section of the
mic.ini file
2. Go to \bin\mic.ini.
Example:
[NoBBTApps]
wmplayer.exe= rek
For more QTP Realtime Sripts, visit
www.ramupalanki.com
4. Save the mic.ini file and restart QuickTest Professional.
The lservrc file contains the license codes that have been installed
The lservrc file contains the license codes that have been installed. Whenever a new license
is created, the license code is automatically added to this file. The lservrc file is a text file,
with no extension.
File Location:
14/73
Example:
Example:
14) What to do if you are not able to run QTP from quality center?
Check that you have selected Allow other mercury products to run tests and components
from Tools–> Options–> Run Tab.
1.LTrim
2.RTrim
3.Trim
4.Replace
For more QTP Realtime Sripts, visit
www.ramupalanki.com
5.StrReverse
6.Space
Syntax:LTrim( string)
Msgbox a
Output=LAKSHMI .
Syntax:RTrim( string)
Msgbox a
Output= LAKSHMI.
Trim Function:Removes spaces on both the left and the right side of a string.
Syntax:Trim( string)
15/73
Ex1:a=Trim(" LAKSHMI ")
Msgbox a
Output=LAKSHMI.
replacewith:Replacement substring.
compare(Optional) :Numeric value indicating the kind of comparison to use when evaluating
substrings.If omitted,the default value is 0, which means perform a binary comparison.
Msgbox a
Output=xbxcxdxexf.
Output=xbxcxdaeaf.
As we are giving values for start and count parameters(optional )in above example only first
3 a's are replaced by x.
Syntax:StrReverse( string)
Ex1:a=StrReverse( "Lakshmi" )
Msgbox a
Output=imhskaL.
Ex1:a="Welcome"&space(5)&"All"
Msgbox a
Output=Welcome All.
16/73
V)QTP reporter objects.
Reporter Object is used for sending information to the test results. With the help of this
object you can:
· >Retrieve the folder path in which the current test's results are stored.
· >Retrieve the run status at the current point of the run session.
There are some very important methods and properties associated with it.
ReporterEvent Method:
I think this is a very common method used with Reporter object. I am sure even if you
have worked on QTP for a relatively short period, you would have come across this.
Its syntax:
0 or micPass: If this step runs test passes which is shown in test report.
1 or micFail: If this step runs test fails which is shown in test report.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
2 or micDone: Used to send message to the test report and does not affect status of test.
3 or micWarning: Again, used to send warning message to the test report and does
not affect status of test.
and
Details are the user defined details for the given step.
For Example:
Filter property
I have mentioned this on my other post Some Useful Tips with QTP but would like
to mention it again here since I get a lot of questions on this.
There can be situations where you don't want the full status displayed on the test report.
17/73
This property can be used to selectively filter the status of your tests.
Its syntax:
Reporter.Filter = NewMode
where NewMode can be:
0 or rfEnableAll: This is the default mode. All reported events are displayed in the
Test Results.
2 or rfEnableErrorsOnly: Only those events with a fail status are displayed in the
Test Results.
ReportPath Property
This is used to get the path in which current test results are stored.
Its syntax:
Path_of_Results = Reporter.ReportPath
RunStatus Property
Reporter.RunStatus
For Example:
Everyone knows we use automated testing tools to optimize our testing process. Unless
you 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. You 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 the QTP scripts:
18/73
· Launch 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]
· 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.
· 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 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 judgement 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
For more QTP Realtime Sripts, visit
www.ramupalanki.com
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.
19/73
· If you are new to automation or 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.
· 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.
Here I am reproducing one of the most important extract from QTP help section. If you
understand this part be assured you of your success in QTP Job interviews, other
question that follow will be of very elementary nature.
When QuickTest uses the learned description to identify an object, it searches for an
object that matches all of the property values in the description. In most cases, this
description is the simplest way to identify the object, and, unless the main properties of
the object change, this method will work.
If QuickTest is unable to find any object that matches the learned object description, or if it
finds more than one object that fits the description, then QuickTest ignores the learned
description, and uses the Smart Identification mechanism to try to identify the object.
If QuickTest activates the Smart Identification mechanism during a run session (because it
was unable to identify an object based on its learned description) , it follows the following
process to identify the object:
1. QuickTest "forgets" the learned test object description and creates a new object
candidate list containing the objects (within the object's parent object) that match all of
20/73
the properties defined in the Base Filter Properties list.
2. QuickTest filters out any object in the object candidate list that does not
match the first property listed in the Optional Filter Properties list. The
remaining objects become the new object candidate list.
o If the new object candidate list still has more than one object, QuickTest uses the new
(smaller) object candidate list to repeat step 2 for the next optional filter property in the
list.
o If the new object candidate list is empty, QuickTest ignores this optional filter property,
returns to the previous object candidate list, and repeats step 2 for the next optional
filter property in the list.
o If the object candidate list contains exactly one object, then QuickTest concludes that it
has identified the object and performs the statement containing the object.
4. QuickTest continues the process described in steps 2 and 3 until it either identifies one
object, or runs out of optional filter properties to use.
If, after completing the Smart Identification elimination process, QuickTest still cannot
identify the object, then QuickTest uses the learned description plus the ordinal
identifier to identify the object.
If the combined learned description and ordinal identifier are not sufficient to identify
the object, then QuickTest stops the run session and displays a Run Error message.
If the learned description does not enable QuickTest to identify a specified object in a
step, and a Smart Identification definition is defined (and enabled) for the object,
then QuickTest tries to identify the object using the Smart Identification mechanism.
If the Smart Identification mechanism cannot successfully identify the object, QuickTest
uses the learned description plus the ordinal identifier to identify the object. If the object
is still not identified, the test or component fails and a normal failed step is displayed in
the results.
The following example walks you through the object identification process for an
object. Suppose you have the following statement in your test or component:
21/73
description for the Login image:
However, at some point after you created your test or component, a second login button
(for logging into the VIP section of the Web site) was added to the page, so the Web
designer changed the original Login button's alt tag to: basic login.
The default description for Web Image objects (alt, html tag, image type) works for most
images in your site, but it no longer works for the Login image, because that image's alt
property no longer matches the learned description. Therefore, when you run your test or
component, QuickTest is unable to identify the Login button based on the learned
description. However, QuickTest succeeds in identifying the Login button using its Smart
Identification definition.
The explanation below describes the process that QuickTest uses to find the Login object
using Smart Identification:
1. According to the Smart Identification definition for Web image objects, QuickTest
learned the values of the following properties when you recorded the click on the Login
image:
For more QTP Realtime Sripts, visit
www.ramupalanki.com
22/73
For more QTP Realtime Sripts, visit
www.ramupalanki.com
2. QuickTest begins the Smart Identification process by identifying the five objects
on the Mercury Tours page that match the base filter properties definition (html
tag = INPUT and image type = Image Button). QuickTest considers these to be the
object candidates and begins checking the object candidates against the Optional
Filter Properties list.
3. QuickTest checks the alt property of each of the object candidates, but none
have the alt value: Login, so QuickTest ignores this property and moves on to the
next one.
4. QuickTest checks the name property of each of the object candidates, and finds
that two of the objects (both the basic and VIP Login buttons) have the name:
login. QuickTest filters out the other three objects from the list, and these two
login buttons become the new object candidates.
5. QuickTest checks the file name property of the two remaining object candidates.
Only one of them has the file name login.gif, so QuickTest correctly concludes
that it has found the Login button and clicks it.
You use the Smart Identification Properties dialog box, accessible from the Object
Identification dialog box, to configure the Smart Identification definition for a test object
23/73
For more QTP Realtime Sripts, visit
www.ramupalanki.com
class.
1. Choose Tools > Object Identification. The Object Identification dialog box opens.
2. Select the appropriate
environment in the Environment list. The test object classes associated with the selected
environment are displayed in the Test object classes list.
Note: The environments included in the Environment list are those that correspond to the
loaded add-in environments.
4. Click the Configure button next to the Enable Smart Identification check box.
The Configure button is enabled only when the Enable Smart Identification
option is selected. The Smart Identification Properties dialog box opens:
5. In the Base Filter Properties list, click Add/Remove. The Add/Remove Properties dialog
For more QTP Realtime Sripts, visit
www.ramupalanki.com
24/73
box for base filter properties opens.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
6. Select the properties you want to include in the Base Filter Properties list and/or
clear the properties you want to remove from the list.
Note: You cannot include the same property in both the base and optional property lists.
You can specify a new property by clicking New and specifying a valid property name in
the displayed dialog box.
Tip: You can also add property names to the set of available properties for Web objects
using the attribute/ notation. To do this, click New. The New Property dialog box opens.
Enter a valid property in the format attribute/ and click OK. The new property is added to
the Base Filter Properties list. For example, to add a property called MyColor, enter
attribute/MyColor.
7. Click OK to close the Add/Remove Properties dialog box. The updated set of base
filter properties is displayed in the Base Filter Properties list.
25/73
For more QTP Realtime Sripts, visit
www.ramupalanki.com
9. Select the properties you want to include in the Optional Filter Properties list
and/or clear the properties you want to remove from the list.
Note: You cannot include the same property in both the base and optional property lists.
You can specify a new property by clicking New and specifying a valid property name in
the displayed dialog box.
Tip: You can also add property names to the set of available properties for Web objects
using the attribute/ notation. To do this, click New. The New Property dialog box opens.
Enter a valid property in the format attribute/ and click OK. The new property is added to
the Optional Filter Properties list. For example, to add a property called MyColor, enter
attribute/MyColor.
10. Click OK to close the Add/Remove Properties dialog box. The properties are
displayed in the Optional Filter Properties list.
11. Use the up and down arrows to set your preferred order
for the optional filter properties. When QuickTest uses the Smart Identification
mechanism, it checks the remaining object candidates against the optional properties one-
26/73
by-one according to the order you set in the Optional Filter Properties list until it
filters the object candidates down to one object.
Broken Links also sometimes called as dead links are those links on the web which are
permanently unavailable. Commonly found, 404 error is one example of such link. Now the
question is how can we identify broken links with the help of QTP during the run session?
There can be two ways to do this:
Using Automatic Page checkpoint: Go to Tools > Options > Web > Advanced and check the
two boxes labeled "Create a checkpoint for each page while recording" and "Broken Links"
For more QTP Realtime Sripts, visit
www.ramupalanki.com
27/73
For more QTP Realtime Sripts, visit
www.ramupalanki.com
Now every time you record a new page, QTP will automatically include a checkpoint for
broken links.
By manually creating a Page checkpoint: QTP does not provide a direct menu option to
incorporate a page checkpoint. You need to take the help of standard checkpoint. Start
recording session > Insert > Checkpoint > Standard Checkpoint (OR press F12). Place and
click the hand pointer anywhere on your web page. Select Page (As shown in picture
below) and Click OK.
28/73
For more QTP Realtime Sripts, visit
www.ramupalanki.com
Now, how will you verify page checkpoint and hence broken links?
29/73
Run the above script. Go To Test Results > Your Check Point. Check the status of all links
under "Broken Links Result"
If you want to verify links pointing only to the current host check the box titled "Broken
Links- check only links to current host" under Tools > Options > Web. Similarly If you
want to verify links pointing to other hosts as well, uncheck it.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
30/73
XI)Creating MS word document in QTP?
How many of you guys ever thought of creating a MS doc file with the help of QTP. It is in
fact quite simple to create one. Let me show you a sample script of creating a very simple
document in MS Word.
Dim obj_MSWord
Now you will try to copy paste this code in your QTP but due to some formatting
problems you may not get the proper format. Please take care of the quotes
before Word.Application. These should be double quotes else your script wont run.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
X)QTP file handling?
Many a times you may need to interact with text files using QTP. Interaction can be(but not
limited to) in the form of reading input from a file, writing output to a file. This post
describe in detail "File handling using QTP".
What is FSO?
FSO stands for File System Object. This is used to support text file creation and
manipulation through the TextStream object and is contained in the Scripting type
library (Scrrun.dll)
The FSO Object Model has a rich set of properties, methods and events to process
folders and files.
We first create a FSO object using CreateObject and then create a text file using
31/73
CreateTextFile.
For Example: Suppose you want to create a file called "test.txt" located in C:
We would use the same example for the rest of this post.
//3rd argument is "True" if new file has to be created if the specified file doesn't
exist else false, blank signify false.
Set file= fso.OpenTextFile( "C:\file_ location" , ForReading, True) //2nd argument should
always be "ForReading" in order to read contents from a file
msgbox data
Loop
You can use Write() or WriteLine() Methods to write text into a file. The difference
For more QTP Realtime Sripts, visit
www.ramupalanki.com
between the Write() and WriteLine() Method is that the latter automatically inserts a new
line character while the former doesn't insert a new line character.
For example:
Set file= fso.OpenTextFile( "C:\file_ location" , ForWriting, True) //2nd argument should
always be "ForWriting" in order to write contents to a file
32/73
How to delete content?
file_location = "C:\file_location"
If your organization is currently using manual means to test your software applications & is
believing that it can derive tangible benefits by automating its software testing process,
then simply jumping to a conclusion of buying some tool simply because it is popular among
many, may not be wise. What should be done now is to take a judicious decision through a
scientific process to find out as to which tool will best be suited to your needs. Since this is
For more QTP Realtime Sripts, visit
www.ramupalanki.com
an capital intensive move aimed at taking your company to the world of Automated Testing,
needs careful examination.
When you are shopping for a proper automation tool, you will come across several people
ambitiously marketing their products, which may provide solution to variety of automated
testing needs. Now the question arises as to whether a particular tool is really suitable to
your needs or not. Are you not inclining your choice for a particular tool by making lot many
compromises in features. Think that in times to come, your testing needs may become more
complicated by the variety of applications coming across for testing & that too under
variety of operating systems.
Thus following guidelines shall be helpful in evaluating & zeroing down your choice of an
appropriate tool for the job at hand, out of a bunch of many testing tools sold by different
vendors.
33/73
First of all don't look at & form any type of opinion about any XYZ tool available in the
market. This is high time for doing deep introspection of your real needs. It is wise to
prepare a comprehensive list of your requirements of software testing at the present
moment. Identify the time consuming problems, which you want to solve with the new tool.
Identify the technical capabilities your prospective tool should have to be compatible with
the environment of your application.
a) List down the Compatibility issues: Remember that the tool selected by you has to
be compatible with:
# Third party software if any with whom your application needs to be integrated at
some stage
# List down the people who will be actually using the prospective tool. Keep the skill
levels of the available persons at the back of your mind.
# Remember that more powerful tools are bound to be more complex as well. If the
skill level of the available manpower (who will be expected to use the prospective
tool everyday), does not match the complexity level of the tool, believe me, you are
likely to land into many problems in smooth implementation of the tool in your
organization.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
# Think as to whether there is enough time for training your staff within the
prevailing time & budgetary constraints, if any.
Technical requirements like the following needs to be listed down before zeroing down your
choice on a particular automation tool.
# Identify the types of your own testing problems you wish that your new tool should
solve for you.
# Identify the time constraints coming across while making minor changes to your
system.
34/73
# Identify the shorter regression testing time frames.
# Identify the Increase in efficiency of the testing process you are looking for.
You need to understand various factors, which may compel you to drop down some of the
tools from your initial selection list. Such crucial factors need to be identified during
the early stages of your tool selection process.
a) Environmental constraints
# The prospective tool must be able to work on the desired operating systems
# The prospective tool must not dictate the terms of having some specialized
hardware for its working.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
# Up-gradation of existing hardware like providing more hard disk / More Ram etc.
to cope with the requirements of additional scripts and test data likely to be
added.
# Consider your likely objections to your new tool running under some specific
environment, while the software application might be required to run under
different environment or operating system. This issue may gain importance from
the consideration of the future use of the new tool.
It is certain that you won't desire to hang on with problems with your new testing tool.
Certainly anyone would like to have a quick, competent & professional solution to the
tool related problems arising may be occasionally.
35/73
# The tool as a product & its supplying company must be matured enough.
# The tool may not be worthwhile at all unless there is enough technical support
available.
# Find out the clientele of the prospective tool & try to obtain the feedback
from such organizations if possible.
# Identify the skill level required for using the prospective tool
# Ensure that there should not be any possibility of getting your data corrupted
by the tool.
Remember that it is not the question of just purchasing a particular tool by spending some
money. In fact it has been seen that in many cases, the cost of fully implementing the tool
can be much higher than the cost of the tool itself. Budgetary constraints shall be
applicable not only to the tool purchase cost, but shall cover costs of licensing / AMC's,
costs of training and cost of tool implementation etc.
We can be in a position to evaluate various tools available in the market after compiling a
comprehensive list of our requirements and various constraints.
This is the stage when an extensive research is needed to identify various types of tools
available in the market. WWW can be a good place to explore the tool. Preliminary study of
the technical brochure of every tool shall reveal the capabilities of the tool fitting your
36/73
requirements & constraints.
We can identify various features of every tool by classifying them like a) Essential
features b) Desirable features c) Less relevant features etc.
a) Essential features: are the ones, which are extremely necessary to meet
your requirements within the defined constraints.
b) Desirable features: are the ones, which will make a particular tool standout among
many of its competitors. Based upon the presence of variety desirable features,
your decision can be favor of a particular tool among many more.
c) Irrelevant features: are the ones, which are not of any great significance & may
not be able to provide some tangible benefit to you in your present requirements.
Evaluation of the above types of features is the next exhaustive & iterative exercise. At
this stage you should evaluate as much number of tools as possible and try to zero down
your focus on around 5-6 tools any one of which could qualify to be the final tool fitting
your ultimate choice.
The next step in the process should be establishing a contact with the tool suppliers &
organizing a practical demonstration. If possible you can ask for an evaluation or trial version of
the tool for refining your decision. At this stage you should clearly explain all your
requirements of testing along with set of constraints to the tool supplier, who shall be in a
better position to clarify many points left out by you during your short-listing process.
Having gone through the above-defined rigorous process of evaluation, the time has come
for you to take a decision in favor of one particular tool, which suits best into your slot
For more QTP Realtime Sripts, visit
www.ramupalanki.com
of requirements & constraints.
# With the help of all available data now you should be able to draw a clear
comparison of the performance related features of the tools as desired by you
vis-a-vis features claimed to be present in the technical literature provided by the
persons marketing the tool.
37/73
b) Practical demonstration at your site:
If a particular tool has already caught your attention, you can ask the supplier to organize a
live demonstration of the tool under your actual working environment. This way you will be
able to judge the technical capability of the supplier as well in providing support later-on.
Proper maintenance of automation scripts & ease of handling them is very important aspect
of the tool under evaluation. Although we may not be able to make an on the spot judgement
about this capability, but this aspect gets confirmed during the second or third release of
testing after implementing the new tool.
Now this is the time for conducting same test on one particular application time & again on
each & every short-listed tool independently. This way you shall be in a position to make a
final decision in favor of a particular tool out of a box of many.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
Judiciously testing all possible permutations of such components creates a highly complex
testing situation with hundreds or thousands of testing scenarios. Under such situations
there comes a need for automating the testing process with the help of automation
framework approach, which can help in achieving detailed testing with great reduction in
testing time.
38/73
It can never be a workable idea to automate all the test cases. Hence it is important
to scientifically understand the areas which can be automated. Remember that an ad-
hoc approach to test automation can in fact, lead to longer testing time and poor
quality irrespective of the name & fame of the testing tool selected by you.
The main advantage of such a framework is the low cost for maintenance. If there is change
to any test case then only the test case file needs to be updated and the Driver Script and
Startup script will remain the same. There's no need to update the scripts in case of
changes to the application.
39/73
automation engineers implement a framework that provides keywords like "check" and
"enter". Testing engineers (who don't have to know the coding) write the test cases based
on the keywords defined in the planning stage that have been implemented by the engineers.
The test is executed using a driver who reads the keywords and executes the
corresponding code.
Keyword Driven Framework methodology requires more planning and a longer initial time-
investment than going directly to the test creation stage and recording a test, it does make
the test creation and test maintenance stages more efficient and keeps the structure of
individual tests more readable and easier to modify.
In this case, the framework utilities can make the data driven scripts more compact and
less prone to failure. The utilities can also facilitate the gradual and manageable conversion
of existing scripts to keyword driven scripts as & when required. On the other hand, the
framework can use scripts to perform some tasks that might be too difficult to re-
implement in a pure keyword driven approach, or where the keyword driven capabilities are
not yet in place.
4) Evaluation of the Test Automation Tool: Evaluation checklist, Identify the candidate
tools available in the market, Sample run, rate & select the tools, Implementation &
Training
40/73
6) Design of the Test Automation Framework: Framework guidelines, validations,
Actions Involved, Systems involved, Tool Extensibility Support, Customs messages
& UML Documentation.
7) Design of the Input Data Bank: Types of Input file. Input files –
Categorization & Design of file prototypes.
9) Population of Input Data Bank: Different Types of data Input, Populate data
from different data sources, Manual input of data and Parent – Child data
hierarchy.
Test Automation Framework built with systematic approach yields following benefits:
# Ensures consistency
# Data Pooling
41/73
X XII)Create a Schedule to Run QTP at a Desired Time
Every Microsoft Windows has a wonderful feature of "Task Scheduler", which can be used
for automatically running any application at any desired time, at desired frequency right
from a specified date for initial launch. Once scheduling is done, it does not require any user
intervention; however the only important thing to remember is that the PC must be kept on
at the scheduled time.
This "Task Scheduler" utility is available in Windows "Control Panel" by the name "Scheduled
Tasks". Detailed steps are described as under.
1) Say our aim is to automatically run the file by the name QTP_Test.vbs available
at the location C:\ExpertQTP\ QTP_Test. vbs
5) Click on "Next" - > Browse - > In "Select Program to Schedule" screen Go to the
location of the QTP_Test.vbs file available in C:\ExpertQTP folder - > Click
"Open" as described in the following picture.
6) In the "Scheduled Tasks Wizard" select the schedule for running the QTP
Script. For example Daily, or Weekly or Monthly as per various options offered
in the Wizard. In or example select say "Daily". Then Click "Next" as described
in the following picture.
7) Select the Time & day you want to start this Script. Then Click "Next" as
described in the following picture.
8) Enter the "User Name" & Password for the workstation, just only once as
described in the following picture.
42/73
This way wizard will not ask the user for his manual intervention of feeding the
password every time.
9) Click "Finish"
10) Above mentioned simple steps shall now execute the desired script automatically,
every day at 12.59PM starting from 07/13/2008.
QTP
* Always start QTP first then start the application that you want to automate.
* Try to avoid the Text Checkpoint, GetText function and other similar functions
that deal with screen resolution as this may fail your test in the long run.
If you are working on Web app along with TD/QC open, you might witness that the app
opens up on TD/QC browser itself during playback instead of opening in a separate
window. The answer for this is to set the index property for browser.
Sometimes as a QTP programmer, we may need to keep track about the files inside our
Operating system. Apart from tracking our files, we need to manage them dynamically
like files can be created, files can be read, files can be edited and deleted. In order to
accomplish this task, we require FileSystemObject. It contains methods to carry all
For more QTP Realtime Sripts, visit
www.ramupalanki.com
administrative tasks related to files.
In order to run this code perfectly fine, the File "testfile.txt" should be present in the
D:\ location else QTP will raise an error.
As you can see in the above mentioned code, we have provided the complete path for the
file which we also call as Absolute path. Now this code is not of much use unless we do
43/73
something more along with it. Like after getting the reference for a file, we can see the
size of the file, its parent folder, its name etc.
Sometimes we may be interested in knowing whether our file exists or not. For this, we use
"FileExists" method. This checks whether the files exists or not. The "FileExists" method
requires a single argument containing the full path of the file. This method returns a
boolean value. I hope you guys must be aware of what a boolean value is. Now this method
will return a value "True" if the file exists and "False" if the file doesn't exists.
Else
End If
We can delete a file by firstly creating an instance of FileSystemObject and then we need
to call the DeleteFile method. Lets see the below mentioned code to explain this concept.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
You can even delete your MS Word file with the above code. Cool na.... I know.
Let me show you something even more interesting. If the file is read-only, then the
"DeleteFile" method will not be able to delete the file. So how to delete such a file? Any
guesses.
This thing is left for you guys to find it out how we can delete a read only file.
Copy Files
Copying files from one location to another is also a very frequently done task. For this, we
use CopyFile method. The syntax for copying files is:
44/73
obj.CopyFile "Source-File- Path", "Destination- File-Path"
In order to copy a file from "C:\test.txt" to "D:\test.txt" , we will use the code:
We can even rename a file just by changing the name of the file in the "Destination-
File-Path" .
What happens if we try to copy a copy inside a folder and the folder doesnt exist?
This thing is left for you guys to try.
Moving Files
We can also move files from one one location to another[Also known as Cut and Paste]. For
this, we require MoveFile method. It is infact quite similar to CopyFile method.
We use the below code to move files from one location to another.
We can read all the contents of a file using the ReadAll method. It captures all the file
contents and stores inside a variable.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
The following code will help you in reading all contents of a file "D:\test.txt" .
We can read all the contents of a file line by line. For this we require the ReadLine method.
The following code will help you in reading all contents of a file "D:\test.txt" line by line.
45/73
Set obj2= obj1.OpenTextFile( "D:\test.
txt") Do Until obj2.AtEndOfStream
Line=obj2.ReadLine
msgbox
Line Loop
obj2.Close
While executing scripts, we usually encounter unexpected & unpredictable events & errors,
which results into application crashing during a run session causing total disruption of the
run session and distortion of results. Such problems are quite frequent especially when the
tests are made to run unattended. In such a case the test process halts until the user
perform some desired recovery operation.
Recovery scenarios are useful when it is difficult to predict at which step the errors can
come or when we are confident that the error will not come in the QTP script, whereas it
can be anywhere outside the QTP Script. For illustration; Pop-up message of "out of paper",
as caused by the printer device driver. "On error resume next" is preferred when we sure
that the error is expected one and wish to perform some other actions.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
In order to handle such situations QTP comes to our rescue by creating recovery scenarios
and associates them with the particular tests. What does a Recovery Scenarios do is to
activate a specific recovery operation when a trigger events takes place. Most simple
example of a typical unexpected & unpredictable events & errors is like Incompatible Media
in portable Drive.
The Recovery Scenario Manager presents a structured wizard which helps us in defining
the recovery scenario, like detailed definition of the unexpected event and the operations
required to recover from the exception during the run session.
46/73
recovery scenario manager are extremely helpful
3) Test Run Error: This event is useful in handling VBScript statement errors at
runtime.
4) Object State: This event is useful in handling object related errors at runtime.
All Recovery scenarios get saved & logically grouped in recovery scenario files. Grouping of
various recovery scenarios in recovery scenario file can be managed according the user
requirements. Recovery scenario files carry a typical extension of .rs.
In order to instruct QTP to carry out a recovery scenario during a particular test run, we
firstly associate it with the particular test. There is no limitation to any fixed number of
recovery scenarios associated with a test. Order of execution of various recovery scenarios
associated with a test can easily be prioritized, thereby the trigger events get recognized
and handled in the desired sequence.
Whenever any error comes during the execution of a test having many recovery scenarios
47/73
associated with it; QTP intelligently hunts for the defined trigger event which had
caused the particular error. After detecting the trigger event, QTP automatically
performs the desired recovery steps and post-recovery test runs etc.
Recovery statements can be inserted in the tests to comfortably control and activate
the recovery scenarios during the test run.
Although Recovery Scenarios are users friendly on one hand; they tend to slow down the
speed of the Test Run. Presence of a few such recovery scenarios would reduce the speed
of Test Run significantly. This can become irritant to the testers, who can prefer the
approach of using VBScript On Error/Goto 0 far more useful for catching & handling small
errors.
For recording the right mouse clicks in QTP, we need to manually modify the configuration
file and then load it.
This is a great article extracted from QTP Help Guide, which leads us through
important steps to configure QTP to record our Right Mouse Clicks.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
Step –1: Choose Tools > Web Event Recording Configuration. The Web Event
Recording Configuration dialog box opens.
Step –2: Click the Custom Settings button. The Custom Web Event Recording
Configuration dialog box opens.
Step –3: In the Custom Web Event Recording Configuration dialog box, choose File >
Save Configuration As. The Save As dialog box opens.
Step –4: Navigate to the folder in which you want to save the web event recording
configuration file, and enter a configuration file name. The extension for configuration files
is .xml.
48/73
Step –5: Click Save to save the file and close the dialog box.
Step –6: Open the saved configuration file for editing in any text editor. The
configuration file uses a defined structure.
The beginning of the file, which is relevant for Web objects, is shown below.
The Property Name argument controls the recording of the mouse buttons. The value of
the mouse buttons are defined as follows:
1—Left 2
—Right 4
—Middle
To record a left mouse click for the onmouseup event, add the following line:
To record right and left mouse clicks for the onmousedown event, add the following lines:
Note: Only one event, either onmouseup or onmousedown, should be used to handle mouse
clicks. If both events are used, QTP will record two clicks instead of one. By default,
For more QTP Realtime Sripts, visit
www.ramupalanki.com
QTP listens for the onmouseup event.
Step –9: In the Custom Web Event Recording Configuration dialog box, choose File >
Load Configuration. The Open dialog box opens.
Step –10: Navigate to the folder in which you saved the edited configuration file, select the
file, and click Open. The Custom Web Recording Configuration dialog box reopens.
Step –11: Click OK. The new configuration is loaded, with all preferences corresponding
to those you defined in the XML configuration file. Any Web objects you now record will
be recorded according to these new settings.
49/73
The objective of this article is to briefly understand the process of interaction of MS
Excel and VBScripts.
We can easily use the built-in mechanism of QTP through which we can display the test
results in a predefined format. A result sheet gets generated after the execution of the
test in QTP; which provides an in-depth view of the script – through which we can know the
various point of failures, warnings and the passes.
In the test script we create customize various checkpoints at our will. Likewise the
result file can also be customized based upon the checkpoints already created according
to the defined criterion of Pass / Fail.
Generally while working in MS Excel, the user desires to generate a detailed report of the
entire test. The idea of generating such detailed / customized report is to have the
output in a format as per our own choice and to preserve the file in a centralized location.
one. Step-4: Setting the objects for various sheets in the workbook.
The above steps can be explained through suitable illustrations to understand the
approach properly.
50/73
It is believed that the user is fairly acquainted with the basics of MS Excel like:
Hence I am skipping the basic explanation of the above basics of MS Excel & directly
moving on to the main content of our topic.
Some of the simple VBScripts are being described below for performing various actions in
MS Excel.
In the process of reporting it is the first step. In MS Excel the reporting can be done in
two ways like 1) in the background wherein the application shall not be visible 2) the
application can be made visible to the user once the process of writing or fetching the data
is going on.
Dim xl
For more QTP Realtime Sripts, visit
www.ramupalanki.com
Set xl = CreateObject( "Excel.Applicati on")
When we run the above script, we can see a process named "Excel.exe" in the Windows task
Manager.
After creation of the object in Excel, it implies that Excel application has been invoked,
however it is not visible. From now on we can either continue to perform the operations in
the invisible back ground alternatively we can make the application visible and then we can
perform the operations.
51/73
To open a new Workbook:
xl.workbooks. Add
After opening a workbook in Excel (A New one or opening an existing one), next activity is to
feed some data in various cells in various sheets of our workbook.
MS Excel provides three sheets in a workbook by default, which are available to us for
performing various operations. To access these sheets with great ease, we need to create
objects referencing these sheets. This will help us in avoiding describing complete
hierarchy time & again.
For example we wish to create a reference for a sheet with an index i, beginning from 1:
We can easily add or delete the desired sheets from the active workbook
To write the data in Excel sheet, we need to identify the Cell ID of the cell where the data
is needed to be written. Similarly for accessing the data value from particular cells, we must
know their Cell ID.
For an example we want to write some data in sheet2 cell ID as D8, the command can be
52/73
written as under. Here "D" represents the Column Number & "8" represents the Row
Number.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
If an object has already been created in a particular sheet, we don't have to repeat the
complete hierarchy again, instead we can simply write:
After finishing the work we can save the workbook to a desired location with a different
name or save the changes made to an already existing open workbook.
To close a workbook:
xl.activeworkbook. close
53/73
Closing an application and clearing the memory:
To close the
application: xl.quit
Set xl = nothing
This is not the end; however it is just a beginning for us to explore the power of QTP in
exploiting the potential of MS Excel through simple VBScripts.
QTP has a unique feature by the name Smart Object Identification or recognition which is
used for identifying the objects smartly, whenever the normal identification fails due to
the dynamic changes in the properties of the objects.
Smart Identification is nothing but an algorithm used by the QTP when it is not able to
recognize an object. A simple generic example as per the QTP manual would be, A
photograph of a 8 year old girl and boy and QTP records identification properties of that
girl when she was 8, now when both are 10 years old then QTP would not be able to
recognize the girl. But there is something that is still the same, that is there is only one girl
in the photograph. So a kind of PI - Programmed intelligence is needed instead of AI.
Object identification is necessary to recognize the GUI objects on the screen. During
automatic recording of a script, the object identifier records various objects present on
the screen. The smart identification feature of QTP smartly identifies all the objects
For more QTP Realtime Sripts, visit
www.ramupalanki.com
irrespective of their being developed using same technology or not, e.g. smart
identification shall be able to identify the objects in an application although developed in
Java but using some of the Microsoft controls as well.
QTP identifies a particular object by comparing the properties of its test object and the
run time object. QTP may not be able to recognize any dynamic objects whose properties or
even the description may undergo some changes during the run time. Thus its great option
of enabling Smart Identification helps us in identifying the objects even if their properties
have undergone changes during the run time.
If QTP is not able to detect any object having description matching with that of the
recorded object, or in case it detects more than one object having matching description,
then QTP ignores the recorded description, and uses the Smart Identification feature to
54/73
identify the object. Smart Identification mechanism is a bit complex, but flexible.
However, if configured logically, Smart Identification definition can help QTP in detecting
an object, of course - if present, in-spite of failure of the recorded description.
Understanding the Smart Identification Process: (Ref. Quick Test Professional 9.0
– Help Guide)
If QTP activates the Smart Identification mechanism during a run session (because it
was unable to identify an object based on its learned description) , it follows the following
process to identify the object:
1) QTP "forgets" the learned test object description and creates a new object
candidate list containing the objects (within the object's parent object) that
match all of the properties defined in the Base Filter Properties list.
2) QTP filters out any object in the object candidate list that does not match the
first property listed in the Optional Filter Properties list. The remaining objects
become the new object candidate list.
# If the new object candidate list still has more than one object, QTP uses the new
(smaller) object candidate list to repeat step 2 for the next optional filter
property in the list.
# If the new object candidate list is empty, QTP ignores this optional filter property,
returns to the previous object candidate list, and repeats step 2 for the next
optional filter property in the list.
# If the object candidate list contains exactly one object, then QTP concludes that
For more QTP Realtime Sripts, visit
www.ramupalanki.com
it has identified the object and performs the statement containing the object.
4) QTP continues the process described in steps 2 and 3 until it either identifies
one object, or runs out of optional filter properties to use.
If, after completing the Smart Identification elimination process, QTP still cannot identify
the object, then QTP uses the learned description plus the ordinal identifier to identify the
object.
If the combined learned description and ordinal identifier are not sufficient to identify
the object, then QTP stops the run session and displays a Run Error message.
55/73
How to Analyze Smart Identification Information displayed in the Test
Results? (Ref. Quick Test Professional 9.0 – Help Guide)
If the recorded description does not enable QTP to identify the specified object in a
particular step, and a Smart Identification definition is defined (and enabled) for the
object, then QTP tries to identify the object using the Smart Identification
mechanism. There are two possible scenarios.
If QTP happens to successfully use the Smart Identification feature to recognize an object
after no object found to match with the recorded description, the Test Results receive a
warning status by providing the information like the following in the results details:
1) An indication that the object (for example, the userName WebEdit object)
was not found.
The following screenshot displays the results for a test in which Smart Identification was
used to identify the userName WebEdit object after one of the recorded description
property values have changed.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
If QTP happens to successfully use the Smart Identification feature to recognize an object
after multiple objects have been found to match the recorded description, QTP shows the
Smart Identification information in the Test Results window. The step still receives a
`Passed' status, because in most of the cases, if Smart Identification was not used, the
test object description plus the ordinal identifier could have potentially identified the
object. In such a situation, the Test Results shows information like the following in the
results details:
1) An indication that the Smart Identification mechanism has successfully found the
56/73
object, and information about the properties used to find the object.
This information can be used to create a unique object description for the object, so
that QTP can find the object using this description in the future run sessions.
The following screenshot displays the results for a test in which Smart Identification was
used uniquely identifies the Home object after the recorded description resulted in
multiple matches.
If the Smart Identification mechanism cannot successfully identify the object, the test
fails and a normal failed step is displayed in the Test Results.
a) Base filter properties: Are the most fundamental properties of a particular test
object class. Her we can not change their values without changing the essence of
the original object.
Smart Identification Example: (Ref. Quick Test Professional 9.0 – Help Guide)
For more QTP Realtime Sripts, visit
www.ramupalanki.com
The object identification process for an object is described through the following
example in great detail.
When you created your test or component, QTP learned the following object description
for the Login image:
However, at some point after you created your test or component, a second login button
(for logging into the VIP section of the Web site) was added to the page, so the Web
designer changed the original Login button's alt tag to: basic login.
57/73
The default description for Web Image objects (alt, html tag, image type) works for most
images in your site, but it no longer works for the Login image, because that image's alt
property no longer matches the learned description. Therefore, when you run your test or
component, QTP is unable to identify the Login button based on the learned description.
However, QTP succeeds in identifying the Login button using its Smart Identification
definition.
The explanation below describes the process that QTP uses to find the Login object using
Smart Identification:
1) According to the Smart Identification definition for Web image objects, QTP learned the
values of the following properties when you recorded the click on the Login image:
____________ _
Property Value
____________ __
____________ __
For more QTP Realtime Sripts, visit
www.ramupalanki.com
Optional Filter Properties:
2) QTP begins the Smart Identification process by identifying the five objects on the
Mercury Tours page that match the base filter properties definition (html tag =
INPUT and image type = Image Button). QTP considers these to be the object
candidates and begins checking the object candidates against the Optional Filter
Properties list.
3) QTP checks the alt property of each of the object candidates, but none have
the alt value: Login, so QTP ignores this property and moves on to the next one.
4) QTP checks the name property of each of the object candidates, and finds that two
of the objects (both the basic and VIP Login buttons) have the name: login. QTP
filters out the other three objects from the list, and these two login buttons
become the new object candidates.
5) QTP checks the file name property of the two remaining object candidates. Only
one of
58/73
them has the file name login.gif, so QTP correctly concludes that it has found the
Login button and clicks it.
Selection of the option "Disable Smart Identification during the run session", Instructs
QTP not to use the Smart Identification mechanism during the run session.
When we select this option, the Enable Smart Identification check boxes in the Object
Properties and Object Repository dialog boxes get disabled, although the settings are
saved. However when you clear this option, the Enable Smart Identification check boxes
return to their previous on or off setting.
As per the suggested best practice we should disable Smart Identification while
creating the test cases, so that we are able to recognize the objects which are dynamic
or inconsistent in their properties. Moreover once the script gets created, the Smart
Identification should be enabled, so that the script does not fail in case of any small
change.
However the scriptwriter should always check for the test results to verify if the Smart
Identification feature had been used to identify a object or not. Sometimes Smart
Identification needs to be disabled for particular objects in the OR, this is advisable when
you use SetTOProperty to change any of the TO properties of an object and especially
ordinal identifiers like index, location and creation time.
Following Frequently Asked Questions shall be quite helpful in making a reasonably good
For more QTP Realtime Sripts, visit
www.ramupalanki.com
foundation for attending an interview on QTP.
# It can easily handle "Non-UI" based Test Cases as well. Like API (Certification
testing & Database Testing etc.
59/73
language based on VBScript
Exception handling is called Recovery in QTP. Its primary aim is to enable the tests to
continue to run in case of an occurrence of an unexpected failure. For example if an
application crash occurs and a message dialog appears, QTP can be instructed to attempt
to restart the application and continue with the rest of the test cases from there onwards.
In QTP, Checkpoint is used to verify the application under test. It can introduce a
checkpoint to verify as to whether a particular object, text or a bitmap is present in the
automation run.
During a test execution, a checkpoint verifies that the behavior or state of the
actual application is consistent with the expected application or not.
6) Text Checkpoint – for checking that a section of text is found between two
other sections of text.
60/73
Q 5. How many types of main views of a script are available in QTP?
1) Keyword View: is the default test procedure interface of QTP & is most useful
for the beginners. It displays the automation steps of a test procedure as a
descriptive tree of Actions and functions. The tree contains columns listing the
Action or function name, any parameters, and comments.
2) Expert View: is most suitable for the advanced users, enabling them to customize
the test, like writing user-defined functions. It is meant for displaying and editing
of the source code of the test. Except for the root Global action, all other test
actions can be edited here. Expert View acts as an IDE for the test. It includes
most standard IDE features, such as breakpoints.
Both Keyword View & the Expert View can be selected from tabs available at the bottom of
the QTP window.
At the end of the test, QTP generates a result file for the test cases, which is in the form
of a XML tree.
This results file provides detail regarding `Pass' or `Fail' counts, error messages, and
all supporting information which allows the user to diagnose the main cause of a failure.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
Q 7. What is a Virtual Object in QTP?
Since sometimes complex objects are not recognized & recorded properly by QTP. Hence an
experienced user can define that object as a personal virtual object and build a virtual
object repository. This way by the concept of Virtual Object, the user can add some sort of
support for such complex objects.
If it is possible to extract the desired information from the object, we can do successful
record and playback against that object.
Q 8. How can we handle the exceptions with the help of recovery scenario manager
in QTP?
With the help of recovery scenario manager we can recover from unexpected events or
errors occurring in the testing environment during the test run. The Recovery Scenario
Manager presents a structured wizard which helps us in defining the recovery scenario, like
61/73
detailed definition of the unexpected event and the operations required to recover from
the exception during the run session.
Text Output values enable us to view the values which are taken by the application during
the run time. If parameterized, the values change for every iteration. Hence by creating
output values, we can capture the values which are taken by the application during the run
time and output them to the data table.
Object Spy enables us to view both the run-time object methods and the test, object
methods associated with an object and to view the syntax for a selected method. It is used
as a pointer to point towards an object. It displays the object hierarchy tree and the run-
For more QTP Realtime Sripts, visit
www.ramupalanki.com
time object methods or test object methods associated with the selected object in the
Methods tab of the Object Spy dialog box.
Like we use QTP for automating the testing of our applications, we can use the automation
object model of QTP to automate its own operations as well. With the help of objects,
methods, and properties exposed by the automation object model of QTP along with
standard programming elements like loops and conditional statements, we can write
programs which can configure QTP options and run tests or components instead of
performing these operations manually using the QTP interface.
Automation programs are especially useful for performing the same tasks several times or
on multiple tests or components, or quickly configuring QTP according to the needs for a
particular environment or application.
62/73
Most of the dialog boxes in QTP have a corresponding automation object. Most of the
options in dialog boxes can be set retrieved using the corresponding object property, and
most of the menu commands and other operations have corresponding automation methods.
During the run session, QTP creates a Runtime Data Table, which is live version of the
Data Table associated with our test. During the run session, QTP displays the run-time
data in the Data Table pane so that we can see the changes taking place in the Data Table.
When the run session ends, the Runtime Data Table closes, and the Data Table pane again
displays the stored design-time Data Table. Data entered in the run-time Data Table during
the run session does not get saved along with the test. The final data from the run-time
Data Table gets displayed in the Run-Time Data Table in the Test Results window.
Runtime Data Table is an excel file, which gets stored in the folder of the test created, its
name is Default.xls by default.
Q 13. What are the properties used by the Smart Identification mechanism?
a) Base filter properties: Are the most fundamental properties of a particular test
object class. Her we can not change their values without changing the essence of
the original object.
Scripts can be written using languages like Visual Basic, XML, JavaScript, Java, HTML
a) Coloring of a cell
During recording QTP identifies various objects and stores them as test objects. For each
test object QTP learns a set of default properties called mandatory properties.
63/73
Simultaneously QTP looks at rest of the objects to check whether these properties are
sufficient to uniquely identify the object or not. During the test run, QTP searches for
the run time objects, which match with the test objects which, have been captured by it
during recording.
When planning and creation of tests is done, we firstly consider how we would like to
store the objects in our tests. In QTP, the test objects can be stored in two types of
object repositories
a) Shared object repository: It stores test objects in a file that can be accessed by
multiple tests (in read-only mode). If someone is new to QTP, he can prefer to use
local object repositories. This way he can record and run the tests without
creating, choosing, or modifying shared object repositories because all objects are
automatically getting saved in a local object repository which can be accessed by
its corresponding action.
b) Local object repository: It stores objects in a file that is associated with one
specific action, so that only that action can access the stored objects. If someone
is familiar with QTP testing, he can find that it is quite efficient to save the
objects in a shared object repository. This way, he can use the same shared object
repository for multiple actions - if the actions include the same objects. Test
object information that applies to many actions is kept in one centralized location.
When the objects in the application change, we can update them in one location for
all the actions that use this shared object repository.
Object Repository displays a tree of all the objects in the current component or in the
current action or in the entire test , depending on the object repository mode selected
by the user. We can view or modify the test object description of any test object in the
repository or to add new objects to the repository.
For more QTP Realtime Sripts, visit
www.ramupalanki.com
QTP remembers the default property values and determines in which test object class it
fits. If it is not found enough it automatically adds assistive properties, one by one to the
description until it successfully compiles the unique description. If no assistive properties
are available, then it adds a special Ordinal identifier such as object location on the page
or in the source code.
QTP uses an in-built functionality called "Step Generator" to create scripts while
appropriate steps are entered into it. Step Generator utility enables us to add steps by
selecting from a range of context-sensitive options and entering the required values.
64/73
We can open the Step Generator from the Keyword View or Expert View while recording or
editing our test. We can also open the Step Generator from the Active Screen while editing.
a) In the function library, click the location in which you want to insert the new step.
b) Choose Insert > Step Generator, or right-click and choose Step Generator.
Alternatively, press F7.
a) Non-reusable action - can be called only in the test with which it is stored, and
can be called only once.
b) Reusable action - can be called multiple times by the test with which it is
stored (the local test) as well as by other tests.
c) External action – is a reusable action which is stored with another test. External
actions are read-only in the calling test, but we can choose to use a local, editable
copy of the Data Table information for the external action.
By default, all new actions are non-reusable. We can mark every action created by us in
the test as reusable or non-reusable.
Data Driver feature enables us to quickly parameterize several property values for the
For more QTP Realtime Sripts, visit
www.ramupalanki.com
test objects, checkpoints, and method arguments containing the same constant value within
a given action.
We can choose to replace all occurrences of a selected constant value with a parameter, in
the same way that we can use a Find and Replace All operation instead of a step-by-step
Find and Replace process. QTP can also show us each occurrence of the constant so that
we can decide as to whether to parameterize the value or not.
We can modify an object by modifying any one of its property values or by changing the set
65/73
of properties used to identify the particular object. This can be done for objects in the
local object repository with the help of Object Repository window, and for objects in
the shared object repository using the Object Repository Manager.
a) Right-click the step containing the object that changed, and choose Object
Properties or choose Edit > Step Properties > Object Properties from the menu bar.
b) The Object Properties dialog box opens and displays the properties QuickTest
uses to identify the object.
During a run session, we can use SystemUtil, object to open and close the applications and
processes.The SystemUtil.Run statement gets automatically added to the test when we
run an application from the Start menu or the Run dialog box while recording a test.E.g :
SystemUtil.Run "Notepad.exe" SystemUtil.CloseDes cendentProcesses ( Closes all the
processes opened by QTP )
Regular expressions can be used while defining the properties of an object, the methods of an
argument, while parameterizing a step, and while creating checkpoints with varying values
The article will discuss on how to close processes in QTP. First we will discuss the
SystemUtil object and then later in the article few other approaches.
SystemUtil Object
SystemUtil is utility object provided by QTP. It can be used to launch or closes a process.
Let's look at various methods supported by this object:
66/73
SystemUtil.Run file, [params], [dir], [op], [mode]
The Run method allows running a new process. The code below illustrates few example on
how to launch a process using SystemUtil object
The problem with using the above method is that it will also close Quality Center (QC)
window even if script was launched from QC. This method should be used in case you are not
concerned about running scripts from QC.
CloseProcessByWndTi tle method allows closing a process by its title. The title can also be
supplied as a regular expression by setting the bRegExp to True
67/73
'Launch a notepad window
SystemUtil.Run "notepad.exe"
SystemUtil.CloseDes cendentProcesses
CloseDescendentProc esses can be used to close any process launched by QTP. The code
below illustrates the usage
'Launch explorer
SystemUtil.Run "iexplore.exe"
This method is best suited to be used during the end of a script to cleanup any process left
open.
Many times it's required to close all open browsers at the start of the script. There are
various ways of achieving this; one is to use the SystemUtil.ClosePro cessByName method
which we discussed earlier. But that approach is not generic as it won't close other
browsers that QTP does support (like firefox and netscape). We can come with a generic 3
lines code which can close all supported QTP browsers
68/73
Wend
QTP assigns creation time to each browser based on the launch time of that browser. A
browser started earlier will have a lower creationtime and a browser started at a later point
of time will have a higher creationtime. So when we start closing the browser with
creationtime: =0, other browser's creationtime is decreased. Which means that the
creationtime: =0 browser will always exist until there is no browser open. This approach of
closing browsers suffers from 2 issues
* QTP has a bug which makes it wait 10 second on Browser identified using
creationtime when there is only one browser open. So above code will always take 10
secs to close the last browser
* The code does not allow to ignore any specific browser (like Quality Center)
Though there another way by which can enumerate all open browser and close them in
QTP and below demonstrates the same
iCount = allBrowser.Count - 1
For i = 0 To iCount
allBrowser(i) .Close
End If
Next
69/73
By now you must be wondering about the line
So why didn't we use allBrowser(i) .Page("micclass: =Page"), well this a Bug or Limitation in
QTP which does not allow using any further Test objects on objects returned from
ChildObjects. This might be because of the fact that a QTP TestObject does not have
any property or method as other Test Object. Ex - a Browser supports no method or
property named Page. But QTP interprets that as way of hierarchy to decide where to look
for that object. Anway this is all my opinion and might not be accurate. So the only
workaround of using further TestObjects is to use ChildObjects again.
IE.Terminate( )
Next
Above code can also be used to close any process on a remote machine by changing sComp
to the IP of the remote machine
Let's take a look at another way which is generic to VBScript and not dependent on QTP. For
this we will use the COM object of "Shell.Application" . This COM library provides a collection
of all open windows (Explorer + Internet Explorer). We can access each windows
70/73
property and close if it is iexplore.exe process. The code below demonstrates the same
window.Quit
End If
Next
The code above will only close alternate windows. This happens because we are loop through
a collection of windows and closing a window in that collection reduces the collection and
hence the for loop skips one window after closing a window. This issue can easily be resolved
by adding the windows to be closed into an array and the closing them later
Dim windows2Close
71/73
Set windows2Close( UBound(windows2C lose)) = Window
End If
Next
Window.Quit
Next
The above code shows how to ignore few internet explorers and close rest.
Summary
In this article we explored various ways of Closing processes and browsers using QTP.
First of all let us understand the meaning of "General run error" as you are seeing above.
"General run error" occurs in a situation when some source while being accessed by QTP
propels an error.
This is the inherent nature of QTP that in such a situation it displays a "General run
error" message instead of showing a simple "Error" .
For more QTP Realtime Sripts, visit
www.ramupalanki.com
Following line of a simple code will illustrate as to how the "General run error" shall be
generated.
On running the above code, you will get an error message "Invalid Syntax"
Here we can see that the actual error is in-fact an "Invalid Syntax Error" and not a
"General run error". However to view the actual error in this case, click on the
"Debug" button and open the Watch Window.
- Incase we get this type of error while working on a QTP test object; we can place
a Msgbox to check the existence of the object being handled.
72/73
- However if we get this type of error while working under the Web environment, the issue
can be resolved by using DOM object method.
obj(i).Close
Next
For more QTP Realtime Sripts, visit
www.ramupalanki.com
73/73