Friday, March 25, 2011

Script to verify the items exists in dropdown box

Public Function fnVerifyDropDownItems(objDropdown, strItemsToSearch)

Dim intItemsCount, intCounter, strItem, intItems, blnItemPresent
Dim arrItemsToSearch

fnVerifyDropDownItems=True

If (objDropdown.Exist = False) Then
reporter.report micFail,"The Dropdown box '" & objDropdown.GetROProperty("name") & "' should Exist", "The Dropdown Box does not exist", "FAIL")
fnVerifyDropDownItems=False
Exit Function
End If

'''''''' Get count of items in dropdown''''''''''''''''''
intItemsCount = objDropdown.GetTOProperty("items count")

''''''''Split the list items list based on comma(,)''''''
arrItemsToSearch = Split(strItemsToSearch, ",")
For intItems=0 to UBound(arrItemsToSearch)
blnItemPresent = False

''''''''''''Loop through all items''''''''''''''
For intCounter=1 to intItemsCount
strItem = ""

'''''''''' Get an item''''''''''''''''''
strItem = objDropdown.GetItem(intCounter)

'''''''''''''''If the search item is present'''''''''''''''''''''''
If (StrComp(Trim(strItem), Trim(arrItemsToSearch(intItems)), 1) = 0) Then
blnItemPresent = True
reporter.report micPass "The Item '" & arrItemsToSearch(intItems) & "' should be present in the dropdown box", "The specified Item exists in the dropdown box", "PASS")
Exit For
End If
Next
If (Not blnItemPresent) Then
reporter.report micFail , "The Item '" & arrItemsToSearch(intItems) & "' should be present in the dropdown box", "The specified Item does not exist in the dropdown box", "WARNING")
fnVerifyDropDownItems = False
End If
Next
End Function

No comments: