Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced QTP. Topics 1.User Defined Function and Sub Procedure 2.Verify that database is updated successfully 3.Method Overriding 4.Using file functions.

Similar presentations


Presentation on theme: "Advanced QTP. Topics 1.User Defined Function and Sub Procedure 2.Verify that database is updated successfully 3.Method Overriding 4.Using file functions."— Presentation transcript:

1 Advanced QTP

2 Topics 1.User Defined Function and Sub Procedure 2.Verify that database is updated successfully 3.Method Overriding 4.Using file functions 5.Access database through script 6.Win32api functions 7.Reading and writing to an external xls file 8.Descriptive Programming 9.Creating Classes 10.Batch tests and Additional 11.Q and A ( )

3 User Defined Function ExecuteFile "D:\Testlib.vbs“ Window("Book_ticket").Activate Window("Book_ticket").WinEdit("Date of Flight:").Set "12/12/12" Window("Book_ticket").WinComboBox("Fly From:").Select "Denver" Window("Book_ticket").WinComboBox("Fly To:").Select "London" Window("Book_ticket").WinButton("FLIGHT").Click Window("Book_ticket").Dialog("Flights Table").WinButton("OK").Click Window("Book_ticket").WinEdit("Tickets:").Set "5" p = Window("Book_ticket").WinEdit("Price:").GetROProperty("text") tic = Window("Book_ticket").WinEdit("Tickets:").GetROProperty("text") total = Window("Book_ticket").WinEdit("Total:").GetROProperty("text") tic = cint(tic) p = cdbl(mid(p,2)) total = cdbl(mid(total,2)) func_total = check_total(tic,p) if(func_total = total) then msgbox("correct") else msgbox("incorrect") end if

4 function check_total(tic,p) check_total = tic*p end function sub flight_check(A) dep = Window("Book_ticket").WinComboBox("Fly From:").GetROProperty("selection") arr = Window("Book_ticket").WinComboBox("Fly To:").GetROProperty("selection") fl = Window("Book_ticket").WinEdit("Flight No:").GetROProperty("text") dt = Window("Book_ticket").WinEdit("Departure Time:").GetROProperty("text") at = Window("Book_ticket").WinEdit("Arrival Time:").GetROProperty("text") al = Window("Book_ticket").WinEdit("Airline:").GetROProperty("text") p = Window("Book_ticket").WinEdit("Price:").GetROProperty("text") dep = ucase(mid(dep,1,3)) msgbox(dep) arr = ucase(mid(arr,1,3)) msgbox(arr) msgbox(A(0)&" "&fl&" "&A(1)&" "&dep&" "&A(2)&" "&dt&" "&A(3)&" "&arr&" "& A(4)&" "&at &" "& A(5)&" "&al &" "& A(7)&" "&p) if(trim(A(0))=trim(fl) and trim(A(1))=trim(dep) and trim(A(2))=trim(dt) and trim(A(3))=trim(arr) and trim(A(4))=trim(at) and trim(A(5))=trim(al) and trim(A(7))=trim(p)) then Reporter.ReportEvent micPass, "flight_details", "correct" else Reporter.ReportEvent 1, "flight_details", "incorrect" end if end sub Testlib.vbs

5 Sub Procedure Window("Book_ticket").Activate Window("Book_ticket").WinEdit("Date of Flight:").Set "12/12/12" Window("Book_ticket").WinComboBox("Fly From:").Select "Denver" Window("Book_ticket").WinComboBox("Fly To:").Select "London" Window("Book_ticket").WinButton("FLIGHT").Click fl_d = Window("Book_ticket").Dialog("Flights Table").WinList("From").GetROProperty("selection") Window("Book_ticket").Dialog("Flights Table").WinButton("OK").Click A = split(fl_d," ") flight_check(A)

6 Database Update Check using Database Output value Window("Book_ticket").Activate Window("Book_ticket").WinEdit("Date of Flight:").Set "12/12/12" Window("Book_ticket").WinComboBox("Fly From:").Select "Frankfurt" Window("Book_ticket").WinComboBox("Fly To:").Select "London" Window("Book_ticket").WinButton("FLIGHT").Click Window("Book_ticket").Dialog("Flights Table").WinButton("OK").Click Window("Book_ticket").WinEdit("Name:_2").Set "hello" Window("Book_ticket").WinButton("Insert Order").Click Window("Book_ticket").WinButton("Update Order").WaitProperty "enabled", True, cust_name = Window("Book_ticket").WinEdit("Name:_2").GetROProperty("text") or_no = Window("Book_ticket").WinEdit("Order No:").GetROProperty("text") fl_no = Window("Book_ticket").WinEdit("Flight No:").GetROProperty("text") ; query given = select * from orders where order_number = (Select MAX(order_number) from orders) DbTable("DbTable_6").Output CheckPoint("DbTable_6") or_num = DataTable.Value("or_no") cust = DataTable.Value("cust_name") flight = DataTable.Value("fl_no") If (or_no=or_num And cust=cust_name And fl_no=flight) Then Call msgbox("updated") Else Call msgbox("not updated") End If

7 Method Overriding -1 RegisterUserFunc "WinEdit", "Set","Myset" function Myset(obj,x) dim y y = obj.GetROProperty("text") if(y = "") then Reporter.ReportEvent micPass, "check for empty", "it is blank" else Reporter.ReportEvent 1, "check for empty", "there ia a value "&y end if Myset = obj.set(x) end function Window("Book_ticket").Activate Window("Book_ticket").WinObject("Button").Click 15,14 Window("Book_ticket").WinEdit("Date of Flight:").Set "12/12/12" Window("Book_ticket").WinComboBox("Fly From:").Select "Denver" Window("Book_ticket").WinComboBox("Fly To:").Select "London" Window("Book_ticket").WinObject("FLIGHT").VirtualButton("V_flight").Click Window("Book_ticket").Dialog("Flights Table").WinButton("OK").Click Window("Book_ticket").WinEdit("Name:_2").Set "hello" Window("Book_ticket").WinButton("Insert Order").Click

8 Method Overriding -2 RegisterUserFunc "WinComboBox","SelectOnIndex","select1" RegisterUserFunc "WinList","SelectOnIndex","select1" function select1(obj,x) dim y y = obj.GetItem(x) select1 = obj.select(y) end function Window("Book_ticket").Activate Window("Book_ticket").WinEdit("Date of Flight:").Set "12/12/12" Window("Book_ticket").WinComboBox("Fly From:").SelectOnIndex 4 Window("Book_ticket").WinComboBox("Fly To:").SelectOnIndex 3 Window("Book_ticket").WinObject("FLIGHT").VirtualButton("V_flig ht").Click Window("Book_ticket").Dialog("Flights Table").WinList("From").SelectOnIndex 2 msgbox("wait") Window("Book_ticket").Dialog("Flights Table").WinButton("OK").Click Window("Book_ticket").WinEdit("Name:_2").Set "ghfjhghj"

9 Using File functions Const ForReading = 1, ForWriting = 2 Dim fso, MyFile Set fso = CreateObject("Scripting.FileSystemObject") Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForWriting, True) MyFile.WriteLine "Hello world!" MyFile.WriteLine "The quick brown fox1" MyFile.WriteLine "The quick brown fox2" MyFile.WriteLine "The quick brown fox3" MyFile.WriteLine "The quick brown fox4" MyFile.Close Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForReading) Do While MyFile.AtEndOfStream <> True retstring = MyFile.ReadLine msgbox retstring Loop MyFile.close

10 Access database through script Window("Book_ticket").Activate Window("Book_ticket").WinEdit("Date of Flight:").Set DataTable("Date", dtGlobalSheet) Window("Book_ticket").WinComboBox("Fly From:").Select DataTable("From", dtGlobalSheet) Window("Book_ticket").WinComboBox("Fly To:").Select DataTable(“To", dtGlobalSheet) Window("Book_ticket").WinButton("FLIGHT").Click Window("Book_ticket").Dialog("Flights Table").WinButton("OK").Click Window("Book_ticket").WinEdit("Name:_2").Set DataTable("Name", dtGlobalSheet) Window("Book_ticket").WinButton("Insert Order").Click Window("Book_ticket").WinButton("Update Order").WaitProperty "enabled",True,10000 ono = Window("Book_ticket").WinEdit("Order No:").GetROProperty("text") Window("Book_ticket").WinMenu("Menu").Select "File;New Order" Call db_check(ono) Function db_check (ono) Set con = createobject("ADODB.connection") con.open "QT_Flight32" Set rs = con.Execute("select max(order_number)from orders") test = Cstr(rs.fields("order_number").value) 'Set rs = con.Execute("select * from orders where order_number="+test) 'test = Cstr(rs.fields(0).value) If (ono=test) Then Reporter.ReportEvent micPass,"database","updated" Else Reporter.ReportEvent 1,"database"," not updated" End If End Function

11 Win32api functions Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString Dim hWnd 'will contain the return value hWnd = Extern.FindWindow(null, "Untitled - Notepad") 'Display a message if the window is found If hWnd > 0 then MsgBox "Window was found." End if ;A collection of code, housing Windows features, hidden inside ;dynamic link library (DLL) files, for example: ;kernel32.dll ;Advapi32.dll ;User32.dll ; Extern.Declare (RetType, MethodName, LibName, Alias [[, ArgType(s)],...]) ;* Alias is not obligatory. If you substitute "" for the value of Alias, ; QuickTest takes the function name and uses it as the Alias.

12 Reading and writing to an external xls file Function db_check (name1) Set con = createobject("ADODB.connection") con.open "QT_Flight32" Set rs = con.Execute("select * from orders where customer_name like '"+name1+"%'") count1 = 0 rs.movefirst while(rs.EOF<>true) count1=count1+1 rs.movenext wend DataTable.GlobalSheet.AddParameter "OR_NUM",count1 DataTable.GlobalSheet.AddParameter "NAME",”razia” rs.movefirst for i =1 to count1-1 or_no1 = Cstr(rs.fields(0).value) name11 = Cstr(rs.fields("customer_name").value) DataTable.Value("OR_NUM")= or_no1 DataTable.Value("NAME")= name11 rs.movenext DataTable.SetCurrentRow(i) next count2 = count1-1 db_check = count2 End Function

13 Reading and writing to an external xls file DataTable.Import ("C:\sonali.xls“) name1="razia" count2 = db_check (name1) DataTable.Export ("C:\sonali.xls") Window("Book_ticket").Activate Window("Book_ticket").WinMenu("Menu").Select "File;Open Order..." Window("Book_ticket").Dialog("Open Order").WinCheckBox("Customer Name").Set "ON" Window("Book_ticket").Dialog("Open Order").WinEdit("Edit_2").Set "razia" Window("Book_ticket").Dialog("Open Order").WinButton("OK").Click count_app = Window("Book_ticket").Dialog("Open Order").Dialog("Search Results").WinList("Flight No.").GetROProperty("items count") Window("Book_ticket").Dialog("Open Order").Dialog("Search Results").WinButton("OK").Click msgbox (count_app) If (count_app = count2) then msgbox(“pass”) Else msgbox(“fail”) EndIf

14 Descriptive Programming set WnFlights = Window("regexpwndtitle:=Flight Reservation", "regexpwndclass:=Afx:") set Eddof = WnFlights.WinEdit("nativeclass:=MSMaskWndClass","attached text:=Date of Flight:") set CbFlyFrom =WnFlights.WinComboBox("nativeclass:=ComboBox","attached text:=Fly From:") set CbflyTo =WnFlights.WinComboBox("nativeclass:=ComboBox","attached text:=Fly To:") set BtFlights =WnFlights.WinObject("nativeclass:=Button","text:=FLIGHT") set EdFlightNo = WnFlights.WinEdit("nativeclass:=Edit","attached text:= Flight No:") set EdDept= WnFlights.WinEdit("nativeclass:=Edit","attached text:=Departure Time:") set EdArrt = WnFlights.WinEdit("nativeclass:=Edit","attached text:=Arrival Time:") set EdAl = WnFlights.WinEdit("nativeclass:=Edit","attached text:=Airline:") set EdName = WnFlights.WinEdit("nativeclass:=Edit","attached text:=Name:") set EdTickets = WnFlights.WinEdit("nativeclass:=Edit","attached text:=Tickets:") set EdPrice = WnFlights.WinEdit("nativeclass:=Edit","attached text:=Price:") set EdTotal = WnFlights.WinEdit("nativeclass:=Edit","attached text:=Total:") set EdOrderno = WnFlights.WinEdit("nativeclass:=Edit","attached text:=Order No:") set BtInsO =WnFlights.WinButton("nativeclass:=Button","text:=&Insert Order") set BtUpdO =WnFlights.WinButton("nativeclass:=Button","text:=&Update Order") set BtDelO =WnFlights.WinButton("nativeclass:=Button","text:=&Delete Order") Set WnFlightsTable=Window("nativeclass:=#32770", "text:=Flights Table") Set LsFlights=WnFlightsTable.WinList("nativeclass:=ListBox","text:=From") SetBtOk =WnFlightsTable.WinButton("nativeclass:=Button","text:=OK") SetBtCancel =WnFlightsTable.WinButton("nativeclass:=Button","text:=Cancel") WnFlights.Activate Eddof.set "12/12/12" CbFlyFrom.select "Denver" CbFlyTo.select "Paris" BtFlights.Click WnFlightsTable.Activate BtOk.click EdName.set "Razia" BtInsO.Click

15 Creating Classes ExecuteFile "D:\flightsobject.vbs" class flights public function Insert_order() WnFlights.Activate Eddof.set "12/12/12" CbFlyFrom.select "Denver" CbFlyTo.select "Paris" BtFlights.Click WnFlightsTable.Activate BtOk.click EdName.set "Razia" BtInsO.Click Insert_order = 1 End function End class dim flights1 set flights1 = new flights a = flights1.Insert_order msgbox a

16 Batch tests and Additional ; USE TEST BATCH RUNNER and add tests to them ; Make reusable actions and call them dim date1 date1 = date msgbox date1 date2 = date date2 = now msgbox date2 MyTime = Time msgbox MyTime mon=datepart("m",date1) day1=datepart("d",date1) year1=datepart("yyyy",date1) msgbox mon & day1 & year1 Environment.LoadFromFile("D:\MyVariables.ini") Environment.Value("name1")= “razia" MyValue=Environment.Value("destination") ;content of environmental files ;[Environment] ;destination = denver

17 Q and A Thank You Siba Ram Baral


Download ppt "Advanced QTP. Topics 1.User Defined Function and Sub Procedure 2.Verify that database is updated successfully 3.Method Overriding 4.Using file functions."

Similar presentations


Ads by Google