Determining the Values of Cells in a Table

When working with Java or HTML tables, you might want to extract the value of a given cell in the table. There are many ways to do this; one simple approach is to query the table directly.

The example shows how to create custom Java code that exploits the Functional Test object model to extract the information from an HTML table. The sample first uses the getTestData method to have Functional Tester return a TestDataTable object that contains all of the data in an HTML table. Given this data table, the getRowCount and getColumnCount methods determine the size of the HTML table. Finally, with these numbers, the code cycles through each cell and uses the getCell method to determine the contents of each cell in the table. The values in the cells display in the console window.

import resources.TableTestHelper;
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 TableTest extends TableTestHelper
{
/**
* Script Name : <b>TableTest</b>
* Generated : <b>Sep 27, 2005 2:54:34 PM</b>
* Modified : <b>Sep 27, 2005 2:54:34 PM</b>
* Description : Functional Tester Script
* Original Host : WinNT Version 5.0 Build 2195 (Service Pack 3)
*
* @since 2005/09/27
* @author Administrator
*/
public void testMain (Object[] args)
{
startApp("TableTest");

// Browser: MS Internet Explorer
// Document: Table Test Page: file:
//D:\Temp\TableTest.html

//Click on table to generate an object in the Object Map.
Table_AutoNumber1().click(atCell(
atRow(atIndex(1)), atColumn(
atIndex(1))));

//Query object to find out what kind of data it has.
System.out.println (Table_AutoNumber1().getTestDataTypes());

//Declare variable for table.
ITestDataTable myTable;
myTable = TestDataTable)Table_AutoNumber1().getTestData("grid");

//Print out total rows & columns.
System.out.println ("Total Rows: " + myTable.getRowCount());
System.out.println ("Total Cols: " + myTable.getColumnCount());

//Print out cell values.
for (int row =0;row < myTable.getRowCount();row++)
{
for (int col = 0;col < Table.getColumnCount();col++)
{
System.out.println("Value at cell (" + row+ "," + col+")
is: " + myTable.getCell(row,col));
}
}

Browser_htmlBrowser(Document_TableTestPage(),MAY_EXIT).close();
}
}

 

Terms of use | Feedback
(C) Copyright IBM Corporation 2002, 2004. All Rights Reserved.