Print Page | Close Window

Advanced QTP Functions

Printed From: One Stop Testing
Category: Testing Tools @ OneStopTesting
Forum Name: QuickTest Pro @ OneStopTesting
Forum Discription: QuickTest Pro is a fresh approach to automated software and application testing that addresses testing needs of both business analysts and Quality Assurance professionals.
URL: http://forum.onestoptesting.com/forum_posts.asp?TID=7221
Printed Date: 17Jun2024 at 4:40am


Topic: Advanced QTP Functions
Posted By: Mithi25
Subject: Advanced QTP Functions
Date Posted: 23Oct2009 at 10:57pm

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, 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) Then

Call msgbox("updated")

Else

Call msgbox("not updated")

End If

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

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_flight").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"

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

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

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.

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

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

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

Eddof.set "12/12/12"

CbFlyFrom.select "Denver"

CbFlyTo.select "Paris"

BtFlights.Click

WnFlightsTable.Activate

BtOk.click

EdName.set "Razia"

BtInsO.Click

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

Batch tests and Additional

; USE TEST BATCH RUNNER and add tests to them

; Make reusable actions and call them



-------------
http://www.quick2sms.com - Send Unlimited FREE SMS to Any Mobile Anywhere in INDIA,
Click Here



Print Page | Close Window