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 a table. The sample first uses
the getTestData
method to have HCL OneTest™
UI return a TestDataTable
object
that contains all of the data in the table. Given this data table, the getRowCount
and getColumnCount
methods
determine the size of the 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.object.interfaces.SAP.*;
import com.rational.test.ft.object.interfaces.siebel.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;
/**
* Description : Functional Test Script
* @author Administrator
*/
public class TableTest extends TableTestHelper
{
/**
* Script Name : TableTest
* Generated : Jul 17, 2006 1:56:28 PM
* Description : Functional Test Script
* Original Host : WinNT Version 5.1 Build 2600 (S)
*
* @since 2006/07/17
* @author Administrator
*/
public void testMain(Object[] args)
{
startApp("ClassicsJavaA");
// Frame: ClassicsCD
jmb().click(atPath("Order"));
jmb().click(atPath("Order->View Existing Order Status..."));
// Frame: View Order Status
nameComboB().click();
nameComboB().click(atText("Claire Stratus"));
ok().click();
// Frame: View Existing Orders
existingTable().click(atCell(atRow("ORDER ID", "7", "ORDER DATE", "3/11/98", "STATUS", "Order Initiated"), atColumn("ORDER ID")), atPoint(33,2));
// Query object to find out what kind of data it has.
System.out.println (existingTable().getTestDataTypes());
//Declare variable for table.
ITestDataTable myTable;
myTable = (ITestDataTable)existingTable().getTestData("contents");
//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 < myTable.getColumnCount();col++)
{
System.out.println("Value at cell (" + row+ "," + col+")is: " + myTable.getCell(row,col));
}
}
close().drag();
// Frame: ClassicsCD
classicsJava(ANY,MAY_EXIT).close();
}
}