Table
CukeTest provides Table and TableItem controls for tables in Linux 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 |
|---|---|
| columnHeaders | Gets the column headers of the table. |
| rowHeaders | Gets the row headers of the table. |
| cellValue | Gets the value of a specified cell. |
| data | Gets all data from the entire table. |
| getItem | Gets the object of a specified cell. |
| findItem | Finds a cell containing specified text. |
| rowData | Gets all data from a specified row. |
| select | Selects a specified cell. |
| rowCount | Gets the total number of rows in the table. |
| columnCount | Gets the total number of columns in the table. |
Type Definitions
export interface IAtTable extends IAtControl {
columnHeaders(): Promise<string[]>;
rowHeaders(): Promise<string[]>;
cellValue(rowIndex: number, columnNameOrIndex: number | string): Promise<string>;
data(): Promise<string[][]>;
getItem(rowIndex: number, columnIndex: number): IAtTableItem;
findItem(text: string, options?: {exact?: boolean}): Promise<IAtTableItem | null>;
rowData(rowIndex: number): Promise<string[]>;
select(rowIndex: number, columnIndex: number): Promise<IAtTableItem>;
rowCount(): Promise<number>;
columnCount(): Promise<number>;
}class AtTable(AtControl):
def columnHeaders() -> List[str]
def cellValue(rowIndex: int, columnNameOrIndex: Union[str, int]) -> str
def data() -> List[List[str]]
def getItem(rowIndex: int, columnIndex: int) -> AtTableItem
def findItem(text: str, options: Optional[FindItemOptional]=None) -> AtTableItem
def rowData(rowIndex: int) -> List[str]
def select(rowIndex: int, columnIndex: int) -> AtTableItem
def rowCount() -> int
def columnCount() -> int
columnHeaders()
Gets the column headers of the table.
Return Value:
Promise<string[]>type, asynchronously returns an array of column headers for the table.
Sample Code
Get the column headers of the table:
let headers = await model.getTable("table").columnHeaders();
console.log(`Column headers: ${headers.join(", ")}`);headers = model.getTable("table").columnHeaders()
print(f"Column headers: {', '.join(headers)}")rowHeaders()
Gets the row headers of the table.
Return Value:
Promise<string[]>type, asynchronously returns an array of row headers for the table.
Sample Code
Get the row headers of the table:
let headers = await model.getTable("table").rowHeaders();
console.log(`Row headers: ${headers.join(", ")}`);headers = model.getTable("table").rowHeaders()
print(f"Row headers: {', '.join(headers)}")cellValue(rowIndex, columnNameOrIndex)
Gets the value of a specified cell.
Parameters:
- rowIndex:
numbertype, the row position index of the target cell, starting from 0. - columnNameOrIndex:
numbertype orstringtype, the column position index or column header of the target cell.
Return Value:
Promise<string>type, asynchronously returns the value of the target cell.
Sample Code
Get the value of a specified cell:
let value = await model.getTable("table").cellValue(0, 1);
console.log(`Cell value: ${value}`);value = model.getTable("table").cellValue(0, 1)
print(f"Cell value: {value}")data()
Gets all data from the entire table, returned as a two-dimensional array.
Return Value:
Promise<string[][]>type, asynchronously returns a two-dimensional array of the table.
Sample Code
Get all data from the entire 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:
IAtTableItemtype, 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)findItem(text, options?)
Finds a cell containing specified text.
Parameters:
- text:
stringtype, the text to find in the target cell. - options:
{exact?: boolean}type, optional parameter, whether to match exactly.
Return Value:
Promise<IAtTableItem | null>type, asynchronously returns the found cell object ornull.
Sample Code
Find a cell containing specified text:
let item = await model.getTable("table").findItem("Search Text", {exact: true});item = model.getTable("table").findItem("Search Text", {"exact": True})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)}")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<IAtTableItem>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)rowCount()
Gets the total number of rows in the table.
Return Value:
Promise<number>type, asynchronously returns the total number of rows in the table.
Sample Code
Get the total number of rows in the table:
let count = await model.getTable("table").rowCount();
console.log(`Total rows: ${count}`);count = model.getTable("table").rowCount()
print(f"Total rows: {count}")columnCount()
Gets the total 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>type, asynchronously returns the total number of columns in the table.
Sample Code
Get the total number of columns in the table:
let count = await model.getTable("table").columnCount();
console.log(`Total columns: ${count}`);count = model.getTable("table").columnCount()
print(f"Total columns: {count}")Cell Control: TableItem
CukeTest provides a series of APIs for cell controls (TableItem) in Linux 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 IAtTableItem extends IAtControl {
data(): Promise<string>;
set(value: string): Promise<void>;
rowIndex(): Promise<number>;
columnIndex(): Promise<number>;
}class AtTableItem(AtControl):
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("tableitem").data();
console.log(`Cell data: ${cellData}`);cell_data = model.getTableItem("tableitem").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("tableitem").set("New Data");model.getTableItem("tableitem").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("tableitem").rowIndex();
console.log(`Row index: ${rowIndex}`);row_index = model.getTableItem("tableitem").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("tableitem").columnIndex();
console.log(`Column index: ${columnIndex}`);column_index = model.getTableItem("tableitem").columnIndex()
print(f"Column index: {column_index}")