TestData types

The Functional Tester framework calls the getTestDataTypes() and getTestData(String) proxy methods for extracting data from controls for verification and reference. These methods are used during the creation and play back of data verification points. You can override the getTestDataTypes() method to add more specific data types for a control.

For example, a TextBox control can have text and selected-text as the supported data types. Each of these types is associated with a string name and description that the proxy defines. This name is passed to the getTestData(String) API for getting the control data. While implementing the getTestData(String) API, use the appropriate predefined data types and populate them with the control data and return them accordingly.


Class diagram

The following class diagram shows the predefined test data types that Functional Tester makes available:

The following predefined data types are some of the data types that you can use while implementing the getTestData() proxy API

TestDataText

The TestDataText type represents a string value.

This example code shows how to implement the TestDataText data type in Java :

import com.rational.test.ft.vp.ITestData;
import com.rational.test.ft.vp.impl.TestDataText;

ITestData testData =  null;
testData = new TestDataText( getSelectedText());
return testData ;

This example code shows how to implement the TestDataText data type in .Net:

Rational.Test.Ft.Vp.ITestData testData = null ;
object item = ((ComboBox)theTestObject).SelectedItem ;
testData = new Rational.Test.Ft.Vp.Impl.TestDataText(((ComboBox)theTestObject).GetItemText(item));
return testData;

TestDataList

The TestDataList type represents a list of items, for example items in a ListBox and a single column of a table.

This example code shows how to implement the TestDataList data type in Java:

import com.rational.test.ft.vp.ITestData;
import com.rational.test.ft.vp.impl.TestDataElementList;
import com.rational.test.ft.vp.impl.TestDataList;

Object[] items = getListItemObjects();
TestDataElementList testData = new TestDataElementList();
for ( int i = 0; i < items.length; i ++  )
{
  if ( items[i] != null )
  {
    testData.add(new TestDataElement(items[i], false));
    nonNullValueExist = true;
  }
  else
    testData.add(null);
}
return (new TestDataList(testData));

This example code shows how to implement the TestDataList data type in .Net:

Rational.Test.Ft.Vp.ITestData testData = null ;
string[] itemList = new string[((ComboBox)theTestObject).Items.Count] ;
for(int i=0; i < ((ComboBox)theTestObject).Items.Count; i++)
{
  object item = ((ComboBox)theTestObject).Items[i] ;

  if (item is string)
    itemList[i] = (string) item ;
  else
    itemList[i] = ((ComboBox)theTestObject).GetItemText(item) ;

}
testData = new Rational.Test.Ft.Vp.Impl.TestDataList(new Rational.Test.Ft.Vp.Impl.TestDataElementList(itemList)) ;
return testData;

TestDataTable

The TestDataTable type represents two-dimensional data that is contained in controls such as tables or grids.

This example code shows how to implement the TestDataTable data type in Java:

import com.rational.test.ft.vp.ITestData;
import com.rational.test.ft.vp.ITestDataTable;
import com.rational.test.ft.vp.impl.TestDataTable;
import com.rational.test.ft.vp.impl.TestDataTableRegion;
.
.
int rowCount = getRowCount();        
int colCount = getColumnCount();

object[] rowElements;
rowElements = new object[colCount];

for (int row = 0; row < rowCount; ++row)
{
  for (int col = 0; col < colCount; ++col)
  {
    object item = this.getItemText(row, col);
    if (item != null)
      rowElements[col] = item.ToString();
  }
  testData.add(rowElements);
}


for (int col = 0; col < colCount; ++col)
{
  object item = this.getColumnName(col);
  if (item != null)
    data.setColumnHeader(col, header);
}


testData.addComparisonRegion(TestDataTableRegion.allCells());
testData.setCompareBothByLeftRegions(true);

return testData;

This example code shows how to implement the TestDataTable data type in .Net:

Rational.Test.Ft.Vp.ITestData testData = null;
System.Data.DataTable dataTable = GetControlData();

int colCount = dataTable.Columns.Count;
int rowCount = dataTable.Rows.Count;

object[] rowElements;
rowElements = new object[colCount];

for (int row = 0; row < rowCount; ++row)
{
  for (int col = 0; col < colCount; ++col)
  {
    object item = null;
    item = dataTable.Rows[row][col];
    if (item != null)
      item = item.ToString();
    rowElements[col] = item;
  }
  testData.Add(rowElements);
}


for (int col = 0; col < colCount; ++col)
{
  string columnName = dataTable.Columns[col].ColumnName;
  if (columnName != null && !columnName.Equals(string.Empty))
    testData.SetColumnHeader(col, columnName);
}

testData.AddComparisonRegion(TestDataTableRegion.AllCells());
testData.SetCompareBothByLeftRegions(true);

return testData;

TestDataTree

The TestDataTree type represents a tree data structure.

This example code shows how to implement the TestDataTree data type in .Net:

public override Rational.Test.Ft.Vp.ITestData GetTestData(string testDataType)
{
.
.
  Rational.Test.Ft.Vp.ITestData testData = new TestDataTree(GetRootNodes());
  return testData;
.
.
}


private ITestDataTreeNodes GetRootNodes()
{
  System.Collections.ArrayList nodeCache = new System.Collections.ArrayList(80);
  System.Windows.Forms.TreeNodeCollection rootNodes = ((TreeView)this.theTestObject).Nodes;

  if ( rootNodes != null && rootNodes.Count > 0 )
  {
    for ( int i = 0; i < children.Length; ++i )
    {
      nodeCache.Add(GetNode(children[i], null));
    }
  }

  ITestDataTreeNode[] nodes = new TestDataTreeNode[nodeCache.Count];
  System.Array array = nodeCache.ToArray();
  for ( int i = 0; i < array.Length; ++i )
  {
    nodes[i] = (ITestDataTreeNode)array.GetValue(i);
  }
  TestDataTreeNodes testNodes = new TestDataTreeNodes(nodes);

  return testNodes;
}

// Gets called by GetRootNodes()

private ITestDataTreeNode GetNode(System.Object item, ITestDataTreeNode parent)
{
  String text = ((TreeNode)item).Text;
  ITestDataTreeAttributes attr = new TestDataTreeAttributes(text);
  ITestDataTreeNode node = new TestDataTreeNode(parent, text, null, false);

  System.Collections.ArrayList nodeCache = new System.Collections.ArrayList(20);

  System.Windows.Forms.TreeNodeCollection childrenNodes = ((TreeNode)item).Nodes;

  if ( childrenNodes != null && childrenNodes.Count > 0 )
  {
    int length = childrenNodes.Count;
    if ( length > 0 ) 
    {
      for ( int i = 0; i < length; ++i )
      {
        nodeCache.Add(GetNode(children[i], node));
      }
      int size = nodeCache.Count;
      if ( size > 0 )
      {
        ITestDataTreeNode[] childNodes = new ITestDataTreeNode[size];
        System.Array array = nodeCache.ToArray();
        for ( int i = 0;i < size; i ++ )
          childNodes[i] = (ITestDataTreeNode)array.GetValue(i);
        node.SetChildren(childNodes);
      }
    }
  }
  return node;
}