QTP Scripting Examples

QTP Training

QTP Scripting Examples
          ----------------------
'Verify Cancel Operation in Login dialog
'Without entering any Data if we select "Cancel" Button then Login Dialog should be disappeared
'After Entering Agent Name, if we select "Cancel" Button then Login Dialog should be disappeared
'After Entering Agent Name & password, if we select "Cancel" Button then Login Dialog should be disappeared
'--------------------------------------------------------------------------------------------------------------------
'Without entering any Data
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Wait 2
Dialog("Login").WinButton("Cancel").Click

If Not Dialog("Login").Exist(3) Then
Reporter.ReportEvent micPass, "Res","Login Dialog disappeared"
Else
Reporter.ReportEvent micFail, "Res","Login Dialog Exists"
End If

'After Entering Agent Name
If Not Dialog("Login").Exist(3)  Then
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
End If
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "abcd"
Wait 2
Dialog("Login").WinButton("Cancel").Click

If Not Dialog("Login").Exist(3) Then
Reporter.ReportEvent micPass, "Res","Login Dialog disappeared"
Else
Reporter.ReportEvent micFail, "Res","Login Dialog Exists"
End If

'After Entering Agent Name & Password
If Not Dialog("Login").Exist(3)  Then
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
End If
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "abcd"
Dialog("Login").WinEdit("Password:").SetSecure "4d0b6f021b55a51a991eb71730181137ccad8f19"
Wait 2
Dialog("Login").WinButton("Cancel").Click

If Not Dialog("Login").Exist(3) Then
Reporter.ReportEvent micPass, "Res","Login Dialog disappeared"
Else
Reporter.ReportEvent micFail, "Res","Login Dialog Exists"
End If

''*****************************************************************************************************
'Test Requirement: Verify "Total" in Flight Reservation, where Total=Tickets*Price
'Verify for 1 to 10 Orders

'Author:abc

'Date of Creation: 17-12-2010

'Date of Modification: NA

'Pre-requasites:
'Login.tsr, Orders.tsr

'Test Flow:
'Launch the Application
'Login Operation
'Acivate the FR window and Open an Order
'Capture Total, Price, Tickets values
'Convert string type data into double/integer type
'Compare if the Total=Tickets*Price or not?
'Form Loop to open 1 to 10 Orders
'*****************************************************************************************************
Option explicit
Dim Tickets, Price, Total, Order_Number
If Not Window("Flight Reservation").Exist(3)  Then

'Launch the Application and Login Operation
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "abcd"
Dialog("Login").WinEdit("Password:").SetSecure "4d0b752a01e5f01019b38bafb8e6a4073189ef86"
Dialog("Login").WinButton("OK").Click
End If

'Open Order
For Order_Number= 1 to 10 Step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("OpenOrder").Click
Window("Flight Reservation").Dialog("Open Order").Activate
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("OrderNo").Set Order_Number
Wait 2
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

'Capture Total, Price, Tickets values
Tickets = Window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text")
Total = Window("Flight Reservation").WinEdit("Total:").GetVisibleText()
Price = Window("Flight Reservation").WinEdit("Price:").GetROProperty("text")

'Msgbox Tickets: Msgbox Total: Msgbox Price

'Convert string type data into integer/Double
Tickets=Cint(Tickets)
Total=Cdbl (Total)
Price=Cdbl(Price)

'Compare if the Total=Tickets*Price or not?
If Total=Tickets*Price  Then
Reporter.ReportEvent 0, "Res","Total is Correct"
Else
Reporter.ReportEvent 1, "Res","Total is Incorrect"
End If
Next

---------------------------------
''*****************************************************************************************************
'Test Requirement: Verify "Total" in Flight Reservation, where Total=Tickets*Price
'Verify for 1 to 10 Orders
'Export Order Number, Tickets, Price ,Toal and Result to an external excel file

'Author:abc

'Date of Creation: 17-12-2010

'Date of Modification: NA

'Pre-requasites:
'Login.tsr, Orders.tsr

'Test Flow:
'Launch the Application
'Login Operation
'Acivate the FR window and Open an Order
'Capture Total, Price, Tickets values
'Convert string type data into double/integer type
'Compare if the Total=Tickets*Price or not?
'Form Loop to open 1 to 10 Orders
'*****************************************************************************************************
Option explicit
Dim Tickets, Price, Total, Order_Number, objExcel, myFile, mysheet, row, Result
Set objExcel=CreateObject("Excel.Application")
Set myFile=objExcel.Workbooks.Open ("C:\Documents and Settings\gcreddy\Desktop\xyz.xls")
Set mySheet=myFile.Worksheets("Sheet1")

'Create column headers in Excel sheet1
row=1
mySheet.Cells(row,"A")="OrderNo"
mySheet.Cells(row,"B")="Tickets"
mySheet.Cells(row,"C")="Price"
mySheet.Cells(row,"D")="Total"
mySheet.Cells(row,"E")="Result"
row=row+1

If Not Window("Flight Reservation").Exist(3)  Then
'Launch the Application and Login Operation
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "abcd"
Dialog("Login").WinEdit("Password:").SetSecure "4d0b752a01e5f01019b38bafb8e6a4073189ef86"
Dialog("Login").WinButton("OK").Click
End If

'Open Order
For Order_Number= 1 to 10 Step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("OpenOrder").Click
Window("Flight Reservation").Dialog("Open Order").Activate
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("OrderNo").Set Order_Number
Wait 2
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

'Capture Total, Price, Tickets values
Tickets = Window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text")
Total = Window("Flight Reservation").WinEdit("Total:").GetVisibleText()
Price = Window("Flight Reservation").WinEdit("Price:").GetROProperty("text")

'Msgbox Tickets: Msgbox Total: Msgbox Price

'Convert string type data into integer/Double
Tickets=Cint(Tickets)
Total=Cdbl (Total)
Price=Cdbl(Price)

'Compare if the Total=Tickets*Price or not?
If Total=Tickets*Price  Then
Result="Total is Correct"
mySheet.Cells(row,"A")=Order_Number
mySheet.Cells(row,"B")=Tickets
mySheet.Cells(row,"C")=Price
mySheet.Cells(row,"D")=Total
mySheet.Cells(row,"E")=Result
Else
Result="Total is InCorrect"
mySheet.Cells(row,"A")=Order_Number
mySheet.Cells(row,"B")=Tickets
mySheet.Cells(row,"C")=Price
mySheet.Cells(row,"D")=Total
mySheet.Cells(row,"E")=Result
End If
row=row+1
Next

myFile.Save
myFile.Close
objExcel.Quit
Set objExcel=Nothing
-----------------------------------------

'Test Requirement: Verify the Cost in jjperfumes web portal
'Where Cost=Quantity*Unit Price
'************************************************************************
SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE", "www.jjperfumes.com"

Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount perfume").Image("thumb_1845_WLINP50PSW").Click
Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount perfume_2").WebEdit("quantity").Set "4"
Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount perfume_2").WebButton("Add To Cart").Click

Unit_Price = Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount perfume_3").WebElement("[Remove]").GetROProperty("innertext")
Quantity = Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount perfume_3").WebEdit("quantity[]").GetROProperty("value")
Cost = Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount perfume_3").WebElement("[Remove]_2").GetROProperty("innertext")

'Msgbox Unit_Price: Msgbox Quantity: Msgbox Cost
Unit_Price=Cdbl (Unit_Price)
Quantity=Cint(Quantity)
Cost=Cdbl(Cost)

If Cost= Unit_Price*Quantity Then
          Msgbox "Pass"
Else
Msgbox "Fail"
End If

-------------------------------------------

'Test Requirement: Verify Login & Logout Links
'After Launch the Application then check the existence of the Login and Logout Links
'Login Link only should be available
'After Login Operation then check the existence of the Login and Logout Links
'Logout Link only should be available
'-----------------------------------------------------------------------------------------------------------
SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE","www.jjperfumes.com"
Wait 5
Set myBrowser=Browser("JJ Perfumes-Discount perfume")
If myBrowser.Page("JJ Perfumes-Discount perfume").Link("Login").Exist(3) Then
Reporter.ReportEvent 0,"Res","Login Link Exists"
Else
Reporter.ReportEvent 1,"Res","Login Link Not Exists"
End If

If Not myBrowser.Page("JJ Perfumes-Discount perfume_5").Link("Logout").Exist(3) Then
Reporter.ReportEvent 0,"Res","Logout Link Not Exists"
Else
Reporter.ReportEvent 1,"Res","Logout Link Exists"
End If
myBrowser.Page("JJ Perfumes-Discount perfume").Link("Login").Click
myBrowser.Page("JJ Perfumes-Discount perfume_4").WebEdit("username").Set "ganga12@yahoo.com"
myBrowser.Page("JJ Perfumes-Discount perfume_4").WebEdit("password").Set "abcd"
myBrowser.Page("JJ Perfumes-Discount perfume_4").WebButton("Login").Click

If Not myBrowser.Page("JJ Perfumes-Discount perfume").Link("Login").Exist(3) Then
Reporter.ReportEvent 0,"Res","Login Link Not Exists"
Else
Reporter.ReportEvent 1,"Res","Login Link Exists"
End If

If myBrowser.Page("JJ Perfumes-Discount perfume_5").Link("Logout").Exist(3) Then
Reporter.ReportEvent 0,"Res","Logout Link Exists"
Else
Reporter.ReportEvent 1,"Res","Logout Link Not Exists"
End If
---------------------------------------------------------


Exercises:
------------
1)'Data Driven Testing for Login Operation by fecthing Test Data from an excel file
' Export Result and Error message to the Same file
'Take Invalid Agent Name for one iteration, Take Invalid Password for one iteration
'and Take Invalid Agent Name & Password for one more iteration.

2) 'Data Driven Testing by fetching Test data from a Database
and Export Result to the same Table

3) Create an excel file using Excel object and add one more sheet

4) Open an Excel file using Excel object and move 3rd sheet to 1st posision

5) Verify Price Consistency in Flight Reservation
,Where First Class = 3 Times of Economy Class Price
'Business Class = 2 Times of Economy Class Price
,Verify for 1 to 10 Orders
----------------------------------------------------------------------------
 

0 comments:

Post a Comment