Extracting data from a ComboBox/List control

You can use Rational® Functional Tester's GetTestData method to access the values in the list of a ComboBox/List control.

The following example tests against the Classics Java application:

#Region " Script Header "
' Functional Test Script
' author Administrator
Imports Microsoft.VisualBasic
Imports Rational.Test.Ft
Imports Rational.Test.Ft.Object.Interfaces
Imports Rational.Test.Ft.Object.Interfaces.SAP
Imports Rational.Test.Ft.Object.Interfaces.Siebel
Imports Rational.Test.Ft.Script
Imports Rational.Test.Ft.Value
Imports Rational.Test.Ft.Vp
#End Region

Public Class GetListDataExample 
		Inherits GetListDataExampleHelper

    'Script Name   : GetListDataExample
    'Generated     : Jun 29, 2006 3:14:01 PM
    'Description   : Functional Test Script
    'Original Host : Windows XP x86 5.1 build 2600 Service Pack 2 

    'since  2006/06/29
    'author Administrator

    Public Function TestMain(ByVal args() As Object)
        StartApp("ClassicsJavaA")

 

        'Frame: ClassicsCD
        Tree2().Click(AtPath("Composers->Schubert->Location(PLUS_MINUS)"))
        Tree2().Click(AtPath("Composers->Schubert->Die schone Mullerin, Op. 25"))
        PlaceOrder().Click()

 

        'Declare variables for list
        Dim nameList As ITestDataList
        Dim nameListElements As ITestDataElementList
        Dim nameListElement As ITestDataElement

 

        ' Frame: Member Logon
        NameCombo().WaitForExistence()

 

        'Available test data types: {selected=Selected List Element,
        ' list=List Elements}
        Dim Ht As System.Collections.Hashtable = NameCombo().GetTestDataTypes()
        System.Console.WriteLine(Ht)

 

        ' Get all elements
        Dim testdata As ITestData

        nameList = CType(NameCombo().GetTestData("list"), TestDataList)

        nameListElements = nameList.GetElements()

        Dim ListElemCount As Integer
        ListElemCount = nameList.GetElementCount()

 

        Dim I As Integer
        For I = 0 To ListElemCount - 1
            nameListElement = nameListElements.GetElement(I)

            System.Console.WriteLine(nameListElement.GetElement().ToString())

            'Click on each element
            NameCombo().Click()
            NameCombo().Click(AtText(nameListElement.GetElement().ToString()))
        Next I

 

        'Frame: Member Logon
        Cancel().Click()

 
        'Frame: ClassicsCD
        ClassicsJava(ANY,MAY_EXIT).Close()
    End Function
 

    End Class

This example first opens up the Classics Java application. It selects a composer in the tree and an album (composer = Schubert, album = "Die Schone Muellerin") and clicks the "Place Order" button. In the next screen (Member Login - dialog) the sample code extracts the list of values from the ComboBox and displays them in the console window before clicking on each list element.

The first step is to extract the data from the control by using the GetTestData method:


Dim testdata As ITestData

nameList = CType(NameCombo().GetTestData("list"), TestDataList)

To find out which data types are available for a control, use the following code:


Dim Ht As System.Collections.Hashtable = NameCombo().GetTestDataTypes()

System.Console.WriteLine(Ht)

Given this data set, you can create an array that contains all of the elements of the list. This is done as follows:


Dim nameListElements As ITestDataElementList
nameListElements = nameList.GetElements()

With the list elements in hand, you can create a loop that accesses each list element. To determine the number of list elements, use the GetElementCount method. To extract the value of the list element, the GetElement method is used. In the example, this is done with the following code:


Dim ListElemCount As Integer
        ListElemCount = nameList.GetElementCount()


Dim I As Integer
  For I = 0 To ListElemCount - 1
  		nameListElement = nameListElements.GetElement(I)

    System.Console.WriteLine(nameListElement.GetElement().ToString())

    'Click on each element
    NameCombo().Click()
    NameCombo().Click(AtText(nameListElement.GetElement().ToString()))
	Next I