Table
CukeTest provides Table and TableItem controls for tables in Java applications, along with a rich set of APIs for getting and editing table data. These APIs can help you easily access and operate on any cell data in tables.
In addition to the table control-specific methods listed below, you can also use Common Control Methods to operate table controls more flexibly.
Table Control: Table
CukeTest provides a series of APIs for table controls in Linux applications to get and operate table data.
| Method Name | Description |
|---|---|
| clickCell | Clicks a cell. |
| cellValue | Gets the value of a cell. |
| setCellValue | Sets the value of a cell. |
| data | Gets all table content, returned as a two-dimensional array. |
| getItem | Gets the object of a specified cell. |
| rowData | Gets all data from a specified row. |
| columnData | Gets all data from a specified column. |
| select | Selects a specified cell. |
| columnHeaders | Gets the table headers. |
| rowCount | Gets the number of rows in the table. |
| columnCount | Gets the number of columns in the table. |
Type Definitions
export interface IQTable extends IQtControl {
clickCell(rowIndex: number, columnToFind: string | number);
cellValue(rowIndex: number, columnNameOrIndex: number | string): Promise<string>;
setCellValue(rowIndex: number, columnToFind: string | number, value: string);
data(): Promise<string[][]>;
getItem(rowIndex: number, columnIndex: number): IJTableItem;
rowData(rowIndex: number): Promise<string[]>;
columnData(nameOrIndex: string | number): Promise<string[]>;
select(rowIndex: number, columnIndex: number): Promise<IJTableItem>;
columnCount(): Promise<number>;
columnHeaders(): Promise<string[]>;
rowCount(): Promise<number>;
}class JTable(JControl):
def clickCell(rowIndex: int, columnToFind: Union[str, int]) -> any
def cellValue(rowIndex: int, columnNameOrIndex: Union[str, int]) -> str
def setCellValue(rowIndex: int, columnToFind: Union[str, int], value: str) -> any
def data() -> List[List[str]]
def getItem(rowIndex: int, columnIndex: int) -> JTableItem
def rowData(rowIndex: int) -> List[str]
def columnData(nameOrIndex: Union[str, int]) -> List[str]
def select(rowIndex: int, columnIndex: int) -> JTableItem
def columnCount() -> int
def columnHeaders() -> List[str]
def rowCount() -> intclickCell(rowIndex, columnToFind)
Clicks a cell in the table at the specified row and column.
Parameters:
- rowIndex:
numbertype, the row position index of the target cell, starting from 0. - columnToFind:
numbertype orstringtype, the column position index of the target cell, starting from 0. Can also pass the name of the target column in the header, such as "Name", "ID", etc.
Return Value:
- Asynchronous method that returns no value.
Sample Code
Click the cell in row 1, column 2:
let cellValue = await model.getTable("table").clickCell(0, 1);cell_value = model.getTable("table").clickCell(0, 1)cellValue(rowIndex, columnNameOrIndex)
Gets the value of a cell at the specified row and column in the table. This method is the corresponding Getter for setCellValue().
Parameters:
- rowIndex:
numbertype, the row position index of the target cell, starting from 0. - columnNameOrIndex:
numbertype orstringtype, the column position index of the target cell, starting from 0. Can also pass the name of the target column in the header, such as "Name", "ID", etc.
Return Value:
Promise<string>type, asynchronously returns the value of the target cell. If the row or column position is out of range, or if the passed column name does not exist, a1006: OutOfRangeerror will be thrown.
Sample Code
Get the value of the cell in row 1, column 2:
let cellValue = await model.getTable("table").cellValue(0, 1);
console.log(`Cell value: ${cellValue}`);cell_value = model.getTable("table").cellValue(0, 1)
print(f"Cell value: {cell_value}")setCellValue(rowIndex, columnNameOrIndex, value)
Sets the value of a cell at the specified row and column in the table. The column position can be passed as a column index or column name in the header.
Parameters:
- rowIndex:
numbertype, the row position index of the target cell, starting from 0. - columnNameOrIndex:
numbertype orstringtype, the column position index of the target cell, starting from 0. Can also pass the column name in the header, such as "Name", "ID", etc. - value:
stringtype, the desired cell value to set.
Return Value:
- Asynchronous method that returns no value. If the row or column position is out of range, or if the passed column name does not exist, a
1006: OutOfRangeerror will be thrown.
Sample Code
Set the value of the cell in row 1, column 2 to "New Value":
await model.getTable("table").setCellValue(0, 1, "New Value");model.getTable("table").setCellValue(0, 1, "New Value")data()
Gets all content from the table and returns it as a two-dimensional array.
Return Value:
Promise<string[][]>type, asynchronously returns a two-dimensional array of table data.
Assuming the table data is as follows:
| Student ID | Name | Gender |
|---|---|---|
| 0001 | Xiao Wang | Male |
| 0002 | Xiao Ming | Male |
| 0003 | Xiao Hong | Female |
Then the array returned by the data() method is as follows:
[
['0001', 'Xiao Wang', 'Male'],
['0002', 'Xiao Ming', 'Male'],
['0003', 'Xiao Hong', 'Female']
]
Sample Code
Get all data from the table:
let tableData = await model.getTable("table").data();
console.log(`Table data: ${JSON.stringify(tableData)}`);table_data = model.getTable("table").data()
print(f"Table data: {table_data}")getItem(rowIndex, columnIndex)
Gets the object of a specified cell.
Parameters:
- rowIndex:
numbertype, the row position index of the target cell, starting from 0. - columnIndex:
numbertype, the column position index of the target cell, starting from 0.
Return Value:
IJTableItemtype, returns the target cell object.
Sample Code
Get a specified cell object:
let item = model.getTable("table").getItem(0, 1);item = model.getTable("table").getItem(0, 1)rowData(rowIndex)
Gets all data from a specified row.
Parameters:
- rowIndex:
numbertype, the index of the target row, starting from 0.
Return Value:
Promise<string[]>type, asynchronously returns all data from the target row.
Sample Code
Get all data from a specified row:
let rowData = await model.getTable("table").rowData(0);
console.log(`Row data: ${rowData.join(", ")}`);row_data = model.getTable("table").rowData(0)
print(f"Row data: {', '.join(row_data)}")columnData(nameOrIndex)
Gets all data from a specified column.
Parameters:
- columnIndex:
numbertype, the index of the target column, starting from 0.
Return Value:
Promise<string[]>type, asynchronously returns all data from the target column.
Sample Code
Get all data from a specified column:
let columnData = await model.getTable("table").columnData(0);
console.log(`Column data: ${columnData.join(", ")}`);column_data = model.getTable("table").columnData(0)
print(f"Column data: {', '.join(column_data)}")select(rowIndex, columnIndex)
Selects a specified cell.
Parameters:
- rowIndex:
numbertype, the row position index of the target cell, starting from 0. - columnIndex:
numbertype, the column position index of the target cell, starting from 0.
Return Value:
Promise<IJTableItem>type, asynchronously returns the selected cell object.
Sample Code
Select a specified cell:
let item = await model.getTable("table").select(0, 1);item = model.getTable("table").select(0, 1)columnHeaders()
Gets all table headers and returns them as a string array.
Return Value:
Promise<string[]>type, asynchronously returns an array of header contents.
Sample Code
Get all table headers:
let headers = await model.getTable("table").columnHeaders();
console.log(`Headers: ${headers.join(", ")}`);headers = model.getTable("table").columnHeaders()
print(f"Headers: {', '.join(headers)}")rowCount()
Gets the number of rows in the table. Note that if the table contains unloaded parts, only loaded rows will be counted.
Return Value:
Promise<number>type, asynchronously returns the number of rows in the table.
Sample Code
Get the total number of rows in the table:
let rowCount = await model.getTable("table").rowCount();
console.log(`Table rows: ${rowCount}`);row_count = model.getTable("table").rowCount()
print(f"Table rows: {row_count}")columnCount()
Gets the number of columns in the table. This value is consistent with the length of the array returned by the columnHeaders() method.
Return Value:
Promise<number>, asynchronously returns anumbertype result.
Sample Code
Get the total number of columns in the table:
let columnCount = await model.getTable("table").columnCount();
console.log(`Table columns: ${columnCount}`);column_count = model.getTable("table").columnCount()
print(f"Table columns: {column_count}")Cell Control: TableItem
CukeTest provides a series of APIs for cell controls (TableItem) in Java applications to get and set cell data, as well as get the row and column indices of cells.
| Method Name | Description |
|---|---|
| data | Gets the data in the cell. |
| set | Sets the data in the cell. |
| rowIndex | Gets the row index of the cell. |
| columnIndex | Gets the column index of the cell. |
Type Definitions
export interface IJTableItem extends IJControl {
data(): Promise<string>;
set(value: string): Promise<void>;
rowIndex(): Promise<number>;
columnIndex(): Promise<number>;
}class JTableItem(JControl):
def data() -> str
def set(value: str) -> None
def rowIndex() -> int
def columnIndex() -> intdata()
Gets the data in the cell.
Return Value:
Promise<string>type, asynchronously returns the data in the cell.
Sample Code
Get the data in the cell:
let cellData = await model.getTableItem("itemName").data();
console.log(`Cell data: ${cellData}`);cell_data = model.getTableItem("itemName").data()
print(f"Cell data: {cell_data}")set(value)
Sets the data in the cell.
Parameters:
- value:
stringtype, the cell data to set.
Return Value:
- Asynchronous method that returns no value.
Sample Code
Set the data in the cell:
await model.getTableItem("itemName").set("New Data");model.getTableItem("itemName").set("New Data")rowIndex()
Gets the row index of the cell.
Return Value:
Promise<number>type, asynchronously returns the row index of the cell.
Sample Code
Get the row index of the cell:
let rowIndex = await model.getTableItem("itemName").rowIndex();
console.log(`Row index: ${rowIndex}`);row_index = model.getTableItem("itemName").rowIndex()
print(f"Row index: {row_index}")columnIndex()
Gets the column index of the cell.
Return Value:
Promise<number>type, asynchronously returns the column index of the cell.
Sample Code
Get the column index of the cell:
let columnIndex = await model.getTableItem("itemName").columnIndex();
console.log(`Column index: ${columnIndex}`);column_index = model.getTableItem("itemName").columnIndex()
print(f"Column index: {column_index}")