User Defined Functions
Visit:
www.gcreddy.com
for QTP Scripts
----------------------------------------------------------
i) Launching Application
Navigation: a) Launch the Browserb) Enter / Select the URL (“www.jjperfumes.com”)
Verification: Capture the Browser Name and Verify
—————
Function Launch_App()SystemUtil.Run “C:\Program Files\Internet Explorer\IEXPLORE.EXE”,”",”C:\Documents and Settings\Administrator”,”open”Browser(“Google”).Page(“Google”).SyncBrowser(“Google”).Navigate “http://www.jjperfumes.com/”Wait (8)Browser_Name = Browser(“Google”).GetROProperty(“title”)
If Browser_Name=”JJ Perfumes-Discount perfume cheap brand name perfumes, fragrance & cologne online” ThenLaunch_App=”Jjperumes.com Browser Launched Sucessfully”Msgbox Launch_AppElseLaunch_App=”Jjperumes.com Browser Not Launched”Msgbox Launch_AppEnd IfEnd Function
——————————————————————————————–
ii) Customer Registration
Pre-Setup: Launching Application
Navigation: a) Select Registration Link in jjperfumes.com homepageb) Enter all Mandatory detailsc) Select Submit button
Verify: Capture confirmation Message and Verify
Function Register(Email)Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume”).Link(“Register”).ClickBrowser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebList(“usertype”).Select “Retailer”Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“firstname”).Set “dfgdg”Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“lastname”).Set “dgdfgdfg”Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebList(“gender”).Select “Male”Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“address1″).Set “dfgfdgf”Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“phone”).Set “9222222223″Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“email”).Set EmailBrowser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“city”).Set “chennai”Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebList(“state”).Select “MS – MISSISSIPPI”Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“zip”).Set “23456″Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“password”).SetSecure “3c30bbc7daa0dccb83c2941bb87fa0709d34″Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“conPass”).SetSecure “3c30bbcdb1f7a32d27a56f70a60f7d1e4159″Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebButton(“Submit”).ClickWait (5)Confirm_Message = Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_3″).WebElement(“Registered successfully.”).GetROProperty(“innertext”)
If Confirm_Message=”Registered successfully. “ThenRegister=”Customer Registration Sucessful”Msgbox RegisterElseRegister=”Registration Failed”Msgbox RegisterEnd IfEnd Function
——————-
Function Register(Email)Set myBrowser=Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″)Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume”).Link(“Register”).ClickmyBrowser.WebList(“usertype”).Select “Retailer”myBrowser.WebEdit(“firstname”).Set “dfgdg”myBrowser.WebEdit(“lastname”).Set “dgdfgdfg”myBrowser.WebList(“gender”).Select “Male”myBrowser.WebEdit(“address1″).Set “dfgfdgf”myBrowser.WebEdit(“phone”).Set “9222222223″myBrowser.WebEdit(“email”).Set EmailmyBrowser.WebEdit(“city”).Set “chennai”myBrowser.WebList(“state”).Select “MS – MISSISSIPPI”myBrowser.WebEdit(“zip”).Set “23456″myBrowser.WebEdit(“password”).SetSecure “3c30bbc7daa0dccb83c2941bb87fa0709d34″myBrowser.WebEdit(“conPass”).SetSecure “3c30bbcdb1f7a32d27a56f70a60f7d1e4159″myBrowser.WebButton(“Submit”).ClickWait (5)Confirm_Message = Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_3″).WebElement(“Registered successfully.”).GetROProperty(“innertext”)
If Confirm_Message=”Registered successfully. “ThenRegister=”Customer Registration Sucessful”Msgbox RegisterElseRegister=”Registration Failed”Msgbox RegisterEnd If
End Function
iii) Login Operation
Pre-Requisites:a) Launching Applicationb) Customer RegistrationNavigation:a) Select “Login” Link in jjperfumes.com homepageb) Enter Email and Passwordc) Select “Login Button”Verify: Check existence of LogOut Link
—————–
Function Login(Email, Pwd)Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume”).Link(“Login”).ClickBrowser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“username”).Set EmailBrowser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“password”).Set PwdBrowser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebButton(“Login”).Click
If Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_3″).Link(“Logout”).Exist(10) ThenLogin=”Login Operation Sucessful”Msgbox LoginElseLogin=”Login Failed”Msgbox LoginEnd IfEnd Function
iv) Closing Application
————————Navigation:————a) Check the Existence of jjperfumes.com Browserb) Close the Browser window (If exists)—————–
Function Launch_App()SystemUtil.Run “C:\Program Files\Internet Explorer\IEXPLORE.EXE”,”",”C:\Documents and Settings\Administrator”,”open”Browser(“Google”).Page(“Google”).SyncBrowser(“Google”).Navigate “http://www.jjperfumes.com/”Wait (8)Browser_Name = Browser(“Google”).GetROProperty(“title”)
If Browser_Name=”JJ Perfumes-Discount perfume cheap brand name perfumes, fragrance & cologne online” ThenLaunch_App=”Jjperumes.com Browser Launched Sucessfully”Msgbox Launch_AppElseLaunch_App=”Jjperumes.com Browser Not Launched”Msgbox Launch_AppEnd IfEnd Function
**********************************************************
v) Login Operation In Flight Reservation Application
Function Login (Agent, Password)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”).ActivateDialog(“Login”).WinEdit(“Agent Name:”).Set AgentDialog(“Login”).WinEdit(“Password:”).Set Passwordwait 2Dialog(“Login”).WinButton(“OK”).ClickIf Window(“Flight Reservation”).Exist(12) ThenWindow(“Flight Reservation”).CloseLogin=”Login Operation Sucessful”Msgbox LoginElseSystemUtil.CloseDescendentProcesses‘If Dialog(“Login”).Dialog(“Flight Reservations”).Exist(2) Then‘Dialog(“Login”).Dialog(“Flight Reservations”).WinButton(“OK”).Click‘Dialog(“Login”).WinButton(“Cancel”).Click‘End ifLogin=”Login Failed”Msgbox LoginEnd ifEnd Function———————————
vi) Open Order In Flight Reservation Application
Function Open_Order(Order_Number)Window(“Flight Reservation”).ActivateWindow(“Flight Reservation”).WinButton(“Button”).ClickWindow(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set Order_NumberWindow(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).ClickOrdNum = Window(“Flight Reservation”).WinEdit(“Order No:”).GetVisibleText()OrdNum=CInt(OrdNum)If OrdNum=Order_Number ThenOpen_Order= Order_Number& ” Opened sucessfully”Msgbox Open_OrderElseOpen_Order= Order_Number& ” Not Opened”Msgbox Open_OrderEnd IfEnd Function——————————————
vii) Update Order In Flight Reservation Application
Function Update_Order(Tickets)Window(“Flight Reservation”).ActivateWindow(“Flight Reservation”).WinButton(“Button”).ClickWindow(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set “2″Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).ClickWindow(“Flight Reservation”).WinEdit(“Tickets:”).Set TicketsWindow(“Flight Reservation”).WinButton(“Update Order”).ClickWait (10)Message = Window(“Flight Reservation”).ActiveX(“Threed Panel Control”).GetROProperty(“text”)
If Message=”Update Done…” ThenUpdate_Order=”Order Updated Sucessfully”Msgbox Update_OrderElseUpdate_Order=”Order Not Updated”Msgbox Update_OrderEnd IfEnd Function—————————————–
viii) ‘Write Function to Count how many Browsers opened on desktop and close them all
Function Close_Browsers()Dim oBrowser, Browsers, TotBrowsers, iSet oBrowser=Description.CreateoBrowser(“micclass”).Value=”Browser”Set Browsers=Desktop.ChildObjects(oBrowser)TotBrowsers=Browsers.CountMsgbox TotBrowsersFor i= 0 to TotBrowsers-1 Step 1Browsers(i).closeNextEnd Function—————————
ix) ‘Write Function to Count how many Buttons available in FR Window
Function Count_Buttons()Dim oButton, Buttons, TotButtons, iSet oButton=Description.CreateoButton(“Class Name”).Value=”WinButton”Set Buttons=Window(“text:=Flight Reservation”).ChildObjects(oButton)TotButtons=Buttons.CountMsgbox TotButtonsEnd FunctionCall Count_Buttons()—————————–
x) ‘Write Function to Count how many Objects available in FR Window by specified Test Object class
Function Count_Objects(Object)Dim obj, Objects, TotObjects, iSet obj=Description.Createobj(“Class Name”).Value=ObjectSet Objects=Window(“text:=Flight Reservation”).ChildObjects(obj)TotObjects=Objects.CountMsgbox TotObjectsEnd FunctionCall Count_Objects(“WinRadioButton”)Call Count_Objects(“WinButton”)Call Count_Objects(“WinEdit”)Call Count_Objects(“WinComboBox”)——————————–
xi) ‘Write function to capture all button names one by one from Login Dialog Box
Function Capture_Buttons()Dim oButton, Buttons, TotButtons, i, myButtonSet oButton=Description.CreateoButton(“Class Name”).Value=”WinButton”Set Buttons=Dialog(“text:=Login”).ChildObjects(oButton)TotButtons=Buttons.Count
For i= 0 to TotButtons-1myButton=Buttons(i).GetRoProperty(“text”)Msgbox myButtonNextEnd FunctionCall Capture_Buttons()——————————————xii) ‘Write function to Count Howmany Links available in Google Homepage
Function Count_Links()Dim oLink, Links, TotLinks, iSet oLink=Description.CreateoLink(“micclass”).Value=”Link”Set Links=Browser(“title:=Google”).Page(“title:=Google”).ChildObjects(oLink)TotLinks=Links.CountMsgbox TotLinksEnd FunctionCall Count_Links()
——————————————————————————-
Functions in QTP
User Defined Functions
Functions in VB Script
gcreddy@gcreddy.com
1
QTP Training
Description
User defined Functions for QTP Testing. This document describes Sub procedures, Function Procedures.
Presentation Transcript
Your Facebook Friends on WizIQ