1/26/11

VB Script User Defined Functions

i) Launching Application


Navigation:

a) Launch the Browser

b) 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”).Sync

Browser(“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” Then

Launch_App=”Jjperumes.com Browser Launched Sucessfully”

Msgbox Launch_App

Else

Launch_App=”Jjperumes.com Browser Not Launched”

Msgbox Launch_App

End If

End Function

——————————————————————————————–

ii) Customer Registration

Pre-Setup: Launching Application

Navigation:

a) Select Registration Link in jjperfumes.com homepage

b) Enter all Mandatory details

c) Select Submit button

Verify: Capture confirmation Message and Verify

Function Register(Email)

Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume”).Link(“Register”).Click

Browser(“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 Email

Browser(“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”).Click

Wait (5)

Confirm_Message = Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_3″).WebElement(“Registered successfully.”).GetROProperty(“innertext”)

If Confirm_Message=”Registered successfully. “Then

Register=”Customer Registration Sucessful”

Msgbox Register

Else

Register=”Registration Failed”

Msgbox Register

End If

End 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”).Click

myBrowser.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 Email

myBrowser.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”).Click

Wait (5)

Confirm_Message = Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_3″).WebElement(“Registered successfully.”).GetROProperty(“innertext”)

If Confirm_Message=”Registered successfully. “Then

Register=”Customer Registration Sucessful”

Msgbox Register

Else

Register=”Registration Failed”

Msgbox Register

End If

End Function

iii) Login Operation

Pre-Requisites:

a) Launching Application

b) Customer Registration

Navigation:

a) Select “Login” Link in jjperfumes.com homepage

b) Enter Email and Password

c) 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”).Click

Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“username”).Set Email

Browser(“JJ Perfumes-Discount perfume”).Page(“JJ Perfumes-Discount perfume_2″).WebEdit(“password”).Set Pwd

Browser(“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) Then

Login=”Login Operation Sucessful”

Msgbox Login

Else

Login=”Login Failed”

Msgbox Login

End If

End Function

iv) Closing Application

————————

Navigation:

————

a) Check the Existence of jjperfumes.com Browser

b) 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”).Sync

Browser(“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” Then

Launch_App=”Jjperumes.com Browser Launched Sucessfully”

Msgbox Launch_App

Else

Launch_App=”Jjperumes.com Browser Not Launched”

Msgbox Launch_App

End If

End 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”).Activate

Dialog(“Login”).WinEdit(“Agent Name:”).Set Agent

Dialog(“Login”).WinEdit(“Password:”).Set Password

wait 2

Dialog(“Login”).WinButton(“OK”).Click

If Window(“Flight Reservation”).Exist(12) Then

Window(“Flight Reservation”).Close

Login=”Login Operation Sucessful”

Msgbox Login

Else

SystemUtil.CloseDescendentProcesses

‘If Dialog(“Login”).Dialog(“Flight Reservations”).Exist(2) Then

‘Dialog(“Login”).Dialog(“Flight Reservations”).WinButton(“OK”).Click

‘Dialog(“Login”).WinButton(“Cancel”).Click

‘End if

Login=”Login Failed”

Msgbox Login

End if

End Function

———————————

vi) Open Order In Flight Reservation Application

Function Open_Order(Order_Number)

Window(“Flight Reservation”).Activate

Window(“Flight Reservation”).WinButton(“Button”).Click

Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”

Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set Order_Number

Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click

OrdNum = Window(“Flight Reservation”).WinEdit(“Order No:”).GetVisibleText()

OrdNum=CInt(OrdNum)

If OrdNum=Order_Number Then

Open_Order= Order_Number& ” Opened sucessfully”

Msgbox Open_Order

Else

Open_Order= Order_Number& ” Not Opened”

Msgbox Open_Order

End If

End Function

——————————————

vii) Update Order In Flight Reservation Application

Function Update_Order(Tickets)

Window(“Flight Reservation”).Activate

Window(“Flight Reservation”).WinButton(“Button”).Click

Window(“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”).Click

Window(“Flight Reservation”).WinEdit(“Tickets:”).Set Tickets

Window(“Flight Reservation”).WinButton(“Update Order”).Click

Wait (10)

Message = Window(“Flight Reservation”).ActiveX(“Threed Panel Control”).GetROProperty(“text”)

If Message=”Update Done…” Then

Update_Order=”Order Updated Sucessfully”

Msgbox Update_Order

Else

Update_Order=”Order Not Updated”

Msgbox Update_Order

End If

End Function

—————————————–

viii) ‘Write Function to Count how many Browsers opened 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

Browsers(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()

 
 

3 comments:

  1. FLIGHT Descriptive Programming Object repository in VB Script
    Dt: 01/11/2011
    1.1 How to Capture object properties in Vbs file?
    All FLIGHT application’s objects properties should be captured in the file FLIGHT_VbsObjRep.vbs. In the main function called “VbOrMainFunc(), we will pass two parameters, ObjCls and ObjectAliasName (eg. VbOrMainFunc(ObjCls,ObjectAliasName)).
    Using ObjCls parameter we pass the exact "Class name" property value of any object ( Pbwindow, Window, PbObject, Pbedit.......)

    Sample code of FLIGHT_ObjRep.vbs
    REM Vbs Object Repository For FLIGHT
    MaxArray = 400 REM 400 is the Maximum array range.

    Public Function VbOrMainFunc(ObjCls,ObjectAliasName)
    ObjName = Split(Trim(ObjectAliasName),",") REM Splitting the ObjAliasName with "," Delimiter
    ObjClsName = ObjName(0) REM ObjClsName - Contains the alias name
    REM Splitting the Classname with "," Delimiter and assign it to AppObjType
    AppObjType = Split("PbWindow,Window,PbObject,PbEdit,PbList,PbButton,PbLabel,winbutton,wincombobox,dialog,WinEdit,WinList,WinObject,VbWindow,ActiveX,WinRadioButton,PbEditor,PbRadioButton", ",")
    REM Array Declaration for function - All the functions are stored in array
    ObjFunc = Array("FetchMainWin(ObjClsName)","FetchWdw(ObjClsName)","FetchPbObj(ObjClsName)","FetchPbEdit(ObjClsName)","FetchPbList(ObjClsName)","FetchPbBtn(ObjClsName)","FetchPbLbl(ObjClsName)","FetchWinBtn(ObjClsName)","FetchWinCombx(ObjClsName)","FetchWinDlg(ObjClsName)","FetchWinedit(ObjClsName)","FetchWinList(ObjClsName)","FetchWinObject(ObjClsName)","FetchVbWindow(ObjClsName)","FetchActiveX(ObjClsName)","FetchWinRdBtn(ObjClsName)","FetchPbEditor(ObjClsName)","FetchPbRdBtn(ObjClsName)")

    REM The below code will search for the "Class Name" and it will call the respective function
    For i = 0 To UBound(AppObjType)
    If LCase(AppObjType(i)) = LCase(ObjCls) Then
    Objppt = Eval(ObjFunc(i))
    Exit For
    End If
    Next
    REM Assign the Dynamic Properties
    If LCase(Objppt) <> "fail" Then
    Set AppObj = Description.Create
    Objppt1 = Split(Objppt,",")
    For i = 0 To UBound(Objppt1)
    Objppt2 = Split(Objppt1(i),":=")
    If UBound(Objppt2) > 1 Then
    AppObj(Trim(Objppt2(0))).value = Trim(Objppt2(1))&":"
    Else
    AppObj(Trim(Objppt2(0))).value = Trim(Objppt2(1))
    End IF
    Next
    Set AppMainFunc = AppObj
    Else
    Set AppObj = Description.Create
    Set AppMainFunc = AppObj
    End If
    End Function
    REM Sample code of FLIGHTObjRep for Main window - REM This function (Array(1)) is to add all Pbwindow Properties.
    Public Function FetchMainWin(PbWinfetchtxt)
    ReDim mwdw(MaxArray,1)
    mwdw(0,0)="AppWindow"
    mwdw(0,1)="Class Name:=PbWindow,nativeclass:=FNWNS390,pbname:=w_login,regexpwndtitle:=Welcome"

    MainWindo = Checkppt(mwdw,PbWinfetchtxt)
    Erase mwdw
    FetchMainWin = MainWindo
    End Function
    REM Checkppt is the function to search for the Alias name in the array.
    Public Function Checkppt(ValArray,srchtxt)
    val =""
    For i = 0 To UBound(ValArray)
    If LCase(ValArray(i,0)) = LCase(srchtxt) Then
    val = ValArray(i,1)
    Exit For
    End If
    Next
    REM When alias name is found it return the property for that object, else it returns fail.
    If val <> "" Then
    Checkppt = val
    Else
    Checkppt ="Fail"
    End If
    End Function

    ReplyDelete
  2. 1.2 How to write script using FLIGHT_vbsObjRep.vbs in UFT?
    FLIGHTObjRep.vbs contains the object properties of FLIGHT application. We use FLIGHTObjRep.vbs to write any action script. (eg. Launch application, Create member … close application.
    Sample Script to launch application:
    LaunchFLIGHT()
    Public Function LaunchFLIGHT() '//Launching the FLIGHT Application
    SystemUtil.Run "C:\Flight\Testing\ Flight.exe"," ","C:\Flight\Testing\",""
    Set oMainWin = PbWindow(VbOrMainFunc("PbWindow","AppWindow"))
    Do Until oMainWin.Exist
    Wait(1)
    Loop
    If oMainWin.Exist(1) then
    Reporter.ReportEvent 0, "Window Availability", "Window is Available"
    Else
    Reporter.ReportEvent 2, "Window Availability", "Window is NOT Available"
    End if
    End Function

    ReplyDelete
  3. The above Concept is the BEST AND FAST Object repository in Vbs, which is an Descriptive Programming.
    1. You need to keep adding the Class Name and Create respective function for it.
    2. In Function capture the object properties in array concept using alias name.
    3. This Vbs Object repository can be twiked to QTP, UFT, UFT with perfecto mobile for the Swf, Pb and Web.

    ReplyDelete