Determining the values of cells in a table
When working with 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 VB.NET code that exploits the Test UI object model to extract the information from a table. The sample first
uses the GetTestData
method to have Test UI return
a TestDataTable
object that contains all of the data in
a 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.
#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 TableTest
Inherits TableTestHelper
'Script Name : TableTest
'Generated : Jul 17, 2006 3:48:02 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().Click(AtPath("Order"))
Jmb().Click(AtPath("Order->View Existing Order Status..."))
' Frame: View Order Status
NameComboB().Click()
NameComboB().Click(AtText("Claire Stratus"))
OK2().Click()
' Frame: View Existing Orders
ExistingTable().Click(AtCell(AtRow("ORDER ID", "7", "ORDER DATE", "3/11/98", "STATUS", "Order Initiated"), AtColumn("ORDER ID")), AtPoint(26, 12))
' Query object to find out what kind of data it has.
System.Console.WriteLine(ExistingTable().GetTestDataTypes().ToString())
' Declare variable for table.
Dim MyTable As ITestDataTable
MyTable = ExistingTable().GetTestData("contents")
' Print out total rows & columns.
System.Console.WriteLine(String.Format("Total Rows: {0}", MyTable.GetRowCount()))
System.Console.WriteLine(String.Format("Total Cols: {0}", MyTable.GetColumnCount()))
' Print out cell values.
Dim Row As Integer
For Row = 0 To MyTable.GetRowCount() - 1
Dim Col As Integer
For Col = 0 To MyTable.GetColumnCount() - 1
System.Console.WriteLine(String.Format("Value at cell {0}, {1}, {2}: {3}", ("Row"), ("Col"), ("is"), MyTable.GetCell(Row, Col)))
Next Col
Next Row
Close().Click()
' Shut down ClassicsJava application
ClassicsJava(ANY, MAY_EXIT).Close()
Return Nothing
End Function
End Class