다음 예는 Classics Java™ 애플리케이션에 대해 테스트합니다.
import resources.GetGridDataExampleHelper; 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 GetGridDataExample extends GetGridDataExampleHelper { /** * Script Name : GetGridDataExample * Generated : Jul 14, 2006 3:05:22 PM * Description : Functional Test Script * Original Host : WinNT Version 5.1 Build 2600 (S) * * @since 2006/07/14 * @author Administrator */ public void testMain (Object[] args) { // Start Classics Java Application 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")); ok().click(); // Frame: View Existing Orders existingTable().click(atPoint(172,92)); //Get the data for the table ITestDataTable orderTable = (ITestDataTable)existingTable().getTestData("contents"); //Display the available data types for the grid, total rows and columns. System.out.println ("Available Data Types: " + existingTable().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 close().click(); // Frame: ClassicsCD classicsJava(ANY,MAY_EXIT).close(); } }
이 예는 애플리케이션의 "기존 주문 보기" 화면으로 이동합니다. 이 샘플의 코드는 눈금의 모든 셀에서 값을 추출하고 이를 콘솔 창에 표시합니다.
데이터를 추출하는 첫 단계는 getTestData 메소드를 사용하여 제어에서 데이터를 추출하는 것입니다. 이것은 다음과 같은 구문으로 수행됩니다.
ITestDataTable orderTable; orderTable = (ITestDataTable)existingTable(). getTestData("contents");
이 데이터 세트가 제공된 경우 getRowCount 및 getColumnCount 메소드를 사용하여 총 행 및 열 수를 결정할 수 있습니다. 또한 getTestDataTypes을 사용하여 테이블에서 사용 가능한 데이터 유형의 제어를 요청할 수도 있습니다. 다음 코드는 이러한 조회 결과를 콘솔 창에 보냅니다.
System.out.println ("Available Data Types: " + existingTable().getTestDataTypes()); System.out.println ("Total Rows in table : " + orderTable.getRowCount()); System.out.println ("Total Cols in table : " + orderTable.getColumnCount());
다음 단계는 각 셀의 값을 인쇄하는 것인데 이는 눈금의 행과 열을 순환하는 for 루프를 사용하여 수행됩니다.
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) ); } }
이 예제 스크립트는 getCell 메소드를 사용하여 현재 셀 값을 인쇄합니다. getColumnHeader 메소드는 현재 열 헤더를 인쇄합니다. 눈금으로 작업할 때 행과 열의 번호는 0부터 시작합니다. 이것은 1부터 번호가 시작되는 getRowCount 및 getColumnCount 메소드에는 적용되지 않습니다.