QTP - Chapter XIII

Re-Naming: - Select the required Action-->Right Click on Test Pane-->Actions-->Action Properties-->Re-Name the
Action Name-->Click OK button.

Deleting an Action: -

Navigation1: -Select the required action-->Edit Menu-->Action-->Delete Action-->Click Yes Button in Conformation
message.
Navigation2: - Keyword view -->Right Click on required Action-->Select Delete-->Click Yes Button in conformation
message.

ScriptNo27: - Write a script to find given Action Existence
sExpAction = "Action5"
iFlag = 0
Set objQtp = CreateObject("QuickTest.Application")
iActionCnt = objQtp.Test.Actions.Count
MsgBox iActionCnt
For index = 1 to iActionCnt
Print objQtp.Test.Actions(index).Name
If objQtp.Test.Actions (index).Name = sExpAction Then
MsgBox "Action is Found"
iFlag = 1
Exit for
End If
Next
If iFlag = 0 Then
MsgBox "Action is Not Found"
End If
Set objQtp = Nothing
-->By default actions are executing in order which we are created.
-->If we want to change the order of action execution then we follow bellow navigation
Navigation: - Keyword ViewSelect the required action and drag and drop in required position

Types of Actions: -
1. Normal /Non Reusable Action
2. Re- Usable Actions
3. External Re-Usable Actions

Normal /Non Reusable Action: - An Action that can be called only in the test without reusability called as Normal /Non Reusable Action.

Re- Usable Actions: - An Action that can be called in same test script and in another test script multiple times is called as Re- Usable Actions.

External Re-Usable Actions: - An Action that can be call in same test script or in another test script in multiple times in READ ONLY mode are called as External Re-Usable Actions

Implement Script Reusability by Action: -
We can implement a Script Reusability by Action, in bellow ways
1. Call to Copy of Action
2. Call to Existing Action

Calling Action: - The Action which is calling another action
Called Action: - The Action which is called by another Action

Implementing re usability by using Call to Copy: -
Navigation: - Open calling test script -->insert Menu --> select call to copy of action -->browse the required called to
test script -->select the required action  --> click on OK button
Syntax: - RunAction”Copy of ”, OneIteration
Ex: - RunAction “Copy of login”, OneIteration
RunAction “Copy of logout”, OneIteration

Implementing re usability by using Call to Existing: -
Navigation: - Open calling test script  --> nsert Menu --> select call to Existing action-->browse the required called test
script-->select the required action --> click on OK button
Syntax: - RunAction “[Called Test Script]”, OneIteration
Ex: - RunAction “login[Action Demo]”, OneIteration
RunAction “logout[Action Demo]”, OneIteration

Difference between call to Copy and Call to Existing: -



                         Implementing Parameterization by using Action Parameters

Action Parameters: - These are used to retrieving the data and sending results in between Called Action and
Calling Action parameters.
There are two types of action parameters
1. Input Parameters: - These are used to retrieving the data from Calling Action to Called Action
2. Output Parameters: - These are used to sending Test Result from Called Action to Calling Action
Note: - We create Action Parameters in Called Action.
Note: - Action Parameters are independent to Action
Navigation to create Action Parameters: -
Open Called test script-->select the required action right click on test pane-->select Action-->Action
Properties-->select Parameter Tab-->Click Add button-->Enter parameter name and value-->Click on OK button.
Split of Action: - Right click on required statement-->select Action-->Split-->Enter First Action Name--> Enter

Second Action Name-->Click on OK button

ScriptNo28: - Write a script for login logout by using Action Parameter Concept
-->Open called Test Script and create 2 actions login and logout
-->Enter bellow code
-->Create sUname, sPwd input parameters and sRslt as output parameters

Script Name [loginlogout]-Action Name [Login]: -
[Add Action Parameters (sUName, sPwd, sRslt) to loginlogout script]
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
If Dialog("Login").Exist Then
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set Parameter("sUName")
Wait(2)
Dialog("Login").WinEdit("Password:").Set Parameter("sPwd")
Dialog("Login").WinButton("OK").Click
If Dialog("Login").Dialog("Flight Reservations").Exist(5) Then
Reporter.ReportEvent micFail,"Login Validation","Given Data is Invalid"
Parameter("sRslt") = "Fail"
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
Dialog("Login").WinButton("Cancel").Click
Else
If Window("Flight Reservation").Exist Then
Reporter.ReportEvent micPass, "Login Validation","Login Validation is Pass"
Parameter("sRslt") = "Pass"
Window("Flight Reservation").Close
Else
Reporter.ReportEvent micFail, "Login Validation","Login Validation is Fail"
Parameter("sRslt") = "Fail"
End If
End If
End If

Action Name [Logout]: -
If Window("Flight Reservation").Exist(5) Then
Window("Flight Reservation").Close
While Window("Flight Reservation").Exist(2) = True
Wend
If Window("Flight Reservation").Exist(2) = "False" Then
Reporter.ReportEvent micPass, "Close Application","Application is Closed"
Else
Reporter.ReportEvent micFail,"Close Application","Application is not Closed"
End If
End If
[Here loginlogout script is called actions]

Script Name [calngaction]: - this action is calling action



Action Template: -
It explains Action description as bellow
*********************************************************************************

  • ACtion name:
  • Action Description:
  • Design Date:
  • Tool Used:
  • Comments:
*********************************************************************************


Navigation: - Open notepad enter the action template save the file as “ActionTemplate.mst” [MST: -mercury scenario test script] in bellow path save it C:\Program files\HP\Quick Test Professional\dat\

Split of Action: - Right click on required statement-->select Action-->SplitEnter First Action Name--> Enter Second Action Name-->Click on OK button

ScriptNo29: -HW



ActionDemo: - Action1
'MsgBox "Login"
SystemUtil.Run "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
If Dialog("Login").Exist Then
Dialog("Login").Activate
'Msgbox Parameter("suname")
'MsgBox Parameter("spwd")
Dialog("Login").WinEdit("Agent Name:").Set parameter("suname")
Dialog("Login").WinEdit("Password:").Set Parameter("spwd")

Dialog("Login").WinButton("OK").Click

If Dialog("Login").Dialog("Flight Reservations").Exist(3) Then
Reporter.ReportEvent micFail, "Login Validation", "Invalid credentials "
Parameter("srslt") = "Fail"
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
Dialog("Login").WinButton("Cancel").Click
Else
Reporter.ReportEvent micPass , "Login Validation", "succesfully logged into flight reservation"
Parameter("srslt") = "Pass"
End If
Else
Reporter.ReportEvent micFail, "Login Validation", "Flight application is not opened"
Parameter("srslt") = "Fail"
End If

Action2: -
If Window("Flight Reservation").Exist Then
Window("Flight Reservation").Close
While Window("Flight Reservation").Exist(2) = True
Wend
If Window("Flight Reservation").Exist(3) = "False" Then
Reporter.ReportEvent micPass, "Close Application", "Application is closed"
Else
Reporter.ReportEvent micFail,"close application","app is not closed"
End If
Else
Reporter.ReportEvent micFail,"close app","app is not closed"
End If

New Order: -

Open Order: -

Fax Order: -
'Msgbox "Fax Order"
Set objxl=CreateObject("Excel.Application")
Set objwbk=objxl.Workbooks.Open ("D:\Project\faxorder.xls")
Set objwst = objwbk.Worksheets("sheet1")
Set objFile = CreateObject("Scripting.FileSystemObject")
Set objptr = objFile.OpenTextFile("D:\Project\FlightDetails.txt",8)
iRcnt=objwst.UsedRange.Rows.count
Set obj= window("Flight Reservation")
If obj.Exist (5) Then
For indx = 2 to iRcnt
obj.Activate
obj.WinMenu("Menu").Select "File;Open Order..."
obj.Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
obj.Dialog("Open Order").WinEdit("Edit_2").Set objwst.Cells(indx,1)
obj.Dialog("Open Order").WinButton("OK").Click
If obj.Dialog("Open Order").Dialog("Flight Reservations").Exist(5) Then
obj.Dialog("Open Order").Dialog("Flight Reservations").WinButton("OK").Click
obj.Dialog("Open Order").WinButton("Cancel").Click
Reporter.ReportEvent micFail,"Open Order","Order number doesnt exist"
objwst.Cells(indx,3) = "order number doesnt exist"
objptr.WriteLine Parameter("sUname") & " tried to open order number " &
objwst.cells(indx,1) & " which doesnt exist"
Else
obj.Activate
obj.WinMenu("Menu").Select "File;Fax Order..."
obj.Dialog("Fax Order No. *.*").WinObject("Fax Number:").Type objwst.cells(indx,2)
'obj.Window("Fax Order No. *.*").RunAnalog "Track2" @@ hightlight
id_;_3016516_;_script infofile_;_ZIP::ssf1.xml_;_
obj.Dialog("Fax Order No. *.*").WinButton("Send").Click

If obj.Dialog("Fax Order No. *.*").Dialog("Flight Reservations").Exist(5) Then
obj.Dialog("Fax Order No. *.*").Dialog("Flight
Reservations").WinButton("OK").Click
Reporter.ReportEvent micFail,"Send Fax","Not able to send fax"
objwst.Cells(indx,3) = "Not able to send fax"
objptr.WriteLine Parameter("sUname") & " tried to send fax to " &
objwst.cells(indx,2) & " but not able to send fax"
obj.Dialog("Fax Order No. *.*").WinButton("Cancel").Click
Else
While obj.Dialog("Fax Order No. *.*").Exist(3)="True"
Wend
sFaxMsg = obj.WinObject("AfxWnd40").GetROProperty("Text")
If sFaxMsg = "Fax Sent Successfully..." Then
Reporter.ReportEvent micPass,"Send Fax" , "Fax Sent Successfully"
objptr.WriteLine Parameter("sUname") & " has successfully sent fax to
" & objwst.cells(indx,2)
objwst.Cells(indx,3) = "Fax sent successfully"
End If
End If
End If
Next
Else
Reporter.ReportEvent micFail,"Select Fax Order","Flight Reservation Window doesnot exist"
End If
objwbk.Save
objwbk.Close
objxl.Quit
Set objwst = nothing
Set objwbk = nothing
Set objxl = nothing
Set obj = nothing

Set objptr = nothing
Set objfile = nothing
Delete order: -
'Msgbox "Delete order"
Set objxl = CreateObject ("Excel.Application")
Set objwb = objxl.Workbooks.Open("D:\Project\deleteorder.xls")
Set objst = objwb.Worksheets("sheet1")
Set objFile = CreateObject("Scripting.FileSystemObject")
Set objptr = objFile.OpenTextFile("D:\Project\FlightDetails.txt",8)
Set obj = Window("Flight Reservation")
iRcnt = objst.UsedRange.rows.count
If obj.Exist(2)Then
For indx = 2 to iRcnt
sOnum = objst.cells(indx,1)
If sOnum>10 Then
RunAction "openord [openorder] [2]", oneIteration, sOnum, bOpen
If bOpen Then
Reporter.ReportEvent micPass,"Open Order","Opened the order to delete"
If obj.WinButton("Delete Order").GetROProperty("Enabled")="True" Then
obj.WinButton("Delete Order").Click
If obj.Dialog("Flight Reservations").Exist Then
obj.Dialog("Flight Reservations").WinButton("Yes").Click
objst.cells(indx,2) = "Deleted order number "& sOnum
objptr.WriteLine Parameter("sUname") & " has successfully
deleted the order " & sOnum
End If
End If
Else
Reporter.ReportEvent micFail,"Delete Order","Order number doesnt exist"

objst.cells(indx,2) =sOnum & " order number doesnt exist"
objptr.WriteLine Parameter("sUname") & " tried to open order " & sOnum & " but order
doesnt exist"
End If
Else
Reporter.ReportEvent micFail,"Delete Order","Cannot delete orders below 10"
objst.cells(indx,2) = "Cannot delete order number "& sOnum
objptr.WriteLine Parameter("sUname") & " tried to delete order " & sOnum & " but
cannot delete orders less than 10"
End If
Next
End If
objwb.Save
objwb.Close
objxl.Quit
Set objst = nothing [ Set objwb = nothing Set objxl = nothing Set objptr = nothing Set objfile = nothing]
Orders: -
Set objxl = CreateObject ("Excel.Application")
Set objwb = objxl.Workbooks.Open("D:\Project\users.xls")
Set objst = objwb.Worksheets("sheet1")
Set objFile = CreateObject("Scripting.FileSystemObject")
Set objptr = objFile.CreateTextFile("D:\Project\FlightDetails.txt",8)
ircnt = objst.UsedRange.Rows.Count
For indx =2 to ircnt
sUname = objst.cells(indx,1)
sPwd = objst.cells(indx,2)
RunAction "Login [ActionDemo] [2]", oneIteration, sUname, sPwd, Result
Role = objst.cells(indx,3)
Select Case Role
Case "new order"
RunAction "Action1 [neworder] [2]", oneIteration, iOrdno
RunAction "Logout [ActionDemo] [2]", oneIteration
objptr.WriteLine sUname & " has placed a new order generating order number: " &
iOrdno
objptr.Close
Case "open order"
RunAction "openord [openorder] [2]", oneIteration, iOrdno, bOpen
RunAction "Logout [ActionDemo] [2]", oneIteration
If objFile.FileExists("D:\Project\FlightDetails.txt") Then
Set objptr = objFile.OpenTextFile("D:\Project\FlightDetails.txt",8)
End If
If bOpen Then
objptr.WriteLine sUname & " has opened an existing order number: " & iOrdno
Else
objptr.WriteLine sUname & " has not opened an existing order number: " & iOrdno
End If
objptr.Close
Case "Fax order"
RunAction "faxorder [faxorder] [2]", oneIteration, sUname
RunAction "Logout [ActionDemo] [2]", oneIteration
Case "delete order"
RunAction "delorder [deleteorder] [2]", oneIteration, sUname
RunAction "Logout [ActionDemo] [2]", oneIteration
Case Else
End Select
Next
objwb.Save
objwb.Close
objxl.Quit
Set objst = nothing [ Set objwb = nothing Set objxl = nothing Set objptr = nothing Set objfile = nothing]



No comments :

Post a Comment