User Defined Functions

 User Defined Functions

 'Sub Procedure without Arguments

Call Login ()
Sub Login ()
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").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "4c43b0b3fe54c4e5051fe7ebcb7ba8b7c706a332"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
End Sub
--------------------------------------------
'Sub Procedure with Arguments
Sub Login (Agent, Pwd)
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").Activate
Dialog("Login").WinEdit("Agent Name:").Set Agent
Dialog("Login").WinEdit("Password:").Set Pwd
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
End Sub
Call Login ("Hyderabad","mercury")
------------------------------------------
'Loading resources directly during Run-Time

RepositoriesCollection.Add "Login.tsr"
ExecuteFile "FuncLib.vbs"
Call Login("abcd","mercury")
-------------------------------------------------

Closing all Opened Browsers on Desktop
Sub Close_Browsers()
   Dim oBrow
   Set oBrow=Description.Create
   oBrow("micclass").value="Browser"
   Set Browsers=Desktop.ChildObjects(oBrow)
   TotBrowsers=Browsers.Count
   'Msgbox TotBrowsers
   For i= 0 to TotBrowsers-1 step 1
Browsers(i).Close
   Next
End Sub
Call Close_Browsers()
-------------------------------------------------
'Count No of Links available in any Opended web page
Sub Count_Links()
   Dim oLink
   Set oLink=Description.Create
   oLink("micclass").value="Link"
   Set Links=Browser("title:=.*").Page("title:=.*").ChildObjects(oLink)
   TotLinks=Links.Count
   Msgbox TotLinks
  End Sub
Call Count_Links()
-------------------------------------------------

'Count No of Buttons available in Flight Reservation Window
Dim oButton
   Set oButton=Description.Create
   oButton("micclass").value="WinButton"
   Set Buttons=Window("text:=Flight Reservation").ChildObjects(oButton)
   TotButtons=Buttons.Count
   Msgbox TotButtons
-----------------------------------------------
''Function for Counting any given object type in a Window
Sub Count_Objects(obj)
Dim myObject
   Set myObject=Description.Create
   myObject("micclass").value=obj
   Set myObjects=Window("text:=Flight Reservation").ChildObjects(myObject)
   TotObjects=myObjects.Count
   Msgbox TotObjects
  End Sub
-------------------------------
Call Count_Objects("WinButton")
Call Count_Objects("WinEdit")
Call Count_Objects("WinComboBox")
------------------------------------------
''Function for Counting any given object type in a Webpage
Sub Count_Objects(obj)
Dim myObject
   Set myObject=Description.Create
   myObject("micclass").value=obj
   Set myObjects=Browser("title:=.*").Page("title:=.*").ChildObjects(myObject)
   TotObjects=myObjects.Count
   Msgbox TotObjects
  End Sub
---------------------------------------
Call Count_Objects("WebButton")
Call Count_Objects("WebEdit")
Call Count_Objects("Link")
---------------------------------------
''Function for Counting all objects in a Webpage
Sub Count_Objects()
Dim myObject
  ' Set myObject=Description.Create
   'myObject("micclass").value=obj
   Set myObjects=Browser("title:=.*").Page("title:=.*").ChildObjects
   TotObjects=myObjects.Count
   Msgbox TotObjects
  End Sub
------------------------------
Call Count_Objects()
--------------------------------------
'Function for Counting all objects in a Window
Sub Count_Objects()
Dim myObject
  ' Set myObject=Description.Create
   'myObject("micclass").value=obj
   Set myObjects=Window("text:=Flight Reservation").ChildObjects
   TotObjects=myObjects.Count
   Msgbox TotObjects
  End Sub
Call Count_Objects()
-------------------------------------------
Sub Count_Objects(x)
   'Const x="Flight Reservation"
Dim myObject
  ' Set myObject=Description.Create
   'myObject("micclass").value=obj
   Set myObjects=Window("text:="&x).ChildObjects
   TotObjects=myObjects.Count
   Msgbox TotObjects
  End Sub
Call Count_Objects("Flight Reservation")
--------------------------------------------
'***************************************************
Function Login (Agent, Pwd)
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").Activate
Dialog("Login").WinEdit("Agent Name:").Set Agent
Dialog("Login").WinEdit("Password:").Set Pwd
Dialog("Login").WinButton("OK").Click
If Window("Flight Reservation").exist(10) Then
    Login="Login Operation Sucessful"
    Reporter.ReportEvent 0, "Res","Login Operation Sucessful"
    Else
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
Dialog("Login").WinButton("Cancel").Click
    Login="Login Operation Failed"
    'Msgbox Login
    Reporter.ReportEvent 1, "Res","Login Operation Failed"
    End If
If Window("Flight Reservation").Exist (3) Then
    Window("Flight Reservation").Close
    End if
End Function
--------------------------------------------
 Function using call by Reference


Function Login ( ByRef var1, var2)
Agent="gcreddy": Pwd="mercury"
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").Activate
Dialog("Login").WinEdit("Agent Name:").Set Var1
Dialog("Login").WinEdit("Password:").Set var2
Wait 2
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
End Function
call Login (Agent, Pwd) 

------------------------------------------------
Function using call by Value

Function Login ( ByVal var)
      msgbox var
  End Function
 myname= "GcReddy"
 call Login (myname)



0 comments:

Post a Comment