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

7 comments to Examples for actions in qtp

  • Kavitha

    Very helpful.

  • super maga….very good….

    continue same attitude…and i hv one prob…..

    if u r free pls tell me hw to select any flight which is avaailable in the list when we pressed the FLIGHT button….pls dude….mail the solution to harisha.mg2007@gmail.com

  • it should be automated…not manually….it selects diff user each time with diff TO & FROM places…n the flights list also changes….dont know wat to do….

  • Thanks for comment Harisha…Presently i got busy..Anyway i will try to solve this problem

  • saikrishna

    Hi harisha ,

    Can you explain your requirement clear, so that i will help you.

  • saikrishna

    if you want to select the any random TO flight and From flight

    retrieve all items using GetROProperty(“all items”)

    and split with space

    allarry=split(allitems,” “)

    .weblist(“weblistname”).select “#”&randomnumber(0,allarray.count-1)

    it will randomly generate value and select the particular position value in the list.

    if i am wrong, correct me

  • bhageerath

    bro awesome work

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>