Relevant Codes

A Test Development Resource for HP QuickTest Professional.

QTP: Working with SiebPickLists

by Anshoo Arora on August 10, 2009

A SiebPickList object closely resembles a List object (WebList) in a Web based environment. A good reference for SiebPickList apart from the QTP help can be found here. Do not confuse a PickList with a SiebList object – they are very different in the way they work, and the latter is much more complex.

In our environment, there are many many SiebPickLists. A good majority of these PickLists are not required fields, but according to the requirements, random values must be selected; ie. the fields cannot be left blank. Since selecting random items in some PickLists does not impact the process, the following can be used to accomplish this task.

Selecting a random value in SiebPickList
The below function can be used to select a random value from the SiebPickList object:

'—————————————————————————————————————————
' Name: Function SiebPickListRandomSelect
' 
' Purpose: Randomly selects an item in a PickList object
' 
' Input:
'  oSiebApplet - object reference to the SiebApplet hierarchy
'  pValUINameSiebPickList - uiname property's value for the SiebList object
' 
' Output
'  Object
' 
' Date:
' 
' Author: Anshoo Arora
' 
' Remarks: 
'—————————————————————————————————————————
Sub SiebPickListRandomSelect( byRef oSiebApplet, pValUINameSiebPickList )
'—————————————————————————————————————————
    'A pick list in a Siebel test automation environment.

    Dim iCnt, i, vNextItemByIndex
 
    If InStr(1, pValUINameSiebPickList, "uiname") <> 0 Then
        pValUINameSiebPickList = Trim(Split(pValUINameSiebPickList, ":=")(1))
    End If
 
    With oSiebApplet.SiebPicklist("uiname:=" & pValUINameSiebPickList)
 
        ' Check if PickList is enabled
        If .IsEnabled Then
            ' Check if PickList is required
            If Not .IsRequired Then
                .Select "#" & RandomNumber.Value(0, .Count - 1)
            Else
                Reporter.ReportEvent micWarning, pValUINameSiebPickList, "Cannot" &_
                " Random Select. Field is Required."
            End If
        Else
            Reporter.ReportEvent micWarning, pValUINameSiebPickList, "Cannot" &_
            " Random Select. Field is disabled."
        End If
 
    End With
 
End Function

Getting all objects of a SiebPickList in a Collection
For required PickLists, I usually check if the item that is to be selected exists before making the selection. Following is how you can retrieve all the items of the PickList in a collection:

'—————————————————————————————————————————
' Name: Function SiebPickListGetAllItems
' 
' Purpose: Retrieve names of all items in a Collection from the PickList object
' 
' Input:
'  oSiebApplet - object reference to the SiebApplet hierarchy
'  pValUINameSiebPickList - uiname property's value for the SiebList object
' 
' Output
'  Collection 
' 
' Dependancy:
'  SiebPickListGetItemsCnt
' 
' Date:
' 
' Author: Anshoo Arora
' 
' Remarks: 
'—————————————————————————————————————————
Function SiebPickListGetAllItems( byRef oSiebApplet, pValUINameSiebPickList )
'—————————————————————————————————————————
    'A pick list in a Siebel test automation environment.

    Dim iCnt, i, vNextItemByIndex
 
    Dim oDict: Set oDict = CreateObject( "Scripting.Dictionary" )
 
    If InStr(1, pValUINameSiebPickList, "uiname") <> 0 Then
        pValUINameSiebPickList = Trim(Split(pValUINameSiebPickList, ":=")(1))
    End If
 
    iCnt = oSiebApplet.SiebPicklist("uiname:=" & pValUINameSiebPickList).Count
 
    For i = 0 to iCnt - 1
        vNextItemByIndex = oSiebApplet.SiebPicklist("uiname:=" & pValUINameSiebPickList).GetItemByIndex(i)
        oDict.Add i+1, vNextItemByIndex
    Next
 
    Set SiebPickListGetAllItems = oDict
 
End Function

The concepts in this article apply strictly to Siebel v7.7

If you have any questions, please ask them in the comments section. If your query is confidential, please use the Contact Form to send me an e-mail instead.

Leave a Comment

Previous post:

Next post: