This example shows how to use Functional Tester's getTestData
method to access the values in the cells of a grid control. The example
tests against the Classics Java application:
import resources.GetGridDataExampleHelper;
import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;
/**
* Description : Functional Tester Script
* @author administrator
*/
public class GetGridDataExample extends GetGridDataExampleHelper
{
/**
* Script Name : <b>GetTreeDataExample</b>
* Generated : <b>Dec 14, 2002 6:24:48 AM</b>
* Modified : <b>Dec 14, 2002 6:24:48 AM</b>
* Description : Functional Tester Script
* Original Host : WinNT Version 5.0 Build 2195 (Service Pack 3)
*
* @since 2002/12/14
* @author administrator
*/
public void testMain (Object[] args)
{
// Turn off Log Viewer for this example
setOption(IOptionName.BRING_UP_LOGVIEWER, false);
// Start Classics Java Application
startApp("ClassicsJavaA");
// Navigate to Existing Order Grid
jmbMenuBar().waitForExistence();
jmbMenuBar().click(atPath("Order"));
jmbMenuBar().click(atPath("Order->View Existing Order Status..."));
// Frame: View Order Status
nameComboBComboBox().click();
nameComboBComboBox().click(atText("Claire Stratus"));
okstatuslogon2Button().click();
// Wait for table to be created
existingTableTable().waitForExistence();
// Get the data for the table
ITestDataTable orderTable;
orderTable
(ITestDataTable)existingTableTable().getTestData("contents");
// Display the available data types for the grid, total rows and
// columns.
System.out.println ("Available Data Types: " +
existingTableTable().getTestDataTypes())
System.out.println ("Total Rows in table : " +
orderTable.getRowCount());
System.out.println ("Total Cols in table : " +
orderTable.getColumnCount());
// Cycle through all rows
for (int row=0; row < orderTable.getRowCount();++row)
{
// Cycle through all columns
for (int col=0; col < orderTable.getColumnCount();++col)
{
// Print out values of cells at (row,col) coordinates
System.out.println ("Row " + row + ", " +
orderTable.getColumnHeader(col) + ": "
+orderTable.getCell(row,col) );
}
}
// Close the frame
closeorderButton().click();
// Shut down Classics Java Application
ClassicsJavaFrame(ANY,MAY_EXIT).close();
}
}
This example navigates to the "View Existing Orders" screen of the application. The code in this sample extracts the values from all cells in the grid and displays them in the console window.
The first step to extracting the data is to use the getTestData
method to extract the data from the control. This is done with the following
syntax:
ITestDataTable orderTable;
orderTable = (ITestDataTable)existingTableTable().
getTestData("contents");
Given this data set, you can determine the total number of rows and
columns by using the getRowCount
and getColumnCount
methods. You can also ask the control what data types are available from
the table using the getTestDataTypes
. The following code
sends the results of these queries to the console window.
System.out.println ("Available Data Types: " +
existingTableTable().getTestDataTypes());
System.out.println ("Total Rows in table : " +
orderTable.getRowCount());
System.out.println ("Total Cols in table : " +
orderTable.getColumnCount());		
The next step is to print out the values of the individual cells, which is done by using a for loop to cycle through the rows and columns of the grid:
for (int row=0; row < orderTable.getRowCount();++row)
{
// Cycle through all columns
for (int col=0; col < orderTable.getColumnCount();++col)
{
// Print out values of cells at (row,col) coords
System.out.println ("Row " + row + ", " +
orderTable.getColumnHeader(col) + ": " +
orderTable.getCell(row,col) );
}
}
The example script uses the getCell
method to print out the value of the current cell. Note also that the
getColumnHeader
method prints out the current column header.
When working with a grid, the numbering for both rows and columns starts
at 0. This does not apply to the getRowCount
and getColumnCount
methods where numbering starts at 1.
Terms of use | Feedback
(C) Copyright IBM Corporation 2002, 2004. All Rights Reserved.