Iterating through table cells using the GetTestData method
This topic provides an example of
using Rational® Functional Tester's GetTestData
method to access the
values in the cells of a grid control.
The 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 GetGridDataExample
Inherits GetGridDataExampleHelper
'Script Name : GetGridDataExample
'Generated : Jul 17, 2006 2:51:15 PM
'Description : Functional Test Script
'Original Host : Windows XP x86 5.1 build 2600 Service Pack 2
'since 2006/07/17
'author Administrator
Public Function TestMain(ByVal args() As Object) As Object
StartApp("ClassicsJavaA")
' Navigate to Existing Order Grid
Jmb().WaitForExistence()
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()
' Wait for table to be created
ExistingTable().WaitForExistence()
' Get the data for the table
Dim OrderTable As ITestDataTable
OrderTable = ExistingTable().GetTestData("contents")
' Display the available data types for the grid, total rows and columns.
System.Console.WriteLine(String.Format("Available Data Types: {0}", ExistingTable().GetTestDataTypes()))
System.Console.WriteLine(String.Format("Total Rows in table : {0}", OrderTable.GetRowCount()))
System.Console.WriteLine(String.Format("Total Cols in table : {0}", OrderTable.GetColumnCount()))
' Cycle through all rows
Dim Row As Integer
For Row = 0 To OrderTable.GetRowCount() - 1
' Cycle through all columns
Dim Col As Integer
For Col = 0 To OrderTable.GetColumnCount() - 1
' Print out values of cells at (Row, Col) coordinates
System.Console.WriteLine(String.Format("Row {0}, {1}: {2}", Row, OrderTable.GetColumnHeader(Col), OrderTable.GetCell(Row, Col)))
Next Col
Next Row
' Close the frame
Close().Click()
' Shut down Classics Java Application
ClassicsJava(ANY, MAY_EXIT).Close()
Return Nothing
End Function
End Class
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:
Dim OrderTable As ITestDataTable
OrderTable = 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.Console.WriteLine(String.Format("Available Data Types: {0}", ExistingTable().GetTestDataTypes()))
System.Console.WriteLine(String.Format("Total Rows in table : {0}", OrderTable.GetRowCount()))
System.Console.WriteLine(String.Format("Total Cols in table : {0}", 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:
' Cycle through all rows
Dim Row As Integer
For Row = 0 To OrderTable.GetRowCount() - 1
' Cycle through all columns
Dim Col As Integer
For Col = 0 To OrderTable.GetColumnCount() - 1
' Print out values of cells at (Row, Col) coordinates
System.Console.WriteLine(String.Format("Row {0}, {1}: {2}", Row, OrderTable.GetColumnHeader(Col), OrderTable.GetCell(Row, Col)))
Next Col
Next Row
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.