Friday, July 6, 2007

verify the Items exists in Dropdown box

'' Name : fnVerifyDropDownItems(objDropdown, strItemsToSearch)
'' Description: This function is used to verify whether the Items exists in Dropdown box
'' Arguments :
''objDropdown: Dropdown box object in which the items are to be searched
''strItemsToSearch:Items that are to be searched separated by Comma (,)
''Example: "Domestic, Canada"
''Return: True/False
''Pre-Condition:The Dropdown box should be displayed
''Post-condition:
''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

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

3 comments:

Computer said...

I want to get weblist items and compare it with some other list
Making sure that weblist populates correct data.
How this should done ?

Computer said...

In Flights Reservation application, i want to parameterise the Flights, which are
appearing in Flights Table.

Ex For a particular date, if we select Fly From - London, Fly To - Denver and click on
Flights.Flights table open which display different flights available.I want to verify that
the Flights with another Datatabl( or Excel Sheet) which also contain same Flights.

Unknown said...

Hi Sudhir,

QTP always returns TRUE even when webelement doesnt exists on the page. I have tried with html id and innertext. No luck... Please help ... Below is the code

Result = Browser("....").Page("....").Webelement("html id:=abc").Exist(0)
msgbox Result


I have tried using object spy (when weblement doesnt exists on the page), qtp opens the page but not highlighting anything. Does it means webelement exists on the page(like hidden). Please help to resolve this.