Advanced qtp
Download
1 / 17

Advanced QTP - PowerPoint PPT Presentation


  • 118 Views
  • Uploaded on

Advanced QTP. Topics. User Defined Function and Sub Procedure Verify that database is updated successfully Method Overriding Using file functions Access database through script Win32api functions Reading and writing to an external xls file Descriptive Programming Creating Classes

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Advanced QTP' - colin-rhodes


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Topics

Topics

User Defined Function and Sub Procedure

Verify that database is updated successfully

Method Overriding

Using file functions

Access database through script

Win32api functions

Reading and writing to an external xls file

Descriptive Programming

Creating Classes

Batch tests and Additional

Q and A (3.36.14.46)


User defined function

User Defined Function

ExecuteFile "D:\Testlib.vbs“

Window("Book_ticket").ActivateWindow("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").ClickWindow("Book_ticket").Dialog("Flights Table").WinButton("OK").ClickWindow("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) thenmsgbox("correct")elsemsgbox("incorrect")endif


Testlib.vbs

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


Sub procedure

Sub Procedure

Window("Book_ticket").ActivateWindow("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").Clickfl_d = Window("Book_ticket").Dialog("Flights Table").WinList("From").GetROProperty("selection")Window("Book_ticket").Dialog("Flights Table").WinButton("OK").ClickA = split(fl_d," ")flight_check(A)


Database update check using database output value

Database Update Check using Database Output value

Window("Book_ticket").ActivateWindow("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").ClickWindow("Book_ticket").Dialog("Flights Table").WinButton("OK").ClickWindow("Book_ticket").WinEdit("Name:_2").Set "hello"Window("Book_ticket").WinButton("Insert Order").ClickWindow("Book_ticket").WinButton("Update Order").WaitProperty "enabled", True, 10000

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) ThenCallmsgbox("updated")ElseCallmsgbox("not updated")EndIf


Method overriding 1

Method Overriding -1

RegisterUserFunc "WinEdit", "Set","Myset"function Myset(obj,x)dim yy = obj.GetROProperty("text")if(y = "") thenReporter.ReportEvent micPass, "check for empty", "it is blank"elseReporter.ReportEvent 1, "check for empty", "there ia a value "&yendifMyset = obj.set(x)endfunctionWindow("Book_ticket").ActivateWindow("Book_ticket").WinObject("Button").Click 15,14Window("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").ClickWindow("Book_ticket").Dialog("Flights Table").WinButton("OK").ClickWindow("Book_ticket").WinEdit("Name:_2").Set "hello"Window("Book_ticket").WinButton("Insert Order").Click


Method overriding 2

Method Overriding -2

RegisterUserFunc "WinComboBox","SelectOnIndex","select1"RegisterUserFunc "WinList","SelectOnIndex","select1"function select1(obj,x)dim yy = obj.GetItem(x)select1 = obj.select(y)endfunctionWindow("Book_ticket").ActivateWindow("Book_ticket").WinEdit("Date of Flight:").Set "12/12/12"Window("Book_ticket").WinComboBox("Fly From:").SelectOnIndex 4Window("Book_ticket").WinComboBox("Fly To:").SelectOnIndex 3Window("Book_ticket").WinObject("FLIGHT").VirtualButton("V_flight").ClickWindow("Book_ticket").Dialog("Flights Table").WinList("From").SelectOnIndex 2msgbox("wait")Window("Book_ticket").Dialog("Flights Table").WinButton("OK").ClickWindow("Book_ticket").WinEdit("Name:_2").Set "ghfjhghj"


Using file functions

Using File functions

Const ForReading = 1, ForWriting = 2

Dim fso, MyFileSet 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)DoWhile MyFile.AtEndOfStream <> True retstring = MyFile.ReadLinemsgbox retstring Loop MyFile.close


Access database through script

Access database through script

Window("Book_ticket").ActivateWindow("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").ClickWindow("Book_ticket").Dialog("Flights Table").WinButton("OK").ClickWindow("Book_ticket").WinEdit("Name:_2").Set DataTable("Name", dtGlobalSheet)Window("Book_ticket").WinButton("Insert Order").ClickWindow("Book_ticket").WinButton("Update Order").WaitProperty "enabled",True,10000ono = 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) ThenReporter.ReportEvent micPass,"database","updated"ElseReporter.ReportEvent 1,"database"," not updated"EndIfEndFunction


Win32api functions

Win32api functions

Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micStringDim hWnd 'will contain the return valuehWnd = Extern.FindWindow(null, "Untitled - Notepad")'Display a message if the window is foundIf hWnd > 0thenMsgBox"Window was found."Endif

;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.


Reading and writing to an external xls file

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 = 0rs.movefirstwhile(rs.EOF<>true)count1=count1+1rs.movenextwendDataTable.GlobalSheet.AddParameter "OR_NUM" ,count1DataTable.GlobalSheet.AddParameter "NAME" ,”razia”

rs.movefirstfor i =1to count1-1or_no1 = Cstr(rs.fields(0).value)name11 = Cstr(rs.fields("customer_name").value)DataTable.Value("OR_NUM")= or_no1DataTable.Value("NAME")= name11rs.movenextDataTable.SetCurrentRow(i)nextcount2 = count1-1

db_check = count2

EndFunction


Reading and writing to an external xls file1

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").ActivateWindow("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").Clickcount_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").Clickmsgbox (count_app)

If (count_app = count2) then

msgbox(“pass”)

Else

msgbox(“fail”)

EndIf


Descriptive programming

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")Set BtOk =WnFlightsTable.WinButton("nativeclass:=Button","text:=OK")Set BtCancel =WnFlightsTable.WinButton("nativeclass:=Button","text:=Cancel")WnFlights.ActivateEddof.set "12/12/12"CbFlyFrom.select "Denver"CbFlyTo.select "Paris"BtFlights.ClickWnFlightsTable.ActivateBtOk.clickEdName.set "Razia"BtInsO.Click


Creating classes

Creating Classes

ExecuteFile "D:\flightsobject.vbs"class flightspublic function Insert_order()WnFlights.ActivateEddof.set "12/12/12"CbFlyFrom.select "Denver"CbFlyTo.select "Paris"BtFlights.ClickWnFlightsTable.ActivateBtOk.clickEdName.set "Razia"BtInsO.ClickInsert_order = 1EndfunctionEnd classdim flights1set flights1 = new flightsa = flights1.Insert_ordermsgbox a


Batch tests and additional

Batch tests and Additional

dim date1date1 = datemsgbox date1date2 = datedate2 = nowmsgbox date2MyTime = Timemsgbox MyTimemon=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

; USE TEST BATCH RUNNER and add tests to them

; Make reusable actions and call them


Q and a

Q and A

Thank You

Siba Ram Baral


ad