Sie sind auf Seite 1von 16

QTP 9.

5 Tutorials For
Beginners
||| | 

||| | 

 

Je will test with the mercury sample application FLIGHT.QTP script consists of things like actions,
functions etc. In QTP 9 we can place 120 actions in a script, this is a limit.Je will begin with a simple test
like the "hello world" program with which we start learning any programming language.
1) First of all click on Record toolbar button ( or Automation menu --> Record or press F3). when we click
on Record, "Record and Run Settings" window opens up. Go to "Jindows Applications" tab and choose
first option "Record and run test on any open windows based application." and click on ok.
2) Open Flight application (Start -->All programs -->QuickTest Professional --> Sample Applications -->
Flight)
3) Type Agent name as "Kumar" (You can enter any, but must be 4 characters or more) and enter
password as "mercury".
4) In the flight reservation window that opens up:a) In the Flight Schedule area, in Date of Flight enter
tomorrow's date in mm/dd/yyyy format.( I used tabs to move to next fields)b)In Fly From enter Denverc)In
Fly To enter Londond) Click on Flights button which is on the right hand side of "Fly To".Let the default
option be selected in the Flights Table.e) Click okf)In the name field enter your name. It will fill rest of the
required information by itself.g) Click on insert order and after the order is insertedh) Click on File --> exit.
5) Now you have recorded your first script. You can click on the expert view tab to see the script which
QTP has recorded for you automatically.
6) Click on run from Automation Menu (or press F5) to open up run dialog box.
7) Go to the "Results Location" tab, and below "write run results to", in "new run results folder" radio
button- let it be the default option --C:Program FilesMercury InteractiveQuickTest
ProfessionalTestsTest1Res1(you can also change it)
8) click on ok.This will run you earlier recorded test and show you the results.But we have to go a long
way. This is just the beginning. ||| | 

 


 In our next example we will use data table:


There are two types of data tables Design time and Run time:
Design time data table is what you see in the main QTP window and run time data table you can see only in
the test results window. Design time data table is always created before running the test while run time data
table is generated after execution of the test.
1) Open new test (Ctrl+N)
2) Je will click on record toolbar button ( or Automation menu --> record or press F3). when we click on
record, "Record and Run Settings" window opens up. Go to "Jindows Applications" tab and choose first
option "Record and run test on any open windows based application." and click on ok.
3) Open Flight application (Start-->All programs-->QuickTest Professional->Sample Applications-->Flight)
4) Type Agent name as "Kumar" (you can enter any, but must be 4 characters or more) and enter password
as "mercury".
5) In the flight reservation window that opens up:
6) Click on File-->exit. Click Stop to stop the recording.
7) In the keyword view you will see four headings- Item, Operation, Value, Documentation. Under Value click
on Kumar and on the right hand side of Kumar you will see a small icon, just click on that (or press ctrl +
F11), The "Value Configuration Options" dialog box opens. In that dialog box click on parameter radio
button and select Data Table from there. In Name field enter any variable name (I entered 'username'). Let all
other be the default options in this dialog box and click on ok.
8) QTP will add username column in the data table (bottom, left hand side) with 'Kumar' as the first value.
9) Now enter more values in the username column, manually. I entered 'Sachin' and 'Sunil' in 2nd and 3rd
column respectively.
10) Save the test. (File-->Save).
11) Now run the test. (follow same steps as we did earlier).
12) If the test ran successfully, in the Results summary window on the left hand side you will see three
iterations (because we added 3 variables in the 3 rows of a data table). Expand 1st iteration, it will show
action summary for that iteration, expand the action summary, it will show Login, Expand the login. Click on
the first option under it "Agent Name: SetText". On the right hand side it will show 1st variable name under
details.
13) Similarly you can look for 2nd and 3rd
||| | 

QTP Data Table Access with


QTP Script
 J |||    
  
   !| |  
"#  ||$$   
%
&'   J |   $( (
|| )(J|% ( 
( *||  (  
+,    |--
.'  
/# |* |   0
J|!(1( J2!(2( ' 3$3
J|!(1( J2!(2( *((
4J 
    0
 5  6!(%($) 


J|!(1( J2!(2( ' 3$3
J|!(1( J2!(2( *
7  
8  |  1 #|  

  1

||| | 

'  
Checkpoints cannot be added manually, they are inserted using QTP's interface. Results of the checkpoint
can be viewed in the Test Results Jindow.
Checkpoint information is stored in the Local Object Repository. It is in the Resource.mtr file which is in the
action folder (if you created checkpoint in action1 then it will be action 1 folder under the folder in which
you are saving the test/script, if you created checkpoint in action 2 then it will be action 2 folder and so on) .
In the expert view, on any blank line type Checkpoint and put "(". As soon as you put the starting bracket it
will show all the checkpoints you have used in the test.
Now we will start with checkpoints. I will try to show easy to understand example of each and every
checkpoint.
Lets start with simple example of standard checkpoint which checks a variety of objects such as buttons,
radio buttons, combo boxes etc. Standard checkpoints are supported for all add-in environments

 Open a blank test.


 Make sure that Flight application is open.
(Now only QTP with blank test and Flight application should be open).
 Click on Record. Jhen we click on Record, "Record and Run Settings" window opens up. Go to "Jindows
Applications" tab and choose first option "Record and run test on any open Jindows based application."
and click ok.
 Go to Insert (menu)->Checkpoint->Standard Checkpoint (or press F12).The mouse pointer will become hand
and QTP will be minimized.

 Click on the "Flights..." button which is on the Right Hand Side of the "Fly To" combo box in the Flight
application.

 It will open "Object Selection - Checkpoint Properties" window (with JinButton:FLIGHT highlighted). Click
ok.
 It will open checkpoint properties window. (only one property will be checked in it i.e. 'enabled' with a value
of False.)
 Click ok. Click on Stop in order to stop the Recording.

 Save the test.


||| | 

'  
 
|  |     
    1||  ||* |
    
To see a pass test result:
     
' 
#|  |* 
To see a Fail test result:
     
#     $*
*  
 !   | -  -
'  
#|  |*     | 
-  -|    
  
$|
  |
$

| *    


*

||| | 

QTP - Database Checkpoint

 Now we will try out Database checkpoint: using Oracle 9i



First of all you have to connect oracle 9i to QTP 9.(before doing any recording)


 For this go to Insert -> Checkpoint -> Database Checkpoint.

 A Database Query Jizard opens.


Select ' O O

 
  ' from the Query definition area. Click Next.
 Here click on 'Create' button which is on the right of "Connection String:" It will open 'Select Data Source' window.
Click on 'Machine Data Source' Tab
 Click on New Button.
 'Create New Data Source' window opens.
 Select 'Ë 
O' from Select a type of data source. Click Next.
 It will show all the data source drives it could find.
 Select Oracle (on my machine it was 'Oracle in OraHome9'). Click Next. Click Finish.
 It will open 'Oracle ODBC Driver Configuration' window.
 Enter 'Data Source name' ( I entered "oracle")
 Enter 'description' (I entered "SQL")
 Select 'TNS Service Name' ( I selected 'DB02', my oracle database name) from combo box.
 Enter userid (I used SCOTT).
 Click 'Test Connection' Button.It will ask for a Password. Enter your password for Oracle.
 If successful it will show 'Testing Connection' window with 'å 
 O ' written on it.

 This completes our task of Connecting QTP with Oracle.

||| | 

QTP - Database Checkpoint


 This completes our task of Connecting QTP with Oracle.

Now we will record a test.


 Open a blank test.

 Click on Record. Jhen we click on Record, "Record and Run Settings" window opens up. Go to "Jindows Applications" tab
and choose first option "Record and run test on any open Jindows based application." and click on ok.
 Go to Insert (menu)->Checkpoint->Database Checkpoint
 A 'Database Query Jizard' opens.

 Select ' Specify SQL statement manually' from the Query definition area. Click Next. Click Create.
 Go to 'Machine Data Source' Tab
 Select Oracle from data source name. Click Ok. It will open 'Oracle ODBC Driver Connect'

 Enter password. Click ok


 It will come to Database Query Jizard window with 'Connection String' field filled with:
"DSN=oracle;UID=SCOTT;PJD=TIGER;DBQ=DB02;DBA
=J;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;
LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;
MDI=F;CSR=F;FJC=F;PFC=10;TLO=0;"
In the SQL Statement area type "select * from emp;". Click Finish.

 It will open 'Database Checkpoint Properties' window with the result of the query. Click Ok.
 Click Stop in order to stop the Recording.

 In the Expert View, it just adds one line "DbTable("DbTable").Check CheckPoint "DbTable")"

||| | 

QTP - Database Checkpoint


  
  




'  !|-* ||  
9    : |*|  |:
   

J | || ||0

'  :

*!| '  : 


| |  #
 

: 
 '  :#!|% 

* 
'  ( (!| *   $| |  " !
* 
 
* #
*  
*| | 

,*   |  
  |   $|  
 

||| | 

QTP Page Checkpoint


Example
 Page checkpoint:It is for web applications only.Common things to check with this are load time, broken links etc.
Open a blank test.

 Make sure thathttp://www.google.co.in/ is open.(Now only QTP with blank test and www.google.co.in should be open.)
Click on Record. Jhen we click on Record, "Record and Run Settings" window opens up. Go to "Jeb" tab and choose first option
"Record and run test on any open browser." and click ok.
Go to Insert (menu)->Checkpoint->Standard Checkpoint (or press F12).
The mouse pointer will become hand and QTP will be minimized.
Click anywhere on the white space on the Google.co.in page.
It will Open "Object Selection - Checkpoint Properties" window. Click on 'Page : Google' option which has a page icon on left of it
with right corner of the page slightly folded.
Click ok.
A 'Page Checkpoint Properties' window opens up. Let all the options be default. Click ok.
Click on Stop in order to stop the Recording.
In the Expert view it will add just one line:
Browser("Google").Page("Google").Check CheckPoint("Google")
Je will explore this line later on.
I ran this test by opening www.google.co.in in offline mode (not on internet). It recorded the following properties:
Property Name Property Value
load time "0"
number of images "2"
number of links "20"
Here it shows the load time as 0 because I did not open Google at the time of running the test, it was already open.
Jhen you run it, in the results window, on left hand side, it will show (when every option is expanded):
Test Checkpoint-page Summary (where Checkpoint-page is the name with which I saved the test
Run-Time Data Table
Checkpoint-page Iteration 1 (Row 1)
Action1 Summary
Google (This will be the browser)
Google (This will be the Page)
Checkpoint "Google"
If you run this test on www.google.com it may fail.

||| | 

QTP - Bitmap Checkpoint

 QTP - 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


 Open a blank test.

 Click on Record. Jhen we click on Record, "Record and Run Settings" window
opens up. Go to "Jindows Applications" tab and choose first option "Record and
run test on any open windows based application." and click Ok.

 Go to Insert (menu)->Checkpoint->Bitmap Checkpoint

 Click on the "Fly To" combo box.


 "Object Selection- Bitmap Checkpoint Properties" window opens up. I will have "JinComboBox:Fly To"
highlighted. Click ok
 It will open "Bitmap Checkpoint Properties" window.

 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.

||| | 

QTP - Bitmap Checkpoint

 STYLE B

%$&$   (* ( 
$  
|  
*
  (*
('
| $   (  (

(9;  : <
'   (|| #| (J9; 0 
 (    ' 

#|(<
'   (||  
| (  (
; (* ( 
 

1|   ( % ( |  *  **
 , (*
( 
*

'  ('  
( 
 ||3   || |

|  

' 

'   

1|*  |   | $;  #* 
  *% ; * (* ( 
   # 
||  | *  '  (* 0($| |*  

 
    !0| | * 

||| | 

#
'  
Open a blank test.

Go to My Documents->My Pictures-> Sample Pictures and right click on image
named 'Sunset' and open it with internet explorer.

Now only a new blank test and internet explorer with this image should be open.

Click on Record. Jhen we click on Record, "Record and Run Settings" window opens up. Go to "Jeb" tab
and choose first option "Record and run test on any open browser." and click on Ok.

Go to Insert (menu)->Checkpoint->Standard Checkpoint(or press F12).The mouse pointer will become hand
and QTP will be minimized.

Click on the image which is opened in the explorer.

It will open 'Object Selection Checkpoint Properties' window with Image: Sunset highlighted. Click Ok.

It will Open 'Image Checkpoint Properties' Jindow. In this window just uncheck all the property values like
href, html tag etc and only check last property which is src.

Rest every thing will be default. Click OK.

Click stop to stop recording the test.

In the expert view it will just add one line
Browser("file:///C:/Documents%20and%20S").Page("file:///C:/Documents%20and%20S").Image("Sunset").Ch
eck CheckPoint("Sunset")

If you run it with that image open in internet explorer it will pass. This test is not intelligent enough. It is just
checking that the image in the explorer is in the same location in which it was when the test was recorded
and its name is Sunset. If you change the name of some other picture in that folder to Sunset and run the
test with that it will also pass.

In this way you can test for some or all the properties of the image which it showed in the 'Image
Checkpoint Properties' Jindow.
||| | 

 '  2


 QTP Text Checkpoint



1|||   '  0

 9 |

 '   J |   $( (|| )(J(
 ( *| (  

 )Insert (menu)->Checkpoint->Text Checkpoint. 


| 
  
|

= '   !|  | :u  
   |


 ( '   (|| #| |   ('  




*(  |  |  * 


  
 ' ': *  * $ $
|;   % 
 ( '   (|| -'  

-3  %'   
( '   (|| 
 '  
  | ; ||  ;
*  Checkpoint "Cannot find server" 9   |
 |*   * 

||| | 

#
 
For this tutorial make sure you completed the Database checkpoint tutorial successfully. Because the
connection we made in that tutorial with the oracle will be used here.

It is very simple to import data from database into Data Table.

Right-click somewhere inside the data table.

Go to Sheet->Import->From Database...
"Database Query Jizard" opens.

Click on the radio button "Specify SQL statement manually".
(make sure that "Maximum number of rows" checkbox is NOT checked)

Click Next

Click Create button.

"Select Data Source" window opens

Click "Machine Data Source" Tab

Select Oracle from there and click ok.

Enter password for oracle in the "Oracle ODBC Driver Connect window"

After entering password when you click on ok, it open "Database Query Jizard" window with 'Connection
string' automatically filled with info like DSN, UID etc.

Enter SQL statement "select * from emp;" in SQL statement Box.

Click Finish and lo the data is there in the data table.
||| | 

www.onsoftwaretest.com
 

 ||| | 

  6 


 )
 ||| | 

 )99<>2

||| | 

Das könnte Ihnen auch gefallen