Search This Blog

Sunday, November 20, 2011

Flex:- Function for selecting the item from the spark dropdown list.

'*******************************************************************************************************************************
' Name: Fun_SelectDropdownListValue
' Purpose: This function is used for selecting the item from the spark dropdown list
' Argument(s):
'     ip_ObjDropDown: Object under the test EX: SparkDropDownList
'     ip_strDropdownName: Name of the dropdown ex:Merchandise
'     ip_strSelectableItemValue: Value to be selected from the dropdown. Ex: All Mdse
' Returns:
'     1: If expected value is found under the dropdown
'     0: If expected value is NOT found under the dropdown
' Example: Call Fun_SelectDropdownListValue(objDropdown, "Merchandise", "All Mdse")
'------------------------------------------------------------------------------------------------------------*******************************************************************************************************************************
Public Function Fun_SelectDropdownListValue(ByRef ip_ObjDropDown, ip_strDropdownName, ip_strSelectableItemValue)
 Dim objDicListIndex, intTotalItemCnt, blnScrollBarExists, intMaxScrollValue, intCurrentScrollPoint
 Dim objSparkListLabelDescr, objSparkListLabelDescrChild
 Dim intChildIndex, strListLabel
 Set objDicListIndex = CreateObject("Scripting.Dictionary")
 '<<< Validate the current selection before making a new selection >>>
 strListLabel = ip_ObjDropDown.GetROProperty("selecteditem")
 If Trim(strListLabel) = Trim(ip_strSelectableItemValue) Then
  Fun_SelectDropdownListValue = 1
  Exit Function
 End If 

 'Get the total items under the list
 intTotalItemCnt = ip_ObjDropDown.GetItemsCount
 '<<< Get the maximum possible scroll point based on the existence of scroll bar object >>>
 ip_ObjDropDown.Open
 Wait 2
 If ip_ObjDropdown.SparkScrollBar("verticalScrollBar").Exist(2) Then
  blnScrollBarExists = True
        intMaxScrollValue = ip_ObjDropDown.SparkScrollBar("verticalScrollBar").GetROProperty("maximum")
 Else
  blnScrollBarExists = False
  intMaxScrollValue = 0
 End If 

 '<<< Get all child objects of type SparkListLabel >>>
 Set objSparkListLabelDescr = Description.Create()
 objSparkListLabelDescr("automationclassname").Value = "SparkListLabel"
 '<<< Extract all child objects until the maximum scroll point is reached >>>
 Do
  '<<< Move the scroll bar based on the child objects extracted within the loop >>>
  If blnScrollBarExists = True Then
   intCurrentScrollPoint = 20 * objDicListIndex.Count
   ip_ObjDropDown.SparkScrollBar("verticalScrollBar").Change intCurrentScrollPoint
   Wait 2
  Else
   intCurrentScrollPoint = 1
  End If 
  '<<< Get child objects >>>
  Set objSparkListLabelDescrChild = ip_ObjDropDown.ChildObjects(objSparkListLabelDescr)
  '<<< Fill the dictionary object based on the child objects extracted >>>>
  For intChildIndex = 0 To objSparkListLabelDescrChild.Count -1
   strListLabel = objSparkListLabelDescrChild(intChildIndex).GetROProperty("label")
   
   If Trim(strListLabel) = Trim(ip_strSelectableItemValue) Then
    objSparkListLabelDescrChild(intChildIndex).Click
    Fun_SelectDropdownListValue = 1 'Indicates success
    Exit Function
   ElseIf Not objDicListIndex.Exists(Trim(strListLabel)) And Trim(strListLabel) <> "" Then
    objDicListIndex.Add Trim(strListLabel), objDicListIndex.Count
   End If
  Next
  '<<< Exit the Loop on scroll bar reaching the maximum end point >>>
  If intCurrentScrollPoint > intMaxScrollValue Then
   Exit Do
  End If     
 Loop 
 subJCP_EventReport "Fail", "Unable to find item as: " & ip_strSelectableItemValue & " under the given dropdown: " & ip_strDropdownName, Browser("FlexApp")    
 Fun_SelectDropdownListValue = 0 'Indicates failure
End Function
'<<< ---------- Register this function to the SparkDropdownList object ----------- >>>
RegisterUserFunc "SparkDropDownList", "Fun_SelectDropdownListValue", "Fun_SelectDropdownListValue"
Example:-

returnValue = .SparkDropDownList("timeDropDown").Fun_SelectDropdownListValue("Time", "Custom...")
  If Cstr(returnValue) <> "1" Then
       ExitComponentIteration
  End If

No comments:

Post a Comment