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
No comments:
Post a Comment