List
For list controls and nodes in lists, CukeTest provides List and ListItem controls.
In addition to the list control-specific methods listed below, you can also use Common Control Methods for more flexible operations.
List View Control: List
CukeTest provides a series of APIs for list controls in Java applications to get and operate list data. These APIs can help you easily access and control items in lists.
| Method Name | Description |
|---|---|
| itemName | Gets the name of the list item at the specified index. |
| itemCount | Gets the total number of list items. |
| data | Gets all data from the list. |
| getItem | Gets an item in the list by name or index. |
| select | Selects the specified list item. |
| selectedIndex | Gets the index of the currently selected list item. |
| scrollToTop | Scrolls the list to the top. |
| scrollToBottom | Scrolls the list to the bottom. |
Type Definitions
export interface IJList extends IJControl {
itemName(index: number): Promise<string>;
itemCount(): Promise<number>;
data(): Promise<string[]>;
getItem(nameOrIndex: number | string): IJListItem;
select(nameOrIndex: number | string): Promise<IJListItem>;
selectedIndex(): Promise<number>;
scrollToTop(): Promise<void>;
scrollToBottom(): Promise<void>;
}class JList(JControl):
def itemName(index: int) -> str
def itemCount() -> int
def data() -> List[str]
def getItem(nameOrIndex: Union[str, int]) -> JControl
def select(nameOrIndex: Union[str, int]) -> JControl
def selectedIndex() -> int
def scrollToTop() -> None
def scrollToBottom() -> NoneitemName(index)
Gets the name of the list item at the specified index.
Parameters:
- index:
numbertype, the index of the target list item, starting from 0.
Return Value:
Promise<string>type, asynchronously returns the name of the target list item.
Sample Code
Get the name of the 2nd item in the list:
let itemName = await model.getList("list").itemName(1);
console.log(`List item name: ${itemName}`);item_name = model.getList("list").itemName(1)
print(f"List item name: {item_name}")itemCount()
Gets the total number of list items.
Return Value:
Promise<number>type, asynchronously returns the total number of list items.
Sample Code
Get the number of items in the list:
let count = await model.getList("list").itemCount();
console.log(`Total list items: ${count}`);count = model.getList("list").itemCount()
print(f"Total list items: {count}")data()
Gets all data from the list, returned as a string array.
Return Value:
Promise<string[]>type, asynchronously returns an array of all item names in the list.
Sample Code
Get all data from the list:
let listData = await model.getList("list").data();
console.log(`List data: ${listData.join(", ")}`);list_data = model.getList("list").data()
print(f"List data: {', '.join(list_data)}")getItem(nameOrIndex)
Gets an item in the list by name or index.
Parameters:
- nameOrIndex:
number | stringtype, can be the name or index of the item.
Return Value:
<IJListItem>type, asynchronously returns the automation object of the selected list item.
Sample Code
Get a list item by name:
let item = model.getList("list").getItem("Item Name");item = model.getList("list").getItem("Item Name")select(nameOrIndex)
Selects the specified list item.
Parameters:
- nameOrIndex:
numbertype orstringtype, the index or name of the target list item.
Return Value:
Promise<IJListItem>type, asynchronously returns the automation object of the selected list item.
Sample Code
Select the list item named "Item 3":
let selectedItem = await model.getList("list").select("Item 3");selected_item = model.getList("list").select("Item 3")selectedIndex()
Gets the index of the currently selected list item.
Return Value:
Promise<number>type, asynchronously returns the index of the currently selected list item.
Sample Code
Get the index of the currently selected list item:
let selectedIndex = await model.getList("list").selectedIndex();
console.log(`Currently selected item index: ${selectedIndex}`);selected_index = model.getList("list").selectedIndex()
print(f"Currently selected item index: {selected_index}")scrollToTop()
Scrolls the list to the top.
Return Value:
- Asynchronous method that returns no value.
Sample Code
Scroll the list to the top:
await model.getList("list").scrollToTop();model.getList("list").scrollToTop()scrollToBottom()
Scrolls the list to the bottom.
Return Value:
- Asynchronous method that returns no value.
Sample Code
Scroll the list to the bottom:
await model.getList("list").scrollToBottom();model.getList("list").scrollToBottom()List Node Control: ListItem
The ListItem control represents individual nodes in the list and provides some basic methods for operating and querying the state of list items.
| Method Name | Description |
|---|---|
| select | Selects the current list item. |
| selected | Checks if the current list item is selected. |
| scrollIntoView | Scrolls the current list item into the visible area. |
| toggleCheck | Toggles the checked state of the list item. |
| checkState | Gets the checked state of the list item. |
Type Definitions
export interface IJListItem extends IJControl {
select(): Promise<void>;
selected(): Promise<boolean>;
scrollIntoView(): Promise<void>;
toggleCheck(checkState: boolean): Promise<void>
checkState(): Promise<boolean>
}class IJListItem(IJControl):
def select() -> None
def selected() -> bool
def scrollntoView() -> None
def toggleCheck(checkState: bool) -> None
def checkState() -> boolselect()
Selects the current list item.
Return Value:
Promise<void>type, indicates the selection operation is complete.
Sample Code
Select a list item:
await model.getListItem("itemName").select();model.getListItem("itemName").select()selected()
Checks if the current list item is selected.
Return Value:
Promise<boolean>type, asynchronously returns a boolean value,trueindicates the current item is selected,falseindicates it is not.
Sample Code
Check if a list item is selected:
let isSelected = await model.getListItem("itemName").selected();
console.log(`Is list item selected: ${isSelected}`);isSelected = model.getListItem("itemName").selected()
print(f"Is list item selected: {isSelected}")scrollIntoView()
Scrolls the current list item into the visible area.
Return Value:
Promise<void>type, indicates the scrolling operation is complete.
Sample Code
Scroll a list item into view:
await model.getListItem("itemName").scrollIntoView();model.getListItem("itemName").scrollIntoView()toggleCheck(checkState)
Toggles the checked state of the list item.
Parameters:
- checkState:
booleantype, passtrueto check the item, orfalseto uncheck it.
Return Value:
Promise<void>type, asynchronous method that returns no value.
Sample Code
Toggle the checked state of a list item:
await model.getListItem("itemName").toggleCheck(true);model.getListItem("itemName").toggleCheck(True)checkState()
Gets the checked state of the current list item.
Return Value:
Promise<boolean>type, asynchronously returnstrueif the list item is checked, otherwise returnsfalse.
Sample Code
Get the checked state of a list item:
let isChecked = await model.getListItem("itemName").checkState();
console.log(`List item checked state: ${isChecked}`);is_checked = model.getListItem("itemName").checkState()
print(f"List item checked state: {is_checked}")