List

CukeTest provides a series of APIs for list controls in ATK applications to get and operate list data. These APIs can help you easily access and control items in lists.

Method Name Description
data Gets all data from the list.
getItem Gets an item in the list by name or index.
select Selects an item in the list and returns the item object.
selectedIndex Gets the index of the currently selected item.
findItem Finds an item in the list by text, supports fuzzy matching.
itemCount Gets the total number of items in the list.

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

Type Definitions

JavaScript
Python
export interface IAtList extends IAtControl {
    data(): Promise<string[]>;
    getItem(nameOrIndex: number | string): IAtListItem;
    select(nameOrIndex: number | string): Promise<IAtListItem>;
    selectedIndex(): Promise<number>;
    findItem(text: string, options?: {exact?: boolean}): Promise<IAtListItem | null>;
    itemCount(): Promise<number>;
}
class AtList(AtControl):
	def data() -> List[str]
	def getItem(nameOrIndex: Union[str, int]) -> AtListItem
	def select(nameOrIndex: Union[str, int]) -> AtListItem
	def selectedIndex() -> int
	def findItem(text: str, options: Optional[FindItemOptional]=None) -> AtListItem
	def itemCount() -> int

data()

Gets the content of all items in the list.

Return Value:

  • Promise<string[]> type, asynchronously returns an array of all item contents in the list.

Sample Code

Get the content of all items in the list:

JavaScript
Python
let items = await model.getList("list").data();
console.log(`List item content: ${items.join(", ")}`);
items = model.getList("list").data()
print(f"List item content: {', '.join(items)}")

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:

  • IAtListItem type, returns the item object in the list.

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 an item in the list and returns the item object.

Parameters:

  • nameOrIndex: number | string type, can be the name or index of the item.

Return Value:

  • Promise<IAtListItem> type, asynchronously returns the selected item object.

Sample Code

Select an item in the list:

JavaScript
Python
let selectedItem = await model.getList("list").select(0);
selectedItem = model.getList("list").select(0)

selectedIndex()

Gets the index of the currently selected item.

Return Value:

  • Promise<number> type, asynchronously returns the index of the currently selected item.

Sample Code

Get the index of the currently selected item:

JavaScript
Python
let index = await model.getList("list").selectedIndex();
console.log(`Currently selected item index: ${index}`);
index = model.getList("list").selectedIndex()
print(f"Currently selected item index: {index}")

findItem(text, options)

Finds an item in the list by text, supports fuzzy matching.

Parameters:

  • text: string type, represents the text to search for.
  • options: Optional type, optional parameter, supports the exact property to specify whether to match exactly.

Return Value:

  • Promise<IAtListItem | null> type, asynchronously returns the found item object or null.

Sample Code

Find an item in the list:

JavaScript
Python
let foundItem = await model.getList("list").findItem("Search Text", { exact: true });
foundItem = model.getList("list").findItem("Search Text", {"exact": True})

itemCount()

Gets the total number of items in the list.

Return Value:

  • Promise<number> type, asynchronously returns the total number of items in the list.

Sample Code

Get the total 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}")