Tuesday, October 5, 2010

VBScript to verify that the specified object exists on the current page

Public Function verifyExistence(ObjectType, ObjectName, ExpStatus)
'********************************************
' Author : Chinmay Mudholkar
' Purpose : Verify that the specified object exists on the current page
' Inputs : ObjectType: The type of object based upon its micClass
'  ObjectName: The HTML name of that object
'  ExpStatus: The expected status of the object
' Returns : Boolean value.  The current status of the object.
'********************************************

Dim Status

Select Case ObjectType
  Case "Link"
Status = Browser("title:=.*").Page("title:=.*").Link("name:=" & ObjectName, "Index:=0").Exist(5)
Case "Image"
Status = Browser("title:=.*").Page("title:=.*").Image("alt:=" & ObjectName).Exist(5)
Case "WebElement"
Status = Browser("title:=.*").Page("title:=.*").WebElement("innertext:=" & ObjectName & ".*","index:=0").Exist(5)
Case "WebList"
Status = Browser("title:=.*").Page("title:=.*").WebList("name:=" & ObjectName).Exist(5)
Case "WebTable"
Status = Browser("title:=.*").Page("title:=.*").WebTable("innertext:=" & ObjectName & ".*","index:=0").Exist(8)
Case "Browser"
Status = Browser("CreationTime:=" & ObjectName).Exist(5)
Case "WebEdit"
Status = Browser("title:=.*").Page("title:=.*").WebEdit("name:=" & ObjectName).Exist(5)
Case "WebButton"
Status = Browser("title:=.*").Page("title:=.*").Webbutton("name:=" & ObjectName,"index:=0").Exist(5)
Case "WebRadioGroup"
Status = Browser("title:=.*").Page("title:=.*").WebRadioGroup("name:=" & ObjectName).Exist(5)
Case "WebCheckBox"
Status = Browser("title:=.*").Page("title:=.*").WebCheckBox("name:=" & ObjectName).Exist(5)
Case Else
Status = False
End Select

If CBool(Status) = CBool(ExpStatus) Then
verifyExistence = True
Else
verifyExistence = False
End If

Set Status = Nothing

End Function

No comments:

Post a Comment