Single Post

Header

Sunday, September 30, 2012

Small Examples in QTP




1.Record and Play Back in qtp (Login and Close)

SystemUtil.Run “C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe”,”",”C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\”,”open”
Dialog(“Login”).WinEdit(“Agent Name:”).Set “abcd”
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4c03551c45cb9c6ce024f12617d6e7f461936ba5″
Dialog(“Login”).WinButton(“OK”).Click
Window(“Flight Reservation”).Close

2. How to create excel file to store results for qtp

Set  xl= CreateObject(“Excel.application”)
xl.Visible = True
xl.Workbooks.add
a=15
b=20

If a>b  Then
xl.ActiveSheet.Cells(1,1).Value = a
Reporter.ReportEvent micDone,”a is bigger”, a
Else
xl.ActiveSheet.Cells(1,1).Value = b
Reporter.ReportEvent  micDone ,”b is bigger” , b
End If

3. How to store Store results in excel using qtp
‘ This is one of the method for importing excel in qtp

set xl=createobject(“excel.application”)
set wb=xl.workbooks.open(“D:\myexcel.xls”)
a=15
b=20

If a>b  Then
wb.ActiveSheet.Cells(1,1).Value = a
Reporter.ReportEvent micDone,”a is bigger”, a
Else
wb.ActiveSheet.Cells(1,1).Value = b
Reporter.ReportEvent  micDone ,”b is bigger” , b
End If

wb.save
wb.close

set wb=nothing
set xl=nothing

4.How to use global and Local Data Sheets in qtp

In Blank Test Case by default one action would be created.
Then write the below code in Action1–>Expert View

gd=DataTable(“Names_Global”, dtGlobalSheet)
ld=DataTable(“College”, dtLocalSheet)
msgbox gd&”_”&ld

Goto insert —>Call to new action and then it would create action2
Then write the below code in Action2–>Expert View

gd=DataTable(“Names_Global”,dtGlobalSheet)
ld=DataTable(“Number”,dtLocalSheet)
msgbox gd&”_”&ld

Put any data in Global ,Action1 and Action2 sheets and then execute.
In the above Names_Global,College and Number are the user defined coloumn names in the
corresponding sheets

1.If we do not give application path

object did not find error

2.For
textboxes---WinEdit
buttons-----Winbutton
menu--------Winmenu
dropdownlist---WinComboBox

3.What is logical name

it is a unique name under which specific physical description of a respective object to store


Questions and Answers for Actions in QTP





1.What is an action in    QTP

Ans:

Action is nothing but a specific task under one test

(Ex: Login is one action and Payment is another action)

(We can make them both in one action but it would be better if they are different)

2.How to call an action in QTP

Ans.

RunAction “Action2[Action Name]“,oneIteration, parameters

3.What is reusable action in QTP

Ans.

To call an action from other tests we must make it as reusable so that scope becomes global and can be called from any test.

A reusable action can be called and executed but not editable in the current test.

4.How many types of actions are there in QTP

Ans.

i)Non-Reusable Action :an action that can be called only in the test with which it is stored, and can be called only once.

ii)Reusable Action : an action that can be called multiple times by the test with which it is stored (the local test) as well as by other tests.

iii)External Action : a reusable action stored within another test.

External actions are read-only in the calling test.

The below are not types of actions.

Internal Action : an action which is created locally under one test . Eventhough if it is reusable action , it would be internal action

Independent Action : an action which is not dependent on any other action

Dependant Action :an action which is depend on other action(s)

Examples for actions in qtp

1. How to create actions while recording in qtp

Create Blank TestCase. Goto –>Record .Open ur Flight Reservation application

Do the record for login (Enter Agent Name and Mercury Password).Then the script would be

SystemUtil.Run “C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe”,”",”C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\”,”open”
Dialog(“Login”).WinEdit(“Agent Name:”).Set “venkatesh”
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4c04981da8da89eb8a871793145df8e386047656″
Dialog(“Login”).WinButton(“OK”).Click

Goto insert —>Call to new action and then it would create action2.
Then go for File–>Open Order and give orger number (Ex:5) and ok.Then the script would be

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;Open Order…”
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set “5″
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click

Goto insert —>Call to new action and then it would create action3.
Close the Flight Reservation application.Then the script would be

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).Close

2.How to create actions for data table from Keyword View in qtp

Create Blank TestCase. Goto –>Record .Open ur Flight Reservation application
Action1 :
Do the record for login (Enter Agent Name and Mercury Password).Then the script would be

SystemUtil.Run “C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe”,”",”C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\”,”open”
Dialog(“Login”).WinEdit(“Agent Name:”).Set “venkatesh”
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4c04981da8da89eb8a871793145df8e386047656″
Dialog(“Login”).WinButton(“OK”).Click

Action2 :
Goto insert —>Call to new action and then it would create action2.
Then go for File–>Open Order and give orger number (Ex:5) and ok.Then the script would be

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;Open Order…”
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set “5″
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click

Action3 :
Goto insert —>Call to new action and then it would create action3.
Close the Flight Reservation application.Then the script would be

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).Close

Fill the data in the global sheet. Ex:
Make the A name as Login and B name as Password
Give any name (Ex: venkatesh for login and mercury for password)

Fill the data in the Action2. Ex:
Make the A name as Order Number
Give some numbers (Ex: 3,45,8 )

Goto KeyWord View
Action1
Login :
AgentName Set Value
Click on the value.There choose Parameter:DataTable.
Name :Choose Login
Ok
Same thing for password field.
Name :Choose Password
Ok

Action2
Flight Reservation
Open Order
Edit  set “some number” click there
There choose Parameter:DataTable.
Location in the datatable :current action
ok

Now you look into the expert view and see the code .
There automatically code would be change

Goto–Action1–>Right Click–>Action Call Properties–>Run on all rows
Goto–Action2–>Right Click–>Action Call Properties–>Run on all rows

Execute it.

execute it

3.How to create actions for data table in qtp

Action 1:

SystemUtil.Run “C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe”,”",”C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\”,”open”
Dialog(“Login”).WinEdit(“Agent Name:”).Set DataTable(“Login”, dtGlobalSheet)
Dialog(“Login”).WinEdit(“Password:”).SetSecure DataTable(“Password”, dtGlobalSheet)
Dialog(“Login”).WinButton(“OK”).Click

Action2 :

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;Open Order…”
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set DataTable(“OpenOrder”, dtLocalSheet)
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click

Action3:

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).Close

4.How to reuse actions in qtp

Step 1:Create Blank Test.
Goto –>Record .Open ur Flight Reservation application

Do the record for login (Enter Agent Name and Mercury Password).Then the script would be

SystemUtil.Run “C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe”,”",”C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\”,”open”
Dialog(“Login”).WinEdit(“Agent Name:”).Set “venkatesh”
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4c04981da8da89eb8a871793145df8e386047656″
Dialog(“Login”).WinButton(“OK”).Click

Goto insert —>Call to new action and then it would create action2.
Then go for File–>Open Order and give orger number (Ex:5) and ok.Then the script would be

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;Open Order…”
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set “5″
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click

Goto insert —>Call to new action and then it would create action3.
Close the Flight Reservation application.Then the script would be

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).Close

Now Goto—>KeyWord view–>Rht Click on Action1 –>Action Properties–>There u choose the option
for Reusable action  (Then action1 is called reusable action)
(Note : You need to give the reuasable action to the corresponding action)

Step2 : Now we can use action1 (which we made as reusable)
Create blank test

Goto–>Keyword view–>Rht Click on action1–>Insert Call to Existing Action
There u can browse the actions and choose (Ex:Action1).
Then you can execute

5.How to exit from the test in actions using exittest in qtp
Action1 :

No need to goto record mode.Just goto Object Repository and add objects to local
Open ur flight application and click on log in window.click ok
write the below code in expert view

SystemUtil.Run “C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe”,”",”C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\”,”open”
Dialog(“Login”).WinEdit(“Agent Name:”).Set “venkatesh”
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4c0616cda83a5c9f88633cdaff4c044c”
Dialog(“Login”).WinButton(“OK”).Click
bexists=Dialog(“Login”).Dialog(“Flight Reservations”).Exist(2)

If bexists Then
smsg=Dialog(“Login”).Dialog(“Flight Reservations”).GetVisibleText
reporter.ReportEvent micFail,”Login”,smsg
Dialog(“Login”).Dialog(“Flight Reservations”).WinButton(“OK”).Click
Dialog(“Login”).WinButton(“Cancel”).Click
exittest

End If

Action2:

Open ur flight application login and login with agent name and pwd
No need to goto record mode.Just goto Object Repository and add objects to local
click on FlightReservation window. click ok
write the below code in expert view

window(“Flight Reservation”).Activate
window(“Flight Reservation”).Close

6.How to exit from the action in actions using exitaction in qtp
Action1 :

No need to goto record mode.Just goto Object Repository and add objects to local
Open ur flight application and click on log in window.click ok
write the below code in expert view

SystemUtil.Run “C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe”,”",”C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\”,”open”
Dialog(“Login”).WinEdit(“Agent Name:”).Set “venkatesh”
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4c0616cda83a5c9f88633cdaff4c044c”
Dialog(“Login”).WinButton(“OK”).Click
bexists=Dialog(“Login”).Dialog(“Flight Reservations”).Exist(2)

If bexists Then
smsg=Dialog(“Login”).Dialog(“Flight Reservations”).GetVisibleText
reporter.ReportEvent micFail,”Login”,smsg
Dialog(“Login”).Dialog(“Flight Reservations”).WinButton(“OK”).Click
Dialog(“Login”).WinButton(“Cancel”).Click
exitaction

End If

msgbox “it will not execute”

Action2:

Open ur flight application login and login with agent name and pwd
No need to goto record mode.Just goto Object Repository and add objects to local
click on FlightReservation window. click ok
write the below code in expert view

window(“Flight Reservation”).Activate
window(“Flight Reservation”).Close

7.How to call action in qtp

(qtp reusable action example)

To call any action in qtp using RunAction, that action should be made as reusable

Follwing example has 3 actions. I am calling Action3 in Action1

Action1 :

SystemUtil.Run “C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe”,”",”C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\”,”open”
Dialog(“Login”).WinEdit(“Agent Name:”).Set “venkatesh”
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4c0616cda83a5c9f88633cdaff4c044c”
Dialog(“Login”).WinButton(“OK”).Click
bexists=Dialog(“Login”).Dialog(“Flight Reservations”).Exist(2)

If bexists Then
smsg=Dialog(“Login”).Dialog(“Flight Reservations”).GetVisibleText
reporter.ReportEvent micFail,”Login”,smsg
Dialog(“Login”).Dialog(“Flight Reservations”).WinButton(“OK”).Click
Dialog(“Login”).WinButton(“Cancel”).Click

End If

runaction “Action3″,oneiteration

Action2 :

msgbox “welcome to action2″

Action3 :

SystemUtil.Run “C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe”,”",”C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\”,”open”
Dialog(“Login”).WinEdit(“Agent Name:”).Set “venkatesh”
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4c06513879e8c9aae96f878ebd40924cb403de52″
Dialog(“Login”).WinEdit(“Password:”).Type  micReturn
Window(“Flight Reservation”).Close

Execute it.It will execute in the below sequence.
Action1–>Action3
Action2–>Action3

Examples for Parameterization in qtp



1. What is parameterization in qtp

Testing an application with different types of inputs for the same script.

2. How many ways are there for parameterization in qtp

Parameterization can do in 3 ways

Through Methods

Through Physical Description

Through Check Point

1.How to parameterize through Methods from Keyword View in qtp.

Create Blank TestCase. Goto –>Record .Open ur Flight Reservation application
Action1 :
Do the record for login (Enter Agent Name and Mercury Password).Then the script would be

SystemUtil.Run “C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe”,””,”C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\”,”open”
Dialog(“Login”).WinEdit(“Agent Name:”).Set “venkatesh”
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4c04981da8da89eb8a871793145df8e386047656″
Dialog(“Login”).WinButton(“OK”).Click

Action2 :
Goto insert —>Call to new action and then it would create action2.
Then go for File–>Open Order and give orger number (Ex:5) and ok.Then the script would be

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;Open Order…”
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set “5″
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click

Action3 :
Goto insert —>Call to new action and then it would create action3.
Close the Flight Reservation application.Then the script would be

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).Close

Fill the data in the global sheet. Ex:
Make the A name as Login and B name as Password
Give any name (Ex: venkatesh for login and mercury for password)

Fill the data in the Action2. Ex:
Make the A name as Order Number
Give some numbers (Ex: 3,45,8 )

Goto KeyWord View
Action1
Login :
AgentName Set Value
Click on the value.There choose Parameter:DataTable.
Name :Choose Login
Ok
Same thing for password field.
Name :Choose Password
Ok

Action2
Flight Reservation
Open Order
Edit  set “some number” click there
There choose Parameter:DataTable.
Location in the datatable :current action
ok

Now you look into the expert view and see the code .
There automatically code would be change

Goto–Action1–>Right Click–>Action Call Properties–>Run on all rows
Goto–Action2–>Right Click–>Action Call Properties–>Run on all rows

Execute it.

execute it

2.How to parameterize through methods in qtp

Action 1:

SystemUtil.Run “C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe”,””,”C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\”,”open”
Dialog(“Login”).WinEdit(“Agent Name:”).Set DataTable(“Login”, dtGlobalSheet)
Dialog(“Login”).WinEdit(“Password:”).SetSecure DataTable(“Password”, dtGlobalSheet)
Dialog(“Login”).WinButton(“OK”).Click

Action2 :

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;Open Order…”
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set DataTable(“OpenOrder”, dtLocalSheet)
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click

Action3:

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).Close

Just user need to give inputs in the corresponding GlobalData sheet (Make ‘A’ as Login and ‘B’ as ‘Password’ )in Action2 Sheet (Make ‘A’ as ‘Order No’).

3.Parameterization through physical description example in qtp

Parameterization through physical description Example :

Action1 :

systemutil.Run “C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe”
Dialog(“Login”).WinEdit(“Agent Name:”).Set “venkatesh”
Dialog(“Login”).WinEdit(“Agent Name:”).Type  micTab
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4c0ba4645292b686779b42c81dd13093544face9″
Dialog(“Login”).WinEdit(“Password:”).Type  micReturn

Action2 :

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;Open Order…”
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set DataTable(“order_no”, dtGlobalSheet)
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click
Window(“Flight Reservation”).Activate

Action3 :

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;Fax Order…”
Window(“Flight Reservation”).Dialog(“Fax Order No. 1″).ActiveX(“MaskEdBox”).Type “11111111111111″
Window(“Flight Reservation”).Dialog(“Fax Order No. 1″).WinButton(“Cancel”).Click
Window(“Flight Reservation”).Activate

Action4 :

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).Close

Goto Global Data Table :
make “A” as “order_no” and enter
1
2
3

make “B” as “fax_no” and enter
Fax Order No. 1
Fax Order No. 2
Fax Order No. 3

Goto Expert Veiw–Action3

rht click on  Dialog(“Fax Order No. 1″) goto object propert1es
goto Fax Order No. 1 click there u will get browse button open
choose DataTable and fax_no and click ok
execute it