Thursday, 16 July 2015

QTP PRACTICE REAL TIME SCRIPTS


Scripts (Tests) to Practice

1) Verify Price Consistency for 1 to 10 Orders in Flight Reservation Application

(In Flight Reservation, First class price=3*Economy class price and Business class price=2*Economy class price)



1)     Option explicit

2)     Dim n,f,b,e

3)     If Not window("Flight Reservation").Exist (2) Then

4)     SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"

5)     Dialog("Login").Activate

6)     Dialog("Login").WinEdit("Agent Name:").Set "asdf"

7)     Dialog("Login").WinEdit("Password:").SetSecure "4aa8b7b7c5823680cfcb24d30714c9bbf0dff1eb"

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

9)     End If

10) For n= 1 to 10 step 1

11) Window("Flight Reservation").Activate

12) Window("Flight Reservation").WinButton("Button").Click

13) Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"

14) Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set n

15) Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

16) Window("Flight Reservation").WinRadioButton("First").Set

17) f=Window("Flight Reservation").WinEdit("Price:").GetVisibleText

18) Window("Flight Reservation").WinRadioButton("Business").Set

19) b=Window("Flight Reservation").WinEdit("Price:").GetVisibleText

20) Window("Flight Reservation").WinRadioButton("Economy").Set

21) e=Window("Flight Reservation").WinEdit("Price:").GetVisibleText

22) f=cdbl(mid(f,2,len (f-1)))

23) b=cdbl(mid(b,2,len (b-1)))

24) e=cdbl(mid(e,2,len (e-1)))

25) If f=3*e and b=2*e Then

26) Reporter.ReportEvent 0,"Res","Pricy Consistancy is there"

27) else

28) Reporter.ReportEvent 1,"Res","Pricy Consistancy is NOT there"

29) End If

30) Window("Flight Reservation").WinButton("Button_2").Click

31) Window("Flight Reservation").Dialog("Flight Reservations").WinButton("No").Click

32) Next



2) Verify Total, In Flight Reservation (In Flight Reservation, Total = Tickets * Price)


1)     Option Explicit

2)     Dim t,p,tot,n

3)     For n= 1 to 10 step 1

4)     If Not window("Flight Reservation").Exist (2) Then

5)     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"

6)     Dialog("Login").Activate

7)     Dialog("Login").WinEdit("Agent Name:").Set "Gcreddy"

8)     Dialog("Login").WinEdit("Password:").SetSecure "4aa892d62c529f1c23298175ad78c58f43da8e34"

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

10) End If

11) Window("Flight Reservation").Activate

12) Window("Flight Reservation").WinButton("Button").Click

13) Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"

14) Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set n

15) Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click



16) t=Window("Flight Reservation").WinEdit("Tickets:").GetVisibleText

17) p=Window("Flight Reservation").WinEdit("Price:").GetVisibleText

18) tot=Window("Flight Reservation").WinEdit("Total:").GetVisibleText

19) t=cdbl (t)

20) p=Cdbl(mid(p,2,len (p-1)))

21) tot=Cdbl(mid(tot,2,len (tot-1)))



22) If tot=t*p Then

23) Reporter.ReportEvent 0,"Res","Calculation Passed"

24) else

25) Reporter.ReportEvent 1,"Res","Calculation Failed"

26) End If

27) Next


3) Verify Flight From & Flight To Combo Boxes (In Flight reservation, select an item from Fly From: combo box and verify weather that item available or not in Fly To: combo box, like this select all items one by one in Fly From and verify weather selected items available or not in Fly To.)



1)     Option explicit

2)     Dim qtp,flight_app,f,t,i,j,x,y

3)     If Not Window("text:=Flight Reservation").Exist (7)= True Then

4)     QTP=Environment("ProductDir")

5)     Flight_app="\samples\flight\app\flight4a.exe"

6)     SystemUtil.Run QTP & Flight_app

7)     Dialog("text:=Login").Activate

8)     Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set "asdf"

9)     Dialog("text:=Login").WinEdit("attached text:=Password:").SetSecure "4aa5ed3daf680e7a759bee1c541939d3a54a5b65"

10) Dialog("text:=Login").WinButton("text:=OK").Click

11) End If

12) Window("text:=Flight Reservation").Activate

13) Window("text:=Flight Reservation").WinButton("window id:=6").Click

14) Window("text:=Flight Reservation").ActiveX("acx_name:=MaskEdBox","window id:=0").Type "090910"

15) f=Window("text:=Flight Reservation").WinComboBox("attached text:=Fly From:").GetItemsCount

16) For i= 0 to f-1 step 1

17) Window("text:=Flight Reservation").WinComboBox("attached text:=Fly From:").Select (i)

18) x=Window("text:=Flight Reservation").WinComboBox("attached text:=Fly From:").GetROProperty ("text")

19) t=Window("text:=Flight Reservation").WinComboBox("attached text:=Fly To:","x:=244","y:=147").GetItemsCount

20) For j= 0 to t-1 step 1

21) Window("text:=Flight Reservation").WinComboBox("attached text:=Fly To:","x:=244","y:=147").Select (j)

22) y=Window("text:=Flight Reservation").WinComboBox("attached text:=Fly To:","x:=244","y:=147").GetROProperty ("text")

23) If x <> y Then

24) Reporter.ReportEvent 0,"Res","Test Passed"

25) Else

26) Reporter.ReportEvent 1,"Res","Test Failed"

27) End If

28) Next

29) Next



4) Count, how many Buttons and Edit boxes available in Flight Reservation main window.


1)     If Not window("Flight Reservation").Exist (2) Then

2)     SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"

3)     Dialog("Login").Activate

4)     Dialog("Login").WinEdit("Agent Name:").Set "Gcreddy"

5)     Dialog("Login").WinEdit("Password:").Set "mercury"

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

7)     End If

8)     Set oDesc = Description.Create()

9)     oDesc("micclass").Value = "WinButton"

10) Set Buttons = Window("text:=Flight Reservation").ChildObjects (oDesc)

11) Num_Buttons = Buttons.Count()

12) Set oDesc1=Description.Create()

13) oDesc1("micclass").Value="WinEdit"

14) Set Editboxes=Window("text:=Flight Reservation").ChildObjects (oDesc1)

15) Num_Editboxes= editboxes.count ()

16) sum= Num_Buttons+Num_Editboxes

17) Reporter.ReportEvent 2, "Res","Total Buttons: "& Num_Buttons &"Total Edit boxes: "& Num_Editboxes



5) Count all opened Browsers on desktop and close all?

1)     Set oDesc = Description.Create()

2)     oDesc("micclass").Value = "Browser"

3)     Set Browsers =Desktop.ChildObjects (oDesc)

4)     NumberofBrowsers = Browsers.Count()

5)     Reporter.ReportEvent 2,"Res","Number of Browsers are: "&NumberOfBrowsers

6)     For Counter=0 to NumberofBrowsers-1

7)     Browsers(Counter).Close

8)     Next


6) Create an Excel file, enter some data and save the file through VB scripting?


1)     Dim objexcel

2)     Set objExcel = createobject("Excel.application")

3)     objexcel.Visible = True

4)     objexcel.Workbooks.add

5)     objexcel.Cells(1, 1).Value = "Testing"

6)     objexcel.ActiveWorkbook.SaveAs("f:\exceltest.xls")

7)     objexcel.Quit

   ************************************************

No comments:

Post a Comment