Professional Documents
Culture Documents
Test suites are normally used to group similar test cases together. The collection of individual
test cases that will be run in a test sequence is called a test suite.
The collection of individual test cases that will be run in a test sequence until some stopping
criteria are satisfied is called a test suite. Test suite preparation involves the construction and
allocation of individual test cases in some systematic way based on the specific testing
techniques used.
Another way to obtain a test suite is through reuse of test cases for earlier versions of the same
product. This kind of testing is commonly referred to as regression testing. It ensures that
common functionalities are still supported satisfactorily in addition to satisfactory performance
of new functionalities. Special types of formal models are typically used to make the selection
from existing test cases.
Test suite management includes managing the collection of both the existing test cases and the
newly constructed ones. At a minimum, some consistent database for the test suite needs to be
kept and shared by people who are working on similar areas. Some personnel information can
also be kept in the test suite, such as the testers who designed specific test cases, to better
supported future use of this test suite.
An object as we know is a graphic user element in an application e.g. a button or a list or an edit
box and the special characteristics of an object within the QuickTest are called object
properties. QTP stores the recorded object properties in Object Repository.
Object Repositories are of two types Local and shared .
If objects are stored in a Local Object Repository then these are available to specific actions but
not to all the actions. But if these objects are stored in one or more Shared Object Repositories
then multiple actions or tests can use them.
By default QTP makes and uses Local Object Repository. If we create a new blank test and do
a recording on it, QTP automatically creates a Local Object Repository for that test or action
and stores the information about any object it finds in that corresponding Object Repository.
In QTP 9 we can associate multiple Shared Object Repositories with an action. If multiple
Shared Object Repositories are associated with an action then also while recording QTP stores
objects in corresponding Local Object Repository on the condition that those objects are not
already stored in any corresponding associated Shared Object Repositories. This is the default
that every time we create a new action QTP creates a new corresponding Local Object
Repository. It is also true that Object Repositories are associated with actions and no matter how
many times we learn or record on the same object in our application in different actions the
object will be stored as separate test object in each of the Local Object Repository. Local Object
Repository is automatically saved with the test when we save it. The extension of the Local
Object Repository is .mtr, but it is not accessible as a separate file as in case of the Shared
Object Repository.
We can also manipulate some aspects of Local Object Repository using Quick test Object
Repository Automation Object Model.
For example we can add, remove, rename test objects in Local Object Repository. [QuickTest
Object Repository Automation documents the Object Repository automation object model that
enables you to manipulate QuickTest object repositories and their contents from outside of
QuickTest.]
When we open a test that was created using a version of QTP earlier that version 9 we are asked
whether we want to convert it or view it in read only format. In any case if the test previously
used per-action Object Repository, the objects in each per action repository are moved to the
Local Object Repository of each action in the test.
If the test previously used a shared object repository, the same shared object repository is
associated with each of the actions in the test, and the local object repository is empty.
While learning or recording we can specify Shared Object Repository for the selected action.
We can specify and associate one or more Shared Object Repositories with each action. We can
also create new Shared Object Repository and associate it with our action.
In case of Shared Object Repository, QTP uses existing information and does not add objects to
the Object Repository if we record operations on an object that already exists either in Shared or
Local Object Repository.
As said earlier QTP does not add objects directly to the associated Shared Object Repository as
we record, instead it adds new objects in Local Object Repository (if that object does not already
exist in associated Shared Object Repository).
We can surely export Local objects to Shared Object Repository.
There are different ways in which we can move objects from Local Object Repository to
Shared Object Repository:
1)
Exporting the objects to the Shared Object Repository from the Local Object Repository:
In Object Repository window choose the action whose local objects you want to move. Choose
File-> Export Local Objects.Select the location in which you want to save the file. Click on save.
2)
We can update the Shared Object Repository with the Local Object Repository:
If we create a new test it will be created with Local Object Repository, we can associate any
new or old Shared Object Repository with it, and so we can update that Shared Object
Repository with Local Object Repository.
In Object Repository Manager open the Shared Object Repository (clear open in read only check
box).
The test in this case should not be open. In Object Repository Manager go to Tools –> Update
From Local Repository. Select the test who's Local Object Repository you want to use. Click
update all. It will move all the objects to the Shared Object Repository.
3)
We can also merge objects from two Object Repositories (called as primary and secondary in
QTP 9) into a new single Object Repository (target Object Repository in QTP 9). The original
source files are not changed. It also enables you to merge objects from Local Object Repository
of one or more action(s) into a Shared Object Repository. It is recommended to use as a primary
Object Repository the file in which you have invested alot of your effort, like which has more
number of objects.
If we do not specify a file extension for Shared Object Repository when creating a new Shared
Object Repository QTP automatically appends a default extension name for Shared Object
Repository as .tsr. This means that we can create Shared Object Repository with any extension
other than .tsr, it should work fine (I have tried that and it works fine), I think it may create
problems while merging two Object Repositories (I haven't tried that yet).
We can compare two Object Repositories using the Object Repository Comparison Tool. The
tool enables you to identify similarities, variations or changes between two Object Repositories.
We can also copy objects to Local Object Repository from the Shared Object Repository. We
can copy, paste and move objects in Local Object Repository and copy, paste and move objects
within Shared Object Repository and between Shared Object Repositories.As said earlier we
can also copy objects from shared Object Repository to Local Object Repository to modify
them locally.
We cannot remove an association between the action and its Local Object Repository.
According to QTP user guide:
You can associate as many object repositories as needed with an action, and the same object
repository can be associated with different actions as needed. You can also set the default object
repositories to be associated with all new actions in all tests.
Whenever we make any changes to an Object Repository those changes are automatically
updated in all the associated tests open on the same computer as soon as we make the change
even if the Object Repository is not yet saved and if we close the same Object Repository
without saving the changes the changes are rolled back in any open tests. For the test that was
not open when we changed Object Repository, when we open the test on the same machine on
which we modified the Object Repository the test is automatically updated with all the saved
changes. To see saved changes in a test or repository open on a different computer, you must
open the test or object repository file or lock it for editing on your computer to load the
changes.
Important points about Object Repositories
It is a point to consider while planning and creating test that how you want to store objects; either
you want to store them in Local Object Repository or Shared Object Repository.
1)
For each action, we can also use a combination of objects from the Local and Shared Object
Repositories, according to our needs. Local objects can also be transferred to a shared object
repository, if necessary. This will cut maintenance and increase the reusability of the tests
because it will enable us to maintain the objects in a single, shared location instead of multiple
locations.
2)
If there is a same name object in both the Local Object Repository and in a Shared Object
Repository associated with the same action, the action uses the local object definition i.e. the
local object is given preference over the shared object. If an object with the same name is stored
in more than one Shared Object Repository associated with the same action, the object definition
is used from the first occurrence of the object, according to the order in which the Shared
Object Repositories are associated with the action.
3)
When we open an existing test, it always uses the object repositories that are specified in the
Associated Repositories tab of the Action Properties dialog box or in the Associate Repositories
dialog box. When we access Shared Object Repositories from tests they are read-only; we can
edit them only using the Object Repository Manager.
4)
As and when an application under test changes, such as when a "Log in" button is renamed "Sign
Into," we can make one update to an XML-based Shared Object Repository (within the new
Object Repository Manager), and the update will circulate (propagate) to all tests that reference
this object. QuickTest Professional keeps object-level changes synchronized among users
throughout test creation efforts.
Object Repository dialog box
Object Repository dialog box window shows a tree of all the objects (either Local or Shared) on
its left hand side in the selected action. On selecting any object in the tree Object Repository
window shows the information about the object like the name, repository in which it is stored
etc. On the left hand side in a tree local objects are editable while the shared ones are grayed out
(non-editable).
To view the test object properties, to modify test object properties and to add objects to Local
Object Repository we can use Object Repository window. We can also delete objects from
Object Repository window; this is needed as when an object is removed form the test it is not
automatically removed from the Local Object Repository.
Object Repository in QTP is XML based means that if we change something related to the
object in Shared Object Repository., the change will be propagated to all the tests that
reference this object, in real time.
Adding Objects to Repositories
[Please see QTP user guide for in-depth information on these below points.]
We can add objects to Shared Object Repository or Local Object Repository in a number of
different ways-
We can decide whether to add only a selected object, or to add all objects of a certain type, such
as all button objects, or to add all objects of a specific class, such as all WebButton objects.
We can modify objects stored in a Local Object Repository using the Object Repository
Window and objects in a Shared Object Repository using the Object Repository Manager.
It is possible to add objects to the object repository before they exist in an application.
We can also add objects to the Local Object Repository while editing our test.
We can add the object directly to a Shared Object Repository using the Object Repository
Manager, so that it is available in all actions that use this Shared Object Repository.
If needed, we can merge test objects from the Local Object Repository into a Shared Object
Repository.
We can also add objects to a Shared Object Repository while navigating through the
application ("Adding Objects Using the Navigate and Learn Option").
We can also add an object to the Local Object Repository by choosing it from the application in
the Select Object for Step dialog box (from a new step in the Keyword View or from the Step
Generator).
We can add objects to the object repository using the Add Objects to Local or Add Objects
option.
We can add objects to the Local Object Repository of the current action by selecting the
required object in the Active Screen.
QTP (QuickTest Professional) lets you create tests and business components by recording
operations as you perform them in your application.
Test - A compilation of steps organized into one or more actions, which we can use to verify that
our application performs as expected. A test is composed of actions (3 kinds of actions are there
in QTP Non-reusable action, Reusable action and External action).
1)
First step is Planning
Before starting to build a test, you should plan it and prepare the required infrastructure.
For example, determine the functionality you want to test, short tests that check specific
functions of the application or complete site.
Decide how you want to organize your object repositories.
2)
Second step in QTP is Creating Tests or Components
We can create a test or component by
a) Either recording a session on your application or Web site.
As we navigate through the application or site, QuickTest graphically displays each step we
perform as a row in the Keyword View. The Documentation column of the Keyword View also
displays a description of each step in easy-to-understand sentences. A step is something that
causes or makes a change in your site or application, such as clicking a link or image, or
submitting a data form.
OR
b) Build an object repository and use these objects to add steps manually in the Keyword View
or Expert View. We can then modify your test or component with special testing options and/or
with programming statements.
3)
Third step is
Inserting checkpoints into your test or component.
A checkpoint is a verification point that compares a recent value for a specified property with the
expected value for that property. This enables you to identify whether the Web site or application
is functioning correctly.
4)
Fourth step is
Broaden the scope of your test or component by replacing fixed values with parameters.
To check how your application performs the same operations with different data you can
parameterize your test or component.
When you parameterize your test or component, QuickTest substitutes the fixed values in your
test or component with parameters
Each run session that uses a different set of parameterized data is called an iteration.
We can also use output values to extract data from our test or component. An output value is a
value retrieved during the run session and entered into the Data Table or saved as a variable or a
parameter. We can subsequently use this output value as input data in your test or component.
We can use many functional testing features of QuickTest to improve your test or component
and/or add programming statements to achieve more complex testing goals.
5)
Fifth step is running the test
After creating test or component, we run it.
Run test or component to check the site or application.
When we run the test or component, QuickTest connects to your Web site or application and
performs each operation in a test or component, checking any text strings, objects, or tables you
specified. If we parameterized the test with Data Table parameters, QuickTest repeats the test (or
specific actions in your test) for each set of data values we defined.
Run the test or component to debug it.
We can control the run session to identify and eliminate defects in the test or component. We can
use the
Step Into,
Step Over,
And Step Out
commands to run a test or component step by step.
We can also set breakpoints to pause the test or component at pre-determined points.
We can view the value of variables in the test or component each time it stops at a breakpoint in
the Debug Viewer.
6)
Sixth step is analyzing the results
After we run test or component, we can view the results.
➤ View the results in the Results window.
After running the test or component, we can view the results of the run in the Test Results
window. We can view a summary of the results as well as a detailed report.
➤ Report defects identified during a run session.
If Quality Center is installed, we can report the defects fond out to a database. We can instruct
QuickTest to automatically report each failed step in the test or component, or we can report
them manually from the Test Results window.
SettingsPrivacyAddThis
Test object Model is a set of object types or Classes that QuickTest uses to represents the
objects in our application.
A test object class comprises of a list of properties that can individually (uniquely) identify
objects of that class and a set of appropriate methods that QuickTest can record for it.
Test Object Class
Properties Methods
A test object is an object that QuickTest creates in the test to correspond to (represent) the actual
object in the application. QuickTest uses the stored information about the object during the run
session to identify and check the object.
A run-time object is the real (actual) object in the application or Web site on which methods are
performed during the run session.
Properties and methods of objects:
The property set for each test object is created and maintained by QuickTest. The property set for
each run-time object is created and maintained by the object architect (creator) (Microsoft for
Internet Explorer objects, Netscape for Netscape objects).
Similarly, methods of test objects are methods that QuickTest recognizes and records when they
are executed (performed) on an object while we are recording, and that QuickTest executes when
the test or component runs. Methods of Run-time object are the methods of the object in the
application as defined by the object architect (creator). We can access and execute run-time
object methods using the Object property.
Some important points to remember about methods and properties :
Each test object method we execute (perform) while recording is recorded as a separate step
in the test. When we run the test, QuickTest executes (performs) the recorded test object method
on the run-time object.
Properties of test object are captured from object while recording. QuickTest uses the values
of these properties to identify runtime objects in the application during a run session.
Property values of objects in the application may change .To make the test object property
values match the property values of the run-time object, we can modify test object properties
manually while designing the test or component or using SetTOProperty statements during a run
session. We can also use regular expressions to identify property values.
We can view or modify the test object property values that are stored with the test or
component in the Object Properties or Object Repository dialog box.
We can view the syntax of the test object methods as well as the run-time methods of any
object on our desktop using the Methods tab of the Object Spy.
We can retrieve or modify property values of the TEST OBJECT during the run session by
adding GetTOProperty and SetTOProperty statements in the Keyword View or Expert View. We
can retrieve property values of the RUNTIME OBJECT during the run session by adding
GetROProperty statements.
If the available test object methods or properties for an object are not sufficient or they do not
provide the functionality we need, we can access the internal methods and properties of any run-
time object using the Object property. We can also use the attribute object property to identify
Web objects in the application according to user-defined properties.
qtp.blogspot.com
Bottom of Form
After we add a checkpoint, QuickTest adds a checkpoint to the current row in the Keyword
View and adds a Check CheckPoint statement in the Expert View.
By default, the checkpoint name receives the name of the test object on which the checkpoint is
being performed. We can change the name of the checkpoint if
needed.
Types of Checkpoints:
1. Standard checkpoint
2. Image checkpoints
3. Bitmap Checkpoint
4. Table checkpoints
5. Accessibility Checkpoint
6. Text Checkpoint
7. Page Checkpoint
8. Database Checkpoint
9. XML checkpoints
Standard checkpoints allow checking the object property values in the Web site or application
under test. Standard checkpoints evaluate (compare) the expected values of object properties
captured during recording to the object's current values during a run session. For
example we can check that a radio button is activated after it is selected. Standard checkpoints
are supported for all add-in environments.
Standard checkpoints can be used to perform checks on
Images,
Tables,
Web page properties, and
Other objects within your application or Web site.
Standard checkpoints can be created for all supported testing environments (as long as the
appropriate add-in(s) are loaded).
Image checkpoints allow you to check the properties of an image in the application or Web
page. For example, you can check that a selected image's source file is correct or not. An image
checkpoint can also be created by inserting a standard checkpoint on an image object. Image
checkpoints are supported for the Web add-in environment
With Bitmap Checkpoint we can check an area of a Web page or application as a bitmap. While
creating a test, we have to specify the area to check by selecting an object. An entire object or
any area within an object can be checked. Bitmap checkpoints are supported for all add-in
environments
By adding table checkpoints to the test, we can check the content of tables displayed in the
application. For example, we can check that a specified value is displayed in a certain cell.
Certain environments also support checking the properties of the table object. For example, a
check that a table has the expected number of rows and columns. A table checkpoint can also be
created by inserting a standard checkpoint on a table object.
Accessibility Checkpoint recognizes areas of your Web site that may not conform to the World
Wide Web Consortium (W3C) Web Content Accessibility Guidelines. For example, check if the
images on a Web page include ALT properties, required by the W3C Web Content Accessibility
Guidelines. Accessibility checkpoints are supported for the Web add-in environment
QuickTest can check that a text string is displayed in the appropriate place in an application or
on a Web page with Text Checkpoint. Text checkpoints are supported for the Web add-in
environment, plus some Web-based add-in environments
Page Checkpoint checks the features of a Web page. For example, you can check how long a
Web page takes to load or whether a Web page contains broken links. A page checkpoint can
also be created by inserting a standard checkpoint on page object. Page checkpoints are
supported for the Web add-in environment
The contents of a database accessed by your application can be checked by Database
Checkpoint. Database checkpoints are supported for all add-in environments
By adding XML checkpoints to your test, you can check the contents of individual XML data
files or documents that are part of your Web application. The XML Checkpoint option is
supported for all add-in environments.
Top of Form
qtp.blogspot.com
Bottom of Form
In the Flight application enter the Date of Flight, Fly From and Fly To fields and nothing else.
(The reason for doing this is that it will enable the 'Flight...' button)
It will Run the test and show you the result as Fail. This is because QTP was looking for a
disabled 'Flight...' button for which it recorded the information at the record time, but now since
the button was enabled at run time, so it failed.
qtp.blogspot.com
This will help you in understanding the standard checkpoint in QTP more deeply.
Bottom of Form
3. Go to Insert->Checkpoint->Standard Checkpoint.
(QTP will be minimized and mouse pointer will take the shape of a hand.)
4. Click on the Flights... button which is on the right hand side of Fly To dropdown.
8. Go to Resources->Object Repository
(OR associated with this particular action will open)
Bottom of Form
2. Click on Record. When we click on Record, "Record and Run Settings" window opens
up. Go to "Windows Applications" tab and choose first option "Record and run test on
any open Windows based application." and click on ok.
3. Go to Insert (menu)->Checkpoint->Database Checkpoint
4. A 'Database Query Wizard' opens.
5. Select ' Specify SQL statement manually' from the Query definition area. Click Next.
Click Create.
6. Go to 'Machine Data Source' Tab
7. Select Oracle from data source name. Click Ok. It will open 'Oracle ODBC Driver
Connect'
12. In the Expert View, it just adds one line "DbTable("DbTable").Check CheckPoint
"DbTable")"
This is the simplest database checkpoint example.
Lets run it.
Click on Run. ( we don't need to open any other window or application to run this as our Oracle
is running at the back end as a service - default way in which it was installed- nothing special.)
When it is passed it will show following in the Result window:
Test Checkpoint-database Summary (where Checkpoint-database is the name with which I saved
the test)
Run-Time Data Table
Checkpoint-database Iteration 1 (Row 1)
Action1 Summary
DbTable
Checkpoint "DbTable"
( when you click on this, in details it will show checked 112 cells (in your case number of cells
may differ). It means if you go to the oracle and add or delete any row and run this test again it
will fail.)
Just try to think how QTP is comparing the expected results with the actual one, with the count
of cells.
qtp.blogspot.com
Bottom of Form
QTP Tutorials 7 - Bitmap Checkpoint
Now we will look at the bitmap checkpoint which is different from the image checkpoint.
Make sure that QTP and the Flight application are open.
STYLE A
1. Open a blank test.
2. Click on Record. When we click on Record, "Record and Run Settings" window
opens up. Go to "Windows Applications" tab and choose first option "Record and
run test on any open windows based application." and click Ok.
3. Go to Insert (menu)->Checkpoint->Bitmap Checkpoint
4. Click on the "Fly To" combo box.
5. "Object Selection- Bitmap Checkpoint Properties" window opens up. I will have
"WinComboBox:Fly To" highlighted. Click ok
6. It will open "Bitmap Checkpoint Properties" window.
7. Change the "Checkpoint timeout" at the bottom of the window to 0 seconds, so that we
will have no wait time while running the test.
8. Click ok.
9. Click stop to stop recording the test.
STYLE B
Above, after 3rd point, instead of clicking on the "Fly To" combo box, click somewhere in the
empty space above the "Fly From" Combo box but below the line, i.e. in the "Flight Schedule"
area.
"Object Selection- Bitmap Checkpoint Properties" window opens up. It will have
"WinObject:Flight Schedule" highlighted. Click ok
It will open "Bitmap Checkpoint Properties" winodow. This time it will have "Flight schedule"
area instead of just the "Fly To" combo box.
Now click on the "Select Area..." button. Mouse pointer will change so that you can select any
area by dragging. Just select "Fly From" combo box by dragging.
Change the "Checkpoint timeout" at the bottom of the window to 0 seconds. so that we will have
no wait time while running the test.
Click ok.
Click stop to stop recording the test.
Now you can run the test it will pass. To see how it stores the results, just fail the test. If you
have recorded in the style A then just select any value in the "Fly To" combo box and then run
the test. In the result window on the left hand side when you click on Checkpoint "Fly To:", it
will show you the expected bitmap and actual bitmap on the right hand side. (note: it will show
that only in case of Failed result)
qtp.blogspot.com
Bottom of Form
qtp.blogspot.com
Bottom of Form
QTP Tutorials 9 - Text Checkpoint
Now we will look at the Text Checkpoint:
1. Open a blank test and a web page in offline mode like this below:
2. Click on Record. When we click on Record, "Record and Run Settings" window opens
up. Go to "Web" tab and choose first option "Record and run test on any open browser."
and click on ok.
3. Go to Insert (menu)->Checkpoint->Text Checkpoint.The mouse pointer will become
hand and QTP will be minimized.Click on the first paragraph (which starts with-The
page you are looking..) of that web page.
4. "Text Checkpoint Properties" window opens up. It will show the text to be checked in
"Checkpoint Summary" area in red color and also show in blue color the text which is
displayed before and after the selected text.
5. Click on Configure -here you can change your selected text, change before and after text
and so on, but for now just click ok. At the bottom of the "Text Checkpoint Properties"
window change 'Checkpoint timeout' to 0 seconds. Again Click ok to come out of "Text
Checkpoint Properties" window.
6. Click on stop in order to stop recording.
Run the test and when it is passed just go to the results window and on the left hand side just
expand every option and click on last option Checkpoint "Cannot find server". On the right
hand side it will show you the details. Try to understand those.
qtp.blogspot.com
Bottom of Form
qtp.blogspot.com
Bottom of Form
msgbox (return)
Now run the test and see the msgbox appearing with the return value.
qtp.blogspot.com
Bottom of Form
A small & simple example to get a feel of both Text and Text Area Checkpoint:
Make sure that the Flight Reservation window is open as shown below.
QTP will be minimized and the mouse pointer will change into pointing hand.
With the pointing hand click on $110.00 in the above Flights Table. Object Selection window
opens. Click OK. Text Checkpoint Properties window opens. (See Screenshot for Text
Checkpoint Properties window below). Click Cancel.
QTP will be minimized and the mouse pointer will change into crosshairs.
With the crosshairs select $110.00 in the above Flights Table. Object Selection window opens.
Click OK. Text Area Checkpoint Properties window opens. (See Screenshot for Text Area
Checkpoint Properties window below). Click Cancel.
Object Selection Window for "Text Area checkpoint" will also be similar as the below one for
"Text Checkpoint":
Text Checkpoint Properties window [In Windows-based environments, if there is more than one
line of text selected, the Checkpoint Summary area displays [complex value] instead of the
selected text string. You can then click Configure to view and manipulate the actual selected text
for the checkpoint.]
qtp.blogspot.com
Bottom of Form
recording modes also like Analog Recording or Low Level Recording. Normal mode is the
default and takes full advantage of the QuickTest test object model, as it recognizes the objects
in the application regardless of their location on the screen.
Analog Recording : Exact mouse and keyboard operations are recorded in relation to either the
screen or the application window. In this QTP also records and tracks every movement of the
mouse for example, recording a signature produced by dragging the mouse. Analog Recording
steps are not editable from within QuickTest.
Low Level Recording : At any time, if an environment or on an object not recognized by
QuickTest, use Low Level Recording. It records at object level and records all run-time objects
as Window or WinObject test objects. QuickTest records all parent level objects as Window test
objects and all other objects as WinObject test objects.
Each step recorded in Low Level Recording mode is shown in the Keyword View and Expert
View.
All the three modes of recording can be used in a single test e.g. we can switch to either Analog
Recording or Low Level Recording in the middle of a recording session for specific steps and
then return to normal recording
mode.
Analog Recording and Low Level Recording require more disk space than normal recording
mode.
Use Analog Recording when :
The actual movement of the mouse is what you want to record.
Recording in Analog mode can be relative to the screen or relative to a specific window (see user
guide for detail)
In Analog Recording a separate file is saved and stored with the action.
In Analog Recording mode, QuickTest adds to your test a RunAnalog statement that calls the
recorded analog file.
Use Low Level Recording when :
Environments or objects not supported by QuickTest.
Exact location of the operation on your application screen is necessary. in normal mode
QuickTest performs the step on an object even if it has moved to a new location on the screen.
If the location of the object is important to your test, switch to Low Level Recording
qtp.blogspot.com
Bottom of Form
qtp.blogspot.com
Bottom of Form
Item The item on which we want to perform the step and it can be a test object, utility object,
function call, or statement. This column shows a hierarchical icon-based tree. The highest level
of the tree is actions, and all steps are contained within the relevant branch of the tree.
Operation The operation (methods or functions) to be performed on the item selected in the
Item column, for example, Click or Select.
Value The argument values for the selected operation, for example, the mouse button to use
when clicking the image.
Assignment The assignment of a value to or from a variable for example, Store in cCols would
store the return value of the current step in a variable called cCols so you can use the value later
in the test. This column is not visible by default.
Comment Any textual information you want to add regarding the step. This column is also not
visible by default.
qtp.blogspot.com
Bottom of Form
qtp.blogspot.com
Bottom of Form
Wait is like forcing the QTP to wait for a specified amount of time while synchronization is not
a 'forced' wait e.g. whenever a specific page loads QTP moves forward in case of
synchronization, but in case of wait, if the wait is for 10 seconds and a webpage loads in 3
seconds then it still waits for 7 seconds.
Synchronization is there to take care of the timing problems between QTP and the AUT.
Examples where synchronization can be used:
For a web page to load.
For a button to become enabled or disabled.
For client-server communications to finish.
Synchronization is possible in many ways:
1)
We can insert a synchronization point for example for a progress bar to reach 100%. QTP will
generate a WaitProperty statement in the Expert View in case of synchronization.
2)
We can use Exist or Wait statements. Exist statements always return a Boolean (0 or 1) value.
3)
We can also modify the default amount of time that QTP waits for a Web page to load.
(Browser Navigation Timeout, File(menu)-> Settings-> Web tab)
4)
When working with tests, we can increase the default timeout settings for a test to instruct
QuickTest to allow more time for objects to appear.
(Object Synchronization Timeout, File(menu)-> Settings-> Run tab)
Synchronization is enabled only during recording.
qtp.blogspot.com
Bottom of Form
Example of Synchronization
Make sure that only QTP and Sample Flight application are open.
Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to
"Windows Applications" tab and choose first option "Record and run test on any open windows
based application." and click on ok.
Enter the Date of flight as tommorrows date.
In Fly From choose Denver.
In Fly To Choose Frankfurt.
Click on Flights... button which is on the
R.H.S of the Fly To combo box.
Flights Table window open up. Let the
first option remains selected in that and just click on ok. It will
automatically fill some of the fields.
Enter your name in the Name field.
Click on Insert Order and let it complete uptill 100% untill you see the 'Insert Done...' text.
Go to Insert (menu)-> Synchronisation Point. QTP will be minimized and cursor will take the
shape of a hand.
Click on that 'Insert Done...' text in the Flight application.
'Object Selection - Synchronization Point' window will open with 'ActiveX: Threed Panel
Control.' selected.
Click Ok.
'Add Synchronization Point' window will open. Choose Property name as 'text' and Property
value as "Insert Done..." (Don't forget to put those 3 dots, and double quotation marks e.g. " in
the Property value text box.)
Click Ok.
In Flight application go to File (menu)-> New Order.
Click Stop in order to stop the recording.
This whole process will add WaitProperty.
The code in the Expert view looks like this:
Window("Flight Reservation").ActiveX("MaskEdBox").Click 1,9
Window("Flight Reservation").ActiveX("MaskEdBox").Type "092407"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Frankfurt"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "axc"
qtp.blogspot.com
Bottom of Form
Example of WAIT
Make sure that only QTP should be open.
Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to
"Windows Applications" tab and choose first option "Record and run test on any open windows
based application." and click on ok.
Go to Start->AllPrograms->QuickTest Professional->Sample Applications->Flight.
Enter Username as your first name (make sure to enter 4 or more characters).
(use tab to move to password textbox.)
Enter password as 'mercury.'
Click Ok.
When Flight Reservation window is open, go to File(Menu)->Exit.
It will record the code as below but one thing which I have added extra is Wait(5) in step 4 (just
go to the expert view and add this line before the line which includes encrypted password).
qtp.blogspot.com
Bottom of Form
Example of Sync
Make sure that your internet is On and QTP is open.
Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to
"Web" tab and choose first option "Record and run test on any open browser." and click on ok.
Open internet explorer (make sure your default page is www.google.com, so that when you open
internet explorer, it by default opens google.com as homepage..)
Type Blogger in the search text box and click on "I'm Feeling Lucky" button instead of Search
button.
When www.blogger.com is open (i.e. when you see 'Done' on the status bar at the bottom) , click
on Back toolbar button (below File menu) to go back to google.com again.
Go toFile(Menu)->Exit.
It will record the following code with sync automatically recorded by QTP (see 4th step).
1)SystemUtil\Program files\Internet Explorer\IEXPLORE.EXE","","C:\Documents and
Settings\Sachin","open"
2) Browser("Google").Page("Google").WebEdit("q").Set "blogger"
3) Browser("Google").Page("Google").WebButton("I'm Feeling Lucky").Click
4) Browser("Google").Page("Blogger: Create your Blog").Sync
5) Browser("Google").Back
6) Browser("Google").WinToolbar("ToolbarWindow32").Press "&File"
7) Browser("Google").WinMenu("ContextMenu").Select "Close"
Try to run this code, it works fine.
Now go to File(Menu)->Settings, Web tab and change the 'Browser navigation Timeout' to 2
seconds for example and then run the above code again. It will fail because sync method waits
for the browser to complete the current navigation, but here we have set the browser navigation
timeout to 2 seconds, which is too short for a browser to complete the navigation i.e. to open
www.blogger.com after clicking on "I'm Feeling Lucky" button (I am not on T1 lines, my
internet connection is average), because what happens is, after the 3rd step it just waits for 2
second after which it goes to the Back button, but it finds it disabled as it gets enabled only when
www.blogger.com is open.
Keep 'Browser navigation Timeout' to 10 seconds in File(Menu)->Settings and then it should
pass because in 10 seconds it surely makes the back button enabled after the 3rd step of clicking
"I'm Feeling Lucky".
qtp.blogspot.com
Bottom of Form
QTP Parameters
This is not an exhaustive material on parameterization. This is just to give you a startup on
parameters in QTP, so that you can go ahead and do wonders with parameters in QTP on your
own.
Test parameters
Action Parameter
Parameterize a checkpoint
qtp.blogspot.com
Bottom of Form
qtp.blogspot.com
Bottom of Form
msgbox(parameter("a"))
13. Go to Expert View of Action2 and type:
For i=1 to 3
RunAction "Action1", oneIteration, RandomNumber("arg_a")
Next
14. When you copy the above text to Expert View of Action2, it will show you a message that it
has made Action1 Reusable, just click ok.
15. Now Run the test.
(It would be better if you run it by activating the expert view, then it will show you which step it
is currently running by pointing to that particular step with yellow color arrow and then you will
be able to understand it in a better way. You will see that it shows a different value in each
msgbox() because we selected 'For each action iteration' from the 'Generate new random number'
area. If we select the second option 'For each test iteration' then a message
box will show same values, but different values if you run it next time i.e. a different value at
each test run.)
RandomNumber is an Object.
RandomNumber(ParameterNameOrStartNumber [,EndNumber])
EndNumber is optional above.
Second example of Random Numbers:
Here is another way of generating random numbers:
Open a new test and in the Expert view write these lines and run the test:
For i=1 to 5
var1=RandomNumber (0, 100)
msgbox(var1)
Next
Third example of Random Numbers: (This is more or less same as the first one)
One more way is to define a Random Number parameter in the 'Parameter Options' or 'Value
Configuration Options' dialog box.
1. Open a new test.
2. In the keyword View right-click on Action1, select 'Action Properties', 'Action Properties'
window opens, Go to 'Parameters' Tab.
3. In the 'Input Parameters' area click on the '+' sign and enter the Name of the input parameter as
'a', Type as Number, and Default value as 1. Click Ok.
4. Again right-click on Action1 in the keyword View , select 'Action Call Properties', 'Action
Call Properties' window opens. Go to 'Parameter Values' Tab.
5. Make a single click under 'Value' column in the 'Input Parameter's' area, it will become a
button '<#>'. Click on this button.
6. It will open 'Value Configuration Options' window.
7. Click on 'Parameter' radio button, select 'Random Number' from the dropdown. In the
Numeric Range enter 0 against From and 100 against To.
8. Click on 'Name' Checkbox and choose arg_a from the dropdown.
9. In the 'Generate New Random Number' area, select first option-For each action iteration.
Click ok.
10. Again Click ok to come out of 'Action Call Properties' window.
11. Now in the Expert View of action1 type:
x=RandomNumber("arg_a")
msgbox(x)
12. And Run the Test.
Fourth example of Random Numbers:
Another VBScript method of generating a random number:
For i= 1 to 3
var1 = int((101*rnd)+0) ' Generate random value between 0 and 100.
MsgBox var1
next
likewise
Int((6 * Rnd) + 1) ' Generate random value between 1 and 6.
The Rnd function returns a value less than 1 but greater than or equal to 0.
Rnd(number)If the number is Less than zero (< 0) then Rnd generates 'The same number' every
time, using number as the seed.
For i= 1 to 3
x=rnd(-1)
msgbox(x)
Next
If the number is Greater than zero(> 0) then Rnd generates 'The next random' number in the
sequence.
For i= 1 to 3
x=rnd(1)
msgbox(x)
Next
If the number is Equal to zero (=0)then Rnd generates 'The most recently generated' number.
For i= 1 to 3
x=rnd(0)
msgbox(x)
Next
If the number is Not supplied then Rnd generates 'The next random number in the sequence.'
For i= 1 to 3
x=rnd()
msgbox(x)
Next
Remember:
For any given initial seed, the same number sequence is generated because each successive call
to the Rnd function uses the previous number as a seed for the next number in the sequence.
Before calling Rnd, use the Randomize statement without an argument to initialize the random-
number generator with a seed based on the system timer.
qtp.blogspot.com
Bottom of Form
Alternatively, you can enter the parameter name in the Expert View using the Parameter utility
object, in the format: Parameter ("ParameterName").
qtp.blogspot.com
Bottom of Form
qtp.blogspot.com
Bottom of Form
9. In the Global Data sheet it will add a new columns with 'mary' as its first value.
10. Go to Insert (menu) -> Call to New Action to insert action2.
11. For this action2, repeat steps from 2 to 7. (This time I have used the Agent Name as 'bill')
12. After repeating step 7, when you click on 'Parameter' radio button and select Data Table from
the dropdown, make sure you select Current action sheet (local) in the Location in Data Table
area. Click Ok to close that window.
13. It will add a new column in action2 Data Sheet with 'bill ' (because I used bill as an Agent
Name ) as its first row.
14. Now you have two actions (action1 and action2), both of them do the same job but their data
is in different sheets.
15. Go to Global Data Sheet and Add one more row in it below 'mary'. I added 'rama'.
16. In the Local Data Sheet (action2) add two more rows to make them a total of 3. I added
'amar' and 'Sumit'.
17. Right click on action1 and select action call properties, go to Run Tab and select "Run on all
rows" radio button. Do the same for action2.
18. Go to Expert View of action one and type : msgbox("acton1"). Now my action1 looks like
this:
Example 2
This examples shows that each action can access data not only from Global Data Sheet or its
own Local Data Sheet but also from other action's Data Sheet in the same test.
Open a new test.
Insert two actions.
In the Global Data table, in cell(A,1) type 'Global Data'.
In the Action1 Data table, in cell(A,1) type 'Action1 Data'.
In the Action2 Data table, in cell(A,1) type 'Action2 Data'.
In Expert View of action1 type:
msgbox("I am in action 1")
rc = DataTable.Value("A", dtGlobalSheet) 'accessing data from Global data sheet from action1
msgbox rc
rc = DataTable.Value("A", 2) 'accessing data from action1 data sheet from action1
msgbox rc
qtp.blogspot.com
Bottom of Form
Just make that Insert Order button enable by putting some values in Flight Reservation window
and then see that column (Insert_Order_enabled_Out ) in Data table. It will show a true value in
there at run time. It will also show that captured value in the Results window.
These above steps show you how to use output values with Data Table. Below tutorial shows
how to use output values with Environment variables.
1. Open a new test and also open a sample Flight application (Flight Reservation
window)
2. Make sure that both (new test and Flight Reservation window) are open and visible.
3. Click on Record in order to record a test.
4. Go to Insert (Menu)->Output Value->Standard Output Value.
5. QTP will be minimized and mouse pointer will take the shape of a hand. Click on
'Insert Order' button in Flight Reservation window.
6. "Object Selection - Output Value Properties" window opens with WinButton : Insert
Order highlighted. Click Ok.
7. "Output Value Properties" window opens with 'Insert Order' in the Name text field.
8. Click on first checkbox (which is Property enabled and Value False).
9. In the Configure Value area click on Modify button.
10. Output Options window opens.
11. In 'Output Options' window, from 'Output Types' dropdown, select Environment, and
click Ok.
12. Now Insert_Order_enabled_out will be User-Defined internal environment variable.
13. Click Ok to come out of this "Output Value Properties" window. (You can check that
environment variable by going to File->Settings, Environment Tab and choosing User-
Defined from variable type)
14. Just add the below line in the Expert View at the end to see the value of the
environment variable.
msgbox(environment("Insert_Order_enabled_out"))
15. Now you can Run the test.
Just make that Insert Order button enable by putting some values in Flight Reservation
window and then see that environment variable value (Insert_Order_enabled_Out ). It
will show a true value in there at run time. It will also show that captured value in the
Results window.
qtp.blogspot.com
Bottom of Form
Parameterize a Checkpoint
You can create a Checkpoint while recording or editing a test. For this tutorial I will take into
account Text Checkpoint created through Standard Checkpoint while editing.
Open a new test.
Click on Record.
Go to Start-> All Programs->QuickTest Professional->Sample Applications->Flight.
Enter the Agent Name as "Sachin" and Password as "mercury". Make sure you use Tab key to
move from one text box to another and hit Return (Enter) key after entering the Password.
When the Flight Reservation window is open Go to File (menu)->Exit.
Click on Stop in order to stop the recording.
In the Keyword view go to the row which has "Sachin" under Value column. Right-click
anywhere on that row and choose "Insert Standard Checkpoint."
"Checkpoint Properties" window opens. Make sure only the Text property is checked which has
a value of "Sachin" and rest all of the properties must be unchecked.
Just make a single click on Text Property, which you checked above, in order to highlight it and
make "Configure Value" area enabled.
In this area click on Parameter Radio button. This is all we need to do.
[On the right hand side of Parameter Radio button you will see Parameter Options button (which
has paper and pen image on it). you can click on it to see the default values QTP has set for us.]
In the "Checkpoint Properties" window just click on Ok to come out of it.
It will add a column in the Global Data Sheet with "Sachin" as its first value.
Add two more values in the subsequent rows. I added "aaaa" in the 2nd and "bbbb" in the 3rd.
Now when we run the test and it opens the window where we need to enter the Agent Name and
Password, you have to enter Agent Name all of the 3 times (Just enter the Agent Name, that's it,
no Tab key or Return key). Make sure you enter "Sachin" during first time, "aaaa" during second
time and so on. We don't need to enter the Password. Remember this is a Text Checkpoint on the
"Agent Name" Text field. Any value entered there first time will be compared by first row of the
Global Data Sheet which has "Sachin" and any value entered there Second time will be
compared by second row of the Global Data Sheet which has "aaaa" and so on. Just try to enter
some other value during second time like "xxxx" it will run the test but show you "Failed" in the
Results window in the second iteration.
qtp.blogspot.com
Bottom of Form
Bottom of Form
qtp.blogspot.com
Bottom of Form
qtp.blogspot.com
Bottom of Form
qtp.blogspot.com
Bottom of Form
qtp.blogspot.com
To Run this test, always go to Action4 and then, Automation (Menu) ->Run
Current Action
What these Actions will do:
Action4 will call Action1 with two input values 2, 2.
Action1 sums those values (2+2=4) and assigns the sum to out_a1_1 (Action1’s output
parameter).
Then Action1 passes the sum (i.e. 4) along with another number (3) to Action2 by calling
Action2 in its last line.
Action2 multiplies those two values (4, 3) it got from Action1 and passes on the result of
multiplication (12) and another number (5) to Action3, where these passed on values are added
and the result is shown in a message box.
Bottom of Form
AutoComplete
File Download
Internet Explorer
Netscape
Enter Network Password
Error
Security Alert
Security Information
Security Warning
Username and Password Required
1. To COMPLETE a Run session an optional step is not necessarily required.
2.If a Step in an optional dialog box does not open, QTP avoids that step and continues ahead
during a Run session. At the end of the Run session, a message is displayed for the step that
failed to open the dialog box. Here remember that the step does not cause the Run to fail.
3. However if QTP does not find an Object from the optional step in the Object Repository, then
the Run fails with an error message.
You can also add an optional step in the Expert View by adding OptionalStep to the beginning of
the VBScript statement. For example:
OptionalStep.Browser("Browser").Dialog("AutoComplete").WinButton("Cancel").Click
This is an Optional step icon
A simple example for Optional Step:
1. Make sure that a new blank test and a blank Internet Explorer window is open.
4. Enter Username.
5. Enter Password.
6. Hit the enter key.
8. Close the Internet explorer window also from the Cross button which is on the extreme top
right..
9. Click Stop to stop the test recording.
In the Keyword view, follow the below steps:
Now before you run the test make sure Internet Explorer window is NOT open.
The idea is when you run the above test without IE, it will not show any error message or fail, it
will just bypass the ‘browser closing’ step as we have marked it Optional and it will ignore any
error for the optional step. But it shows you the warning in the test results.
Try to run the same test by just removing the ‘Optional Step’ tag from the above lines and see
that it will fail and show you the Run Error.
qtp.blogspot.com
Bottom of Form
1.
I created a test in QTP with the name "twra". (E.g. for better understanding “test with reusable
action"). It has just one line of code:
In the Keyword View, right click on Action1 and choose Action Properties. In the Action
Properties dialog box that opens, check the ‘Reusable action’ checkbox in the General tab and
click OK.
2.
I created another test in QTP with the name "call twra". At present it also has just one line of
code:
Now without doing anything on Select Action window, just close (Cancel) it.
4.
Now go to Tools -> Options and go to Folders tab. Click on + to add a Path. The paths that you
specify here can be a full path or a relative path. The relative path is relative to the location of the
test currently being edited.
5.
Now again go to Insert ->Call to Existing Action. Select Action window opens.
Now in the “From test:” dropdown just type the name of the test from where you want to call a
reusable action (twra in our case) and it will list all of its reusable actions.
[If you enter any path (e.g. path for Function Library or path for Object Repository etc.) as
relative path, then during the run session, QuickTest searches for the file in the folders listed in
the Folders pane of the Options dialog box, in the order in which the folders are listed.]
We can also do the above steps like this: (Suppose “call twra” test is open)
Above in the 3rd step when Select Action window opens, since both “twra” and “Call twra” are
stored under Tests, we can simply write ..\twra in the “From test:” dropdown (No need of step 4
and 5 above) in order to access its reusable actions.
This is because both the tests are located in C:\Program Files\Mercury Interactive\QuickTest
Professional\Tests and we are currently in C:\Program Files\Mercury Interactive\QuickTest
Professional\Tests\call twra. Path of current test (<current test>) is always there in search list
(Tools -> Options -> Folders tab),
and our current path is C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\call
twra, so to find twra which is under C:\Program Files\Mercury Interactive\QuickTest
Professional\Tests\ we go one step back with ..\ and type twra. So in all we type ..\twra and it
will find it.
PathFinder.Locate
You can use a PathFinder.Locate statement in your test to retrieve the complete path that
QuickTest will use for a specified relative path based on the folders specified in the Folders tab.
Locate is a method of PathFinder object which returns the full file path that QuickTest uses for
the specified relative path based on the folders specified in the Folders tab search list (Tools ->
Options -> Folders tab).
Additionally you can add the below line in the "call twra" test to know which relative path it
picked from the search list (Tools -> Options -> Folders tab).
Msgbox (PathFinder.Locate ("twra"))
See how much you have learned about QTP Relative & Absolute Path by answering these
Multiple Choice Questions .
Script on How to add any path in the Search List '(Tools -> Options -> Folders tab) through a
script.
qtp.blogspot.com
Bottom of Form
msgbox(parameter("a"))
13. Go to Expert View of Action2 and type:
For i=1 to 3
RunAction "Action1", oneIteration, RandomNumber("arg_a")
Next
14. When you copy the above text to Expert View of Action2, it will show you a message that it
has made Action1 Reusable, just click ok.
15. Now Run the test.
(It would be better if you run it by activating the expert view, then it will show you which step it
is currently running by pointing to that particular step with yellow color arrow and then you will
be able to understand it in a better way. You will see that it shows a different value in each
msgbox() because we selected 'For each action iteration' from the 'Generate new random number'
area. If we select the second option 'For each test iteration' then a message
box will show same values, but different values if you run it next time i.e. a different value at
each test run.)
RandomNumber is an Object.
RandomNumber(ParameterNameOrStartNumber [,EndNumber])
EndNumber is optional above.
Second example of Random Numbers:
Here is another way of generating random numbers:
Open a new test and in the Expert view write these lines and run the test:
For i=1 to 5
var1=RandomNumber (0, 100)
msgbox(var1)
Next
Third example of Random Numbers: (This is more or less same as the first one)
One more way is to define a Random Number parameter in the 'Parameter Options' or 'Value
Configuration Options' dialog box.
1. Open a new test.
2. In the keyword View right-click on Action1, select 'Action Properties', 'Action Properties'
window opens, Go to 'Parameters' Tab.
3. In the 'Input Parameters' area click on the '+' sign and enter the Name of the input parameter as
'a', Type as Number, and Default value as 1. Click Ok.
4. Again right-click on Action1 in the keyword View , select 'Action Call Properties', 'Action
Call Properties' window opens. Go to 'Parameter Values' Tab.
5. Make a single click under 'Value' column in the 'Input Parameter's' area, it will become a
button '<#>'. Click on this button.
6. It will open 'Value Configuration Options' window.
7. Click on 'Parameter' radio button, select 'Random Number' from the dropdown. In the
Numeric Range enter 0 against From and 100 against To.
8. Click on 'Name' Checkbox and choose arg_a from the dropdown.
9. In the 'Generate New Random Number' area, select first option-For each action iteration.
Click ok.
10. Again Click ok to come out of 'Action Call Properties' window.
11. Now in the Expert View of action1 type:
x=RandomNumber("arg_a")
msgbox(x)
12. And Run the Test.
Fourth example of Random Numbers:
Another VBScript method of generating a random number:
For i= 1 to 3
var1 = int((101*rnd)+0) ' Generate random value between 0 and 100.
MsgBox var1
next
likewise
Int((6 * Rnd) + 1) ' Generate random value between 1 and 6.
The Rnd function returns a value less than 1 but greater than or equal to 0.
Rnd(number)If the number is Less than zero (< 0) then Rnd generates 'The same number' every
time, using number as the seed.
For i= 1 to 3
x=rnd(-1)
msgbox(x)
Next
If the number is Greater than zero(> 0) then Rnd generates 'The next random' number in the
sequence.
For i= 1 to 3
x=rnd(1)
msgbox(x)
Next
If the number is Equal to zero (=0)then Rnd generates 'The most recently generated' number.
For i= 1 to 3
x=rnd(0)
msgbox(x)
Next
If the number is Not supplied then Rnd generates 'The next random number in the sequence.'
For i= 1 to 3
x=rnd()
msgbox(x)
Next
Remember:
For any given initial seed, the same number sequence is generated because each successive call
to the Rnd function uses the previous number as a seed for the next number in the sequence.
Before calling Rnd, use the Randomize statement without an argument to initialize the random-
number generator with a seed based on the system timer.
Type the below text in a new test in QTP and run it.
pwd = "sachin"
e_pwd = Crypt.Encrypt(pwd)
msgbox e_pwd
Type the below text in a new test in QTP and run it. You can also write the function
(Crypt_Pass) in library and call it from a QTP test.
pas = "Sachin"
MsgBox Crypt_Pass(pas)
Function Crypt_Pass(epas)
Crypt_Pass = Crypt.Encrypt(epas)
End Function
Use Encrypt outside of QTP in VBScript. Write the below 3 lines in a notepad and save it with
.vbs extension and run it from command prompt. For example I saved it as "a.vbs" under c:\ and
ran it from command prompt by typing just "a" and pressing enter.
Set a=CreateObject("Mercury.Encrypter")
Msgbox a.encrypt ("Sachin")
Set a=Nothing
Source
There is one trick by which you can know the encrypted password. For example type the below
lines in a new test in QTP and run them. I am entering the encrypted password (in e_pwd) in
"Agent Name" field of the Login dialog box which shows up when you open the Flight
Application. Entering the encrypted text in a non-secured edit box lets you know the original
text.
pwd = "sachin"
e_pwd = Crypt.Encrypt(pwd)
Source
qtp.blogspot.com
Bottom of Form
Function Library
Function Libraries in QTP
If you have repeatable steps in a test or an action then consider using a user-defined function.
User-defined functions will make your tests look shorter, easier to maintain, read and design. A
user-defined function can then be called from within an action.
1. Time and resources can be saved by implementing and using user-defined reusable functions.
2. User-defined functions can be stored in a function library or within an action in the test.
3. User-defined functions can be registered as a method for a QTP test object.
[It is advisable not to give user-defined functions same name as built-in functions (refer to the
Built-in functions list in the Step Generator (Insert > Step Generator, in theStep Generator
dialog box choose Built-in functions from Library Combo box, it will show all of the Built-in
functions in Operation Combo box))]
If the function is stored in a function library then we have to associate that function library to a
test so that the test can call all the public functions listed in that library.
Functions in an associated function library are accessible:
a) From Step Generator (for tests and function libraries),
b) From the Operation column in the Keyword View, or
c) Can be entered manually in the Expert View.
Functions directly stored in an action in a test can be called from within that action only making
them private from the outside world.
A Private function can also be created in a function library and this private function can only be
called from within the function library itself in which it is defined.
Functions can be created manually or by using Function Definition Generator.
It is easy to create a function library:
1. Open a new function library (File->New->Function library).
2. Add content to it (your function). Associate it with a test (File-> Associate Library with Test).
3. You are ready to go.
Many different function libraries can be opened simultaneously as each opens in its own separate
window and you can work on them separately.
If a test is open you can view all the function libraries associated with it. (Resources->Associated
Function Libraries.)
You can save function library either from File->Save or right click on function library tab on the
top of function library and choose save.
qtp.blogspot.com
Bottom of Form
Bottom of Form
Another example which uses both public and private functions in the function library.
1. Open a new function library. Go to File->New->Function library.
2. Open a new test. Go to File->New->Test.
3. Write the below two functions in the function library. One of the functions is private i.e. it can
be accessed from within the function library itself and cannot be accessed from outside of this
function library. One of the functions is public which we will access from the test.
Private Function my_name_tell(name2)
msgbox "Hello " & name2
End
Function
Public Function my_name(name1)
msgbox(name1)
my_name_tell(name1)
End Function
4. Save the function library.
5. Associate the function library with the test which is open.
In the expert view of the test type:
my_name("sachin")
7. When you run it, it will show two message boxes, one from the public function and second
from the private function.
qtp.blogspot.com
Bottom of Form
Once it is saved, go to File->'Associate Library with Test' to associate this function library with
the already open test.
After it is associated go the ‘Expert View’ of the test already open and type:
Window("title:=Filght Reservation").WinEdit("Attached text:=Name:", "height:=20").
as soon as you press . (dot), the list of operations which WinEdit supports are displayed by
default (also called IntelliSense), just select New_operation_1 from there.
After selecting New_operation_1 just supply one argument to it because while creating the
function we provided one argument called var1. So the final line of code in the Expert View now
looks like:
Window("title:=Filght Reservation").WinEdit("Attached text:=Name:",
"height:=20").New_operation_1"merry"
[You can open Flight Reservation window for this test, but it is not necessary]
Just Run the test. It does nothing for the WinEdit object or anything special. It just displays a
message box with the value which we have supplied to it at the time of writing the code. This is
just a simple example to show how it works.
If in this same test you go to ‘Keyword View’, it will show you New_operation_1 under the
Operation column. It is displayed as an operation in the Keyword View Operation list when
that test object is selected from the Item list. But here we are not using any Object repository
(we are using Descriptive Programming) so we cannot select any object from the Item list as the
Object Repository is empty. But if we do the below steps it surely will show:
We will record a simple step in a new action.
Now insert another new action in this test. (Insert->Call to New Action)
Make sure ‘Flight Reservation’ window is open.
Click on Record.
In the ‘Flight Reservation’ window, in the Name text box enter any name.
Stop recording.
Now go to the ‘Keyword View’. In this ‘Keyword View’, go to the row which has 'Name' under
item. Make a single click under Operation column in that row (click where it shows Set) it will
show a dropdown and you will be able to see New_operation_1 in that dropdown. This
New_operation_1 will be there for every object of class WinEdit.
Now if you open any new test and again type
Window("title:=Filght Reservation").WinEdit("Attached text:=Name:", "height:=20").
Now QTP will not display New_operation_1unless otherwise you associate the library we
created earlier to this new test.
qtp.blogspot.com
Bottom of Form
Below is an example that creates a new copy method for winedit object which copies the data
from the text field to clipboard and then shows that data (which is copied to the clipboard) in a
message box. In a new library file type:
Sub Copy (edit)
Edit.Click
Edit.SetSelection 0, Len(Edit.GetROProperty("text"))
Edit.Type micCtrlDwn + "c" + micCtrlUp
End Sub
RegisterUserFunc "WinEdit", "Copy","Copy"
Open a new test and type:
Dialog("text:=Login").winedit("attached text:=Agent Name:").Copy
Set objhtml=Createobject("htmlfile")
a=objhtml.parentwindow.clipboarddata.getdata("text")
msgbox a
unRegisterUserFunc "WinEdit", "Copy"
Associate the library with the test as we did earlier. Make sure 'Login' window is open (Start->
All Programs -> QuickTest Professional -> Sample Applications ->Flight). In this login window
type "sachin" in the Agent Name text field and run the test.
qtp.blogspot.com
Bottom of Form
ExecuteFile
ExecuteFile
There are two ways (usually) to associate the library file to a test.
1. Resources pane of Test Settings (File->Settings) dialog (has advantages like files are in global
scope –all the actions in a test can use those, can be debugged).
2. ExecuteFile (Local scope - When you run an ExecuteFile statement within an action, you can
call the functions in the file only from the current action, and you cannot debug a file that is
called using an ExecuteFile statement).
We will start with a very simple example and go on to elaborate more on ExecuteFile.
Create a new .vbs script as shown below. I saved it under c:\ as add.vbs.
Now open a new test in QTP and write few lines as below and run the test. It will show the value
of a as 5 in message box.
Above we are using ExecuteFile function to include the add.vbs file we created earlier. After
including that file we are calling the function from that file and showing its return value in a
message box.
When you run your test, the ExecuteFile statement executes all global code in the function
library making all definitions in the file available from the global scope of the action's script.
ExecuteFile File
Where File is a string - the absolute or relative path of the file to execute.
When you run an ExecuteFile statement within an action, you can call the functions in the file
only from the current action.
To make the functions in a VBScript file available to your entire test, add the file name to the
associated function libraries list in the Resources pane of the Test Settings dialog box.
In addition to the functions available in the associated function libraries, you can also call a
function contained in any function library (or VBscript file) directly from any action using the
ExecuteFile function.
You can also insert ExecuteFile statements within an associated function library.
You cannot debug a file that is called using an ExecuteFile statement, or any of the functions
contained in the file. In addition, when debugging a test that contains an ExecuteFile statement,
the execution marker may not be correctly displayed.
Now my add.vbs and QTP test are like as shown below, i.e. one more variable z is added. Now
what do you think it will show (for z) when the test is run.
On running this QTP test it will show 7 for msgbox z.
And guess what will it show now for the msgbox z if the add.vbs and QTP test are as below:
qtp.blogspot.com
Bottom of Form
QTP GetTOProperty, GetROProperty, GetTOProperties
GetTOProperties
Returns properties and values which QTP has recorded and will use to identify an object at run
time.
GetROProperty
It will Return the current value (run time value) of the test object property from the object in the
application.
GetROProperty retrieves the current property value of the object in the application during the
test run.
GetTOProperty
It will Return the value of a particular property for a test object which QTP recorded to identify
an object during Run time. The value is taken from the Object Repository.
GetTOProperty retrieves the values of only those properties that are included in the test object
description in Object Repository by QTP.
We did all the above steps just to enable the radio buttons in the Class area.
From the above script which QTP recorded in Expert View, delete all the lines, except one,
which sets the Business radio button as shown below.
Window("Flight Reservation").WinRadioButton("Business").Set
Go to Resources (menu)->Object Repository. Object Repository window opens.
Click on Business radio button as shown below
It will show all the properties which QTP recorded for Business radio button.
Now to view all these properties through a script (and use them later somewhere)use
GetTOProperties as below:
GetTOProperties
Convert the remaining one line in the Expert view like this below and add a For Loop.
set a=Window("Flight Reservation").WinRadioButton("Business").GetTOProperties
count_of_prop = a.Count
For i = 0 To count_of_prop - 1
Prop_Name = a(i).Name
Prop_Value = a(i).Value
MsgBox Prop_Name & " = " & Prop_Value
Next
This above code which uses GetTOProperties shows all the properties of Business radio button
which QTP recorded in order to identify it.
For GetROProperty & GetTOProperty you have to specify the property whose value you want to
retrieve.
In the same test delete or comment all of the above code (GetTOProperties) and write the below
code for GetROProperty and run the test.
GetROProperty
a=Window("Flight Reservation").WinRadioButton("Business").GetROProperty("checked")
msgbox a
Select Economy radio button and then run the above code again to see a different value.
Again in the same test delete or comment all of the above code (GetROProperty) and write the
below code for GetTOProperty and run the test.
GetTOProperty
You can view the value for only those properties which QTP recorded for a particular object.
a=Window("Flight Reservation").WinRadioButton("Business").GetTOProperty("nativeclass")
msgbox a
a=Window("Flight Reservation").WinRadioButton("Business").GetTOProperty("text")
msgbox a
qtp.blogspot.com
Bottom of Form
QTP SetTOProperty
QTP SetTOProperty
The SetTOProperty method enables you to modify a property value that QuickTest uses to
identify an object.
Because QuickTest refers to the temporary version of the test object during the run session, any
changes you make using the SetTOProperty method apply only during the course of the run
session, and do not affect the values stored in the test object repository.
The Object Repository window is read-only during record and run sessions.
Example 1 of SetTOProperty
I opened a new test in QTP and opened Calculator (Start -> All Programs -> Accessories-
>Calculator). I started Recording in QTP.
I clicked on button (7), then button (+), then button (3) and finally button (=). Finally I closed the
Calculator. It recorded the first six lines of the script as seen below. I added the following lines
afterward.
Object Repository shows that the text property of button named "7" has a value of 7.
'QuickTest refers to the temporary version of the test object during the run session.
Window("Calculator").Activate
Window("Calculator").WinButton("7").Click
Window("Calculator").WinButton("+").Click
Window("Calculator").WinButton("3").Click
Window("Calculator").WinButton("=").Click
Window("Calculator").Close
below statement retrieves a value of the text property of a button named "7" using
GetTOProperty from memory.
x=Window("Calculator").WinButton("7").GetTOProperty("text")
msgbox x
the following statement would set the button's (named "7") text property value to seven
(remember temporarily)
Window("Calculator").WinButton("7").SetTOProperty "text", "seven"
below statement retrieves a value of the text property of a button named "7" using
GetTOProperty from memory.
x=Window("Calculator").WinButton("7").GetTOProperty("text")
msgbox x
After running the above statements the Object Repository will still be the same as it was before
running the above statements. (See screenshot above)
Example 2 of SetTOProperty
Write the below text in the Notepad and save it as .html file. I saved it as a.html
When you open the file in IE it will look like as shown below:
Make sure that this above file (a.html) is open in IE and QTP is open.
Click on Record.
Browser("Browser").Page("Page").Link("Link 1").Click
So for this test, Object Repository contains information only for Link 1 as can be seen below:
And now if we run this test it will click only Link 1. [Object Repository does not contain
information on Link 2]
Now if you write the below line in this test, removing the above line (which clicks link 1) and
run, it will show error:
Browser("Browser").Page("Page").Link("Link 2").Click
But if you use SetTOProperty as below, it will click on Link 2 although Link 2 is not in Object
Repository.
Browser("Browser").Page("Page").Link("Link 1").Click
Browser("Browser").Back
Browser("Browser").Page("Page").Link("Link 1").SetTOProperty "text", "Link 2"
Browser("Browser").Page("Page").Link("Link 1").Click
qtp.blogspot.com
Bottom of Form
qtp.blogspot.com
Bottom of Form
<title>Hello World1</title>
2.
Open another new blank notepad and type
<title>Hello World2</title>
3.
Open a new blank test in QTP and type the following code:
4.
Also enter World1 and World2 in Cell A1 and A2 in Global Sheet.
5.
Double click on First.html and Second.html in order to open them in Internet Explorer.
6.
Make sure that both First and Second are visible and run the test.
Running the test will close both the browsers.
Above is a very small example that shows how we can data-drive a property value since the
browsers have opentitle property values as “Hello World1” and “Hello World2” respectively. So
we have used data table in this example to parameterize the values.
qtp.blogspot.com
Bottom of Form
qtp.blogspot.com
Bottom of Form
Smart Identification works with the help of Object Repository. In case of Descriptive
Programming we bypass the Object Repository. So the Smart Identification mechanism is not
used with Descriptive Programming or Programmatic Description.
Regular expressions can be used with descriptive programming. Let us take a small example.
This below example clicks on File ->Open, menu of either a new blank Notepad or WordPad
which ever is open. You can write the below example in a new test in QTP and make sure either
a new Notepad or a WordPad window is open and run the test. It uses regular expression in the
second line where value of regexpwndtitle in case of Notepad is Notepad and in case of
WordPad is WordPad. So I have used regular expression for this where first four dots (.)
correspond to any four characters and after these four characters there can be capital or lower
case p and then ad.
Or
Set myobj = Description.Create()
myobj("regexpwndtitle").Value = "....[Pp]ad"
In this above code there can be issues if there is no proper spacing between File;Open… and
Ctrl+O
<title>Welcome A*</title>And save it with .html extension as I saved it as sac.html under c:\
After it is saved just double click it to open it with Internet Explorer.
Make sure that “Welcome A*” Internet Explorer window is open. Run the test.
It will show an error.
Now rewrite the above line with a backslash “\” in front of *
No it is not possible to use descriptive programming with the checkpoint object as in the below
line of code:
Browser("Browser").Page("Page").check checkPoint("text:=sometext")