Tree

For tree controls and nodes in trees, CukeTest provides Tree and TreeItem controls. The Tree control represents the entire tree, while TreeItem represents individual nodes in the tree.

In addition to the tree control-specific methods listed below, you can also use Common Control Methods to operate tree controls more flexibly.

Tree View Control: Tree

Tree controls mainly operate on related nodes by passing in itemPath. Since node names are not unique, using node names as identifying properties is unreliable. The Model Manager provides an identifying property that describes the node's position—itemPath. You can click itemPath property to view the specific introduction.

Method Name Description
columnHeaders Gets the column headers of the tree.
getItem Gets the tree node object at the specified path.
rowData Gets the data of the node at the specified path.
childCount Gets the number of child nodes of the tree.
children Gets all child nodes of the tree.
columnCount Gets the total number of columns in the tree.
scrollToTop Scrolls to the top of the tree.
scrollToBottom Scrolls to the bottom of the tree.

Type Definitions

JavaScript
Python
export interface IAtTree extends IAtControl {
    columnHeaders(): Promise<string[]>;
    getItem(itemPath: ItemPath): IAtTreeItem;
    rowData(itemPath: ItemPath): Promise<string[]>;
    childCount(): Promise<number>;
    children(): Promise<IAtTreeItem[]>;
    columnCount(): Promise<number>;
    scrollToTop(): Promise<void>;
    scrollToBottom(): Promise<void>;
}
export type ItemPath = (number | string | [number, number])[];
class AtTree(AtControl):
    def columnHeaders() -> List[str]
    def getItem(itemPath: ItemPath) -> AtTreeItem
    def rowData(itemPath: ItemPath) -> List[str]
    def childCount() -> int
    def children() -> List[AtTreeItem]
    def columnCount() -> int
    def scrollToTop() -> None
    def scrollToBottom() -> None

columnHeaders()

Gets the column headers of the tree.

Return Value:

  • Promise<string[]> type, asynchronously returns an array of column headers for the tree.

Sample Code

Get the column headers of the tree:

JavaScript
Python
let headers = await model.getTree("tree").columnHeaders();
console.log(`Column headers: ${headers.join(", ")}`);
headers = model.getTree("tree").columnHeaders()
print(f"Column headers: {', '.join(headers)}")

getItem(itemPath)

Gets the tree node object at the specified path.

Parameters:

  • itemPath: ItemPath type, an array representing the tree node path, supporting numbers, strings, or [number, number] format.

Return Value:

  • IAtTreeItem type, returns the tree node object at the specified path.

Sample Code

Get the tree node object at the specified path:

JavaScript
Python
let item = model.getTree("tree").getItem([0, "Node Name", [2, 3]]);
item = model.getTree("tree").getItem([0, "Node Name", [2, 3]])

rowData(itemPath)

Gets the data of the node at the specified path.

Parameters:

  • itemPath: ItemPath type, an array representing the tree node path, supporting numbers, strings, or [number, number] format.

Return Value:

  • Promise<string[]> type, asynchronously returns an array of data for the node at the specified path.

Sample Code

Get the data of the node at the specified path:

JavaScript
Python
let data = await model.getTree("tree").rowData([0, "Node Name"]);
console.log(`Node data: ${data.join(", ")}`);
data = model.getTree("tree").rowData([0, "Node Name"])
print(f"Node data: {', '.join(data)}")

childCount()

Gets the number of child nodes of the tree.

Return Value:

  • Promise<number> type, asynchronously returns the number of child nodes of the tree.

Sample Code

Get the number of child nodes of the tree:

JavaScript
Python
let count = await model.getTree("tree").childCount();
console.log(`Number of child nodes: ${count}`);
count = model.getTree("tree").childCount()
print(f"Number of child nodes: {count}")

children()

Gets all child nodes of the tree.

Return Value:

  • Promise<IAtTreeItem[]> type, asynchronously returns an array of all child node objects of the tree.

Sample Code

Get all child nodes of the tree:

JavaScript
Python
let children = await model.getTree("tree").children();
children = model.getTree("tree").children()

columnCount()

Gets the total number of columns in the tree.

Return Value:

  • Promise<number> type, asynchronously returns the total number of columns in the tree.

Sample Code

Get the total number of columns in the tree:

JavaScript
Python
let count = await model.getTree("tree").columnCount();
console.log(`Total columns: ${count}`);
count = model.getTree("tree").columnCount()
print(f"Total columns: {count}")

scrollToTop()

Scrolls to the top of the tree.

Return Value:

  • Promise<void> type.

Sample Code

Scroll to the top of the tree:

JavaScript
Python
await model.getTree("tree").scrollToTop();
model.getTree("tree").scrollToTop()

scrollToBottom()

Scrolls to the bottom of the tree.

Return Value:

  • Promise<void> type.

Sample Code

Scroll to the bottom of the tree:

JavaScript
Python
await model.getTree("tree").scrollToBottom();
model.getTree("tree").scrollToBottom()


Tree Node Control: TreeItem

The TreeItem control represents individual nodes in the tree. You can expand, collapse, select them, and also get their child nodes, data, and other information. The following is a detailed introduction to the methods and properties of the TreeItem control.

Method Name Description
expand Expands the tree node.
collapse Collapses the tree node.
data Gets the data of the tree node.
set Sets the data of the tree node.
expandable Determines whether the tree node can be expanded.
expanded Determines whether the tree node is expanded.
childCount Gets the number of child nodes of the tree node.
children Gets all child nodes of the tree node.

Type Definitions

JavaScript
Python
export interface IAtTreeItem extends IAtControl {
    expand(): Promise<void>;
    collapse(): Promise<void>;
    data(roleId?: number): Promise<string>;
    set(value: string): Promise<void>;
    expandable(): Promise<boolean>;
    expanded(): Promise<boolean>;
    childCount(): Promise<number>;
    children(): Promise<IAtTreeItem[]>;
}

export enum ExpandCollapseState {
    collapsed = 0,
    expanded = 1,
    partiallyExpanded = 2,
    leafNode = 3,
    unknown = -1
}
class AtTreeItem(AtControl):
	def expand() -> None
	def collapse() -> None
	def data(roleId: Optional[int]=None) -> str
	def set(value: str) -> None
	def expandable() -> bool
	def expanded() -> bool
	def childCount() -> int
	def children() -> List[AtTreeItem]

expand()

Expands the current tree node.

Return Value:

  • Promise<void> type, asynchronous operation.

Sample Code

Expand a tree node:

JavaScript
Python
await model.getTreeItem("treeitem").expand();
model.getTreeItem("treeitem").expand()

collapse()

Collapses the current tree node.

Return Value:

  • Promise<void> type, asynchronous operation.

Sample Code

Collapse a tree node:

JavaScript
Python
await model.getTreeItem("treeitem").collapse();
model.getTreeItem("treeitem").collapse()

data(roleId?: number)

Gets the data of the current tree node.

Parameters:

  • roleId: number type, (optional) data role ID, used to get specific types of data.

Return Value:

  • Promise<string> type, asynchronously returns the data of the tree node.

Sample Code

Get the data of the tree node:

JavaScript
Python
let nodeData = await model.getTreeItem("treeitem").data();
console.log(`Node data: ${nodeData}`);
nodeData = model.getTreeItem("treeitem").data()
print(f"Node data: {nodeData}")

set(value: string)

Sets the data of the current tree node.

Parameters:

  • value: string type, the value to set.

Return Value:

  • Promise<void> type, asynchronous operation.

Sample Code

Set the data of the tree node:

JavaScript
Python
await model.getTreeItem("treeitem").set("New Value");
model.getTreeItem("treeitem").set("New Value")

expandable()

Determines whether the current tree node can be expanded.

Return Value:

  • Promise<boolean> type, asynchronously returns true if it can be expanded, false if it cannot.

Sample Code

Determine whether the tree node can be expanded:

JavaScript
Python
let isExpandable = await model.getTreeItem("treeitem").expandable();
console.log(`Expandable: ${isExpandable}`);
isExpandable = model.getTreeItem("treeitem").expandable()
print(f"Expandable: {isExpandable}")

expanded()

Determines whether the current tree node is expanded.

Return Value:

  • Promise<boolean> type, asynchronously returns true if it is expanded, false if it is not.

Sample Code

Determine whether the tree node is expanded:

JavaScript
Python
let isExpanded = await model.getTreeItem("treeitem").expanded();
console.log(`Expanded: ${isExpanded}`);
isExpanded = model.getTreeItem("treeitem").expanded()
print(f"Expanded: {isExpanded}")

childCount()

Gets the number of child nodes of the current tree node.

Return Value:

  • Promise<number> type, asynchronously returns the number of child nodes.

Sample Code

Get the number of child nodes of the tree node:

JavaScript
Python
let count = await model.getTreeItem("treeitem").childCount();
console.log(`Number of child nodes: ${count}`);
count = model.getTreeItem("treeitem").childCount()
print(f"Number of child nodes: {count}")

children()

Gets all child nodes of the current tree node.

Return Value:

  • Promise<IAtTreeItem[]> type, asynchronously returns an array of child nodes.

Sample Code

Get all child nodes of the tree node:

JavaScript
Python
let childrenItems = await model.getTreeItem("treeitem").children();
childrenItems = model.getTreeItem("treeitem").children()