【软件自动化测试-QTP实战技能 23】== QTP 常用Functions

'Write Function to Count how many Browsers opend on desktop and close them all

Function Close_Browsers()
        Dim oBrowser,Browsers,TotBrowsers,i
        Set oBrowser = Description.Create
        oBrowser("micclass").Value = "Browser"
        Set Browsers = Desktop.ChildObjects(oBrowser)
        TotBrowsers = Browsers.Count
        Msgbox TotBrowsers
        
        For i = 0 to TotBrowsers-1 Step 1
            Browser(i).close
        Next
End Function


—————————
ix) ‘Write Function to Count how many Buttons available in FR Window

Function Count_Buttons()

Dim oButton, Buttons, TotButtons, i
Set oButton=Description.Create
oButton(“Class Name”).Value=”WinButton”
Set Buttons=Window(“text:=Flight Reservation”).ChildObjects(oButton)
TotButtons=Buttons.Count
Msgbox TotButtons
End Function

Call 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, i
Set obj=Description.Create
obj(“Class Name”).Value=Object
Set Objects=Window(“text:=Flight Reservation”).ChildObjects(obj)
TotObjects=Objects.Count
Msgbox TotObjects

End Function
Call 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, myButton
Set oButton=Description.Create
oButton(“Class Name”).Value=”WinButton”
Set  Buttons=Dialog(“text:=Login”).ChildObjects(oButton)
TotButtons=Buttons.Count
For i= 0 to TotButtons-1
myButton=Buttons(i).GetRoProperty(“text”)
Msgbox myButton
Next

End Function
Call Capture_Buttons()
'——————————————
xii) ‘Write function to Count Howmany Links available in Google Homepage
Function Count_Links()

Dim oLink, Links, TotLinks, i
Set oLink=Description.Create
oLink(“micclass”).Value=”Link”
Set  Links=Browser(“title:=Google”).Page(“title:=Google”).ChildObjects(oLink)
TotLinks=Links.Count
Msgbox TotLinks
End Function

Call Count_Links()
'——————————————————————————-



你可能感兴趣的:(function,测试,Google,Class,dialog,browser)