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

JavaScript
Python
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() -> None

itemName(index)

Gets the name of the list item at the specified index.

Parameters:

  • index: number type, 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:

JavaScript
Python
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:

JavaScript
Python
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:

JavaScript
Python
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 | string type, 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:

JavaScript
Python
let item = model.getList("list").getItem("Item Name");
item = model.getList("list").getItem("Item Name")

select(nameOrIndex)

Selects the specified list item.

Parameters:

  • nameOrIndex: number type or string type, 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":

JavaScript
Python
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:

JavaScript
Python
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:

JavaScript
Python
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:

JavaScript
Python
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

JavaScript
Python
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() -> bool

select()

Selects the current list item.

Return Value:

  • Promise<void> type, indicates the selection operation is complete.

Sample Code

Select a list item:

JavaScript
Python
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, true indicates the current item is selected, false indicates it is not.

Sample Code

Check if a list item is selected:

JavaScript
Python
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:

JavaScript
Python
await model.getListItem("itemName").scrollIntoView();
model.getListItem("itemName").scrollIntoView()

toggleCheck(checkState)

Toggles the checked state of the list item.

Parameters:

  • checkState: boolean type, pass true to check the item, or false to uncheck it.

Return Value:

  • Promise<void> type, asynchronous method that returns no value.

Sample Code

Toggle the checked state of a list item:

JavaScript
await model.getListItem("itemName").toggleCheck(true);

Python
model.getListItem("itemName").toggleCheck(True)

checkState()

Gets the checked state of the current list item.

Return Value:

  • Promise<boolean> type, asynchronously returns true if the list item is checked, otherwise returns false.

Sample Code

Get the checked state of a list item:

JavaScript
let isChecked = await model.getListItem("itemName").checkState();
console.log(`List item checked state: ${isChecked}`);

Python
is_checked = model.getListItem("itemName").checkState()
print(f"List item checked state: {is_checked}")