Baisc Control Type

In the last article, we learned about the container classes and control base classes in CukeTest. Next, we introduced the APIs for different Basic Control Types. This article will introduce the following basic control classes:

Because each control class inherits from IWintControl, each control class has all the operations and property methods of Common Control. Take the 'CheckBox' control class as an example:

CheckBoxcontrol has an operation method toggleCheck() is used to set the check status; An attribute method, checkState(), is used to determine the checkbox check statusTrue means checked, false means unchecked, and indetermine means intermediate state:

JavaScript
Python
export interface IWinCheckBox extends IWintControl {    
    toggleCheck(checkState: boolean | 'indeterminate'): Promise<void>
    checkState(): Promise<boolean | 'indeterminate'>
}
class WinCheckBox(WinControl):
	def check(checked: bool) -> None
	def checkState() -> Union[bool, str]
	def toggleCheck(checkState: Union[bool, str]) -> None
But in fact, CheckBox inherits all methods from the IWintControl base class in addition to these two methods, so CheckBox methods should actually include methods of the base class
JavaScript
export interface IWinCheckBox extends IWintControl {
    
    toggleCheck(checkState: boolean): Promise<void>
    // Operation methods inherited from the base class
    click(x?: number, y?: number, mousekey?: MouseKey): Promise<void>;
    dblClick(x?: number, y?: number, mousekey?: MouseKey): Promise<void>;
    moveMouse(x?: number, y?: number): Promise<void>
    wheel(value: number): Promise<void>;
    exists(time: number): Promise<boolean>;
    hScroll(value: number | ScrollAmount): Promise<void>;
    vScroll(value: number | ScrollAmount): Promise<void>;
    property(propertyIds: PropertyIds): Promise<string | boolean | number | Rect>;
    waitProperty(propertyIds: PropertyIds, value: string, timeoutSeconds: number): Promise<boolean>
    drop(x?: number, y?: number): Promise<void>;
    drag(x?: number, y?: number): Promise<void>;
    pressKeys(keys: string, options?: PressKeysOptions | number): Promise<void>;
    takeScreenshot(filePath?: string): Promise<void | string>;

    checkState(): Promise<boolean>
    // Property methods inherited from the base class
    type(): Promise<string>;
    text(): Promise<string>;
    name(): Promise<string>;
    hwnd(): Promise<number>;
    x(): Promise<number>;
    y(): Promise<number>;
    height(): Promise<number>;
    width(): Promise<number>;
    enabled(): Promise<boolean>;
    focused(): Promise<boolean>;
    helpText(): Promise<string>;
    labeledText(): Promise<string>;
    value(): Promise<string | number>;
    processId(): Promise<number>;
    rect(): Promise<Rect>;
    modelImage(options?: {encoding: 'buffer' | 'base64'}): Promise<Buffer | string>  //base64 is the default
}
If an object does not contain any operation and property methods, it only applies to its base class -- that is, the operation and property methods in IWintControl and IWintContainer, and has no unique features, such as Button Control

Introduction to Basic Control Type

Button

For common button controls, the Model Manager provides a Button object type.

JavaScript
Python
export interface IWinButton extends IWintControl {

}
class WinButton(WinControl):
	...

Since the operation and property methods of the Button control are consistent with those of the base class IWintControl, there is no unique method of its own, so it is empty. For its operation method, please refer to Base Class Method.


Window

For application window controls, the Model Manager provides a Window object type.

JavaScript
Python
export interface IWinWindow extends IWintControl {
    activate(): Promise<void>;
    close(): Promise<void>;
    maximize(): Promise<void>;
    minimize(): Promise<void>;
    restore(): Promise<void>;
}
class WinWindow(WinControl):
	def activate() -> None
	def close() -> None
	def maximize() -> None
	def minimize() -> None
	def restore() -> None

activate(): Promise<void>

Activate the target window to make it appear on the top of the desktop and avoid being covered by other windows.

  • returns: An asynchronous method that returns no value.

close(): Promise<void>

Close the target window.

  • returns: An asynchronous method that returns no value.

maximize(): Promise<void>

Maximize the target window.

  • returns: An asynchronous method that returns no value.

minimize(): Promise<void>

Minimize the target window.

  • returns: An asynchronous method that returns no value.

restore(): Promise<void>

Restore the target window. This method can be used to restore to normal state when the target is minimized.

  • returns: An asynchronous method that returns no value.

Input Control: Edit and Document

For the input control Edit used to receive user input, while the multiline input is sometimes Document. The provided operation methods and property methods are for the values in the input.

JavaScript
Python
export interface IWinEdit extends IWintControl {
    set(value: string): Promise<void>;
    clearAll(): Promise<void>;
    readOnly(): Promise<boolean>;
}
export interface IWinDocument extends IWinControl {
    set(value: string): Promise<void>;
    clearAll(): Promise<void>;
    readOnly(): Promise<boolean>;
}
class WinEdit(WinControl):
	def set(value: str) -> None
	def clearAll() -> None
	def readOnly() -> bool
class WinDocument(WinControl):
	def set(value: str) -> None
	def clearAll() -> None
	def readOnly() -> bool
In addition, the text box control Text and the container control Pane can also be edited in some cases, so the set method is also provided, and the usage is consistent with Edit and Document.
JavaScript
Python
export interface IWinText extends IWinControl {
    set(value: string): Promise<void>;
}
export interface IWinPane extends IWinControl {
    set(value: string): Promise<void>;
}
class WinText(WinControl):
	def set(value: str) -> None
class WinPane(WinControl):
	def set(value: str) -> None

set(value): Promise<void>

Set the value in the input box. Replace the value in the target input box with the passed in string.

  • value: String type, the value expected to be written to the input;
  • returns: An asynchronous method that returns no value.

clearAll(): Promise<void>

Clear the value in the input.

  • returns: An asynchronous method that returns no value.

readOnly(): Promise<boolean>

Whether the current input is read-only. Read only returns true, read/write returns false.

  • returns: Promise<boolean>,You need to use the await keyword to get the results.

RadioButton

For the RatioButton control of the radio button, the method of selecting and obtaining the selected status is provided according to the use logic.

JavaScript
Python
export interface IWinRadioButton extends IWintControl {
    check(): Promise<void>;
    checked(): Promise<boolean>;
}
class WinRadioButton(WinControl):
	def checked() -> Union[bool, str]
	def check() -> None

check(): Promise<void>

Select the target radio button.

  • returns: An asynchronous method that does not return any value.

checked(): Promise<boolean>

Get the selected status of the target radio button. true means selected, and false means not selected.

  • returns: Promise<boolean>,Indicates whether the target check box is selected. You need to use the await keyword to get the results.

CheckBox

For the CheckBox control of the check box control, you can directly set the selection status, and of course, you can also obtain the status.

JavaScript
Python
export interface IWinCheckBox extends IWintControl {
    toggleCheck(checkState: boolean | 'indeterminate'): Promise<void>
    checkState(): Promise<boolean | 'indeterminate'>
}
class WinCheckBox():
	def check(checked: bool) -> None
	def checkState() -> Union[bool, str]
	def toggleCheck(checkState: Union[bool, str]) -> None
CheckState is a class created for Windows check boxes. The supported values are true | false |'indetermine '. true means to select the check box, and false means to deselect the target check box. 'Indeterminate' stands for the intermediate value. Because Windows check boxes sometimes have three states, they cannot be directly represented by boolean.

toggleCheck(checkState): Promise<void>

Sets the selected state of the target check box.

  • checkState: checkState type。
  • returns: An asynchronous method that does not return any value.

checked(): Promise<checkState>

Get the selected status of the target radio button.

  • returns: Promise<checkState>

ComboBox

For the ComboBox control of a special type of input with select, the operation method of selecting and specifying drop-down options is provided.

JavaScript
Python
export interface IWinComboBox extends IWintControl {
    open(): Promise<void>;
    select(nameOrIndex: String | number): Promise<void>;

    options(index: number): Promise<string | string[]>;
    itemCount(): Promise<number>;
    selectedName(): Promise<string>;
}
class WinComboBox(WinControl):
	def options(index: Optional[int]=None) -> Union[str, List[str]]
	def itemCount() -> int
	def selectedName() -> str
	def select(value: Union[str, int]) -> None
	def open() -> None

open(): Promise<void>

Expanding select can be regarded as triggering the button on the right of the target.

  • returns: An asynchronous method that does not return any value.

select(nameOrIndex): Promise<void>

  • nameOrIndex: number or String type.If it is a number, the corresponding index position option in select will be selected; If it is a string, the option of the corresponding name in the drop-down box will be selected.
  • returns: An asynchronous method that does not return any value.

selectedName(): Promise<string>

Gets the currently selected value.

  • returns: Promise<string>, Represents the currently selected value. You need to use the await keyword to get the results.

    options(): Promise<string[]>

    Gets the names of all optional options in the target combo box.
  • returns: Promise<string[]>, That is a string array, get the names of all selectable options in the target combo box. You need to use the await keyword to retrieve the result.

itemCount(): Promise<number>

Gets the count of all selectable options in the target combo box. It can be understood that the options() method returns the length of the array. returns: Promise<number>,Asynchronously return the number of options.


Spinner

For the spinner Spinner control with up and down arrows in the application, it provides methods for input, editing and clearing similar to the input box Edit control. In addition, an operation API for increasing/decreasing the value in a single step is provided.

The type definition of the control is as follows:

JavaScript
Python
export interface IWinSpinner extends IWinEdit {
    set(value: string): Promise<void>;
    clearAll(): Promise<void>;
    readOnly(): Promise<boolean>;
    increment(): Promise<void>;
    decrement(): Promise<void>;
}
class WinSpinner(WinControl):
	def set(value: str) -> None
	def clearAll() -> None
	def readOnly() -> bool
	def increment() -> None
	def decrement() -> None

set(value): Promise<void>

See set() method. It will fail if you enter a string because the control only accepts numeric parameters.

You can also use the pressKeys() method to complete the input.

clearAll(): Promise<void>

See clearAll() method.

readOnly(): Promise<boolean>

See readOnly() method.

increment(): Promise<void>

Increments the value of the value box by one unit, and the size of the unit depends on the settings in the application. It can be understood as triggering the up arrow in the value box once.

  • returns: An asynchronous method that returns no value.

decrement(): Promise<void>

Decreases the value of the value box by one unit, and the size of the unit depends on the settings in the application. It can be understood as triggering the down arrow in the value box once.

  • returns: An asynchronous method that returns no value.

ScrollBar

For operating the scroll bar control in the scroll area, but when scrolling operation is required, it is a very convenient choice to recognize the scroll bar control in this area, and then complete the scroll operation of the area by calling the method on the scroll bar.

A scroll bar control is actually a special kind of slider.

The type file is as follows:

JavaScript
Python
export interface IWinScrollBar extends IWinControl {
    setValue(value: number): void; 
    isTop(): Promise<boolean>;
    isBottom(): Promise<boolean>;
    lineUp(): Promise<void>;
    lineDown(): Promise<void>;
    pageUp(): Promise<void>;
    pageDown(): Promise<void>;
    scrollToTop(): Promise<void>;
    scrollToBottom(): Promise<void>;
}
class WinScrollBar(WinControl):
	def setValue(value: int) -> None
	def isTop() -> bool
	def isBottom() -> bool
	def lineUp() -> None
	def lineDown() -> None
	def pageUp() -> None
	def pageDown() -> None
	def scrollToTop() -> None
	def scrollToBottom() -> None

setValue(value: number): Promise<void>

Set the value of the scroll bar, drag the slider to the position of the specified value, but not exceed the maximum value. The unit can be understood as the number of scroll wheel grids.

  • value: number,Drag the slider to the position of the specified value;
  • returns: An asynchronous method that returns no value.

lineUp(): Promise<void>

Scroll up/left by one unit, the unit can be regarded as the number of scroll wheel grids, that is, the amount of scrolling by pressing the up/left arrow key once.

  • returns: An asynchronous method that returns no value.

lineDown(): Promise<void>

Scroll down/right by one unit, the unit can be regarded as the scroll wheel number, that is, the amount to scroll by pressing the down/right arrow key once.

  • returns: An asynchronous method that returns no value.

pageUp(): Promise<void>

Scroll up/left by one page, that is, the amount of scrolling by pressing the PageUp key once.

  • returns: An asynchronous method that returns no value.

pageDown(): Promise<void>

Scroll down/right by one page, that is, the amount of scrolling by pressing the PageDown key once.

  • returns: An asynchronous method that returns no value.

scrollToTop(): Promise<void>

Scroll the scroll bar to the top.

  • returns: An asynchronous method that returns no value.

scrollToBottom(): Promise<void>

Scroll the scroll bar to the bottom.

  • returns: An asynchronous method that returns no value.

isTop(): Promise<boolean>

Whether the scrollbar is on top.

  • returns: boolean, Whether the scrollbar is on top.

isBottom(): Promise<boolean>

Whether the scrollbar is at the bottom.

  • returns: boolean, Whether the scrollbar is at the bottom.

For the menu operation in the application, there are three controls: MenuBar, Menu and MenuItem. Among them, the first two controls belong to container controls (menu bar container and expanded menu container), and the options that can actually be clicked are MenuItem controls.

JavaScript
Python
export interface IWinMenuBar extends IWintControl {    
    itemNames(index:number) : Promise<string>;
    open(itemNameOrIndex: string | number): Promise<void>;
    //Get the menu item count
    itemCount(): Promise<number>;
}
export interface IWinMenu extends IWintControl {
    select(menuPath: string): Promise<boolean>;  
    
    itemCount(menuPath:string): Promise<number>; 
    itemName(menuPath:string): Promise<string>;
    itemNames(): Promise<string[]>;
}
export interface IWinMenuItem extends IWintControl {
    invoke(): Promise<void>;
    open(): Promise<void>
}
class WinMenuBar(WinControl):
	def itemNames(index: int) -> str
	def open(itemNameOrndex: Union[str, int]) -> None
	def itemCount() -> int
class WinMenu(WinControl):
	def itemCount(menuPath: str) -> int
	def itemName(menuPath: str) -> str
	def itemNames() -> List[str]
	def select(menuPath: str) -> bool
class WinMenuItem(WinControl):
	def invoke() -> None
	def open() -> None
API Introduction of MenuBar

itemNames(index) : Promise<string>

Gets the menu item name for the target index value.

  • index: number,The index value of the target menu item.
  • returns: Promise<string>, Asynchronously returns the menu item name corresponding to the target index value.

Expand the menu item for the target index value.

  • index: number, The index value of the target menu item; string,The name of the target menu item.
  • returns: An asynchronous method that returns no value.

itemCount(): Promise<number>

Get the total number of menu items in the menu bar.

  • returns: Promise<number>, Asynchronously returns the number of menu items.

API introduction of menu container Menu

itemCount(): Promise<number>

Get the total number of menu items in the menu container.

  • returns: Promise<number>, Asynchronously returns the number of menu items.

itemName(menuPath): Promise<string>

Gets the menu item name for the target index value.

  • menuPath: number, The index value of the target menu item.
  • returns: Promise<string>, Asynchronously returns the menu item name corresponding to the target index value.

itemNames(): Promise<string[]>

Get the names of all menu items.

  • returns: Promise<string[]>, Asynchronously returns the names of all menu items in the menu.

select(menuPath: string): Promise<boolean>

Select the menu item for the target index value.

  • menuPath: number, The index value of the target menu item.
  • returns: Promise<boolean>, Asynchronously returns whether the target was successfully selected.

API introduction of menu item MenuItem

Expands the menu container in which the menu item resides.

  • returns: An asynchronous method that does not return any value.

invoke(): Promise<void>

Click/trigger menu item. It is recommended to use the open() method to expand the menu before clicking.

  • returns: An asynchronous method that does not return any value.

How to click the submenu:
For some submenu items that need to be clicked after hovering, you can first call the .moveMouse() general method on the parent menu item to move the mouse to the position, and then click the submenu. This is because the mouse trajectory before the two clicks cannot be determined, and the click of some controls will not move the mouse. At this time, if the mouse cursor needs to appear at a certain position, it is best to use moveMouse() to Move the cursor manually.


Tab bar control and tab page control: Tab & TabItem

For the control of the tab page in the application, Tab and TabItem, switch the tab page.
The definition of the tab bar control is as follows:

JavaScript
Python
export interface IWinTab extends IWintControl {
    select(item: string | number): Promise<void>;
    activate(itemNameOrIndex: string | number): Promise<void>;
    tabNames(index: number): Promise<string[] | string>;
    
    findItem(nameOrIndex: string | number): Promise<IWinTabItem>;

    activeName(): Promise<string>;
    activeIndex(): Promise<number>;
    count(): Promise<number>;
    selectedItem(): Promise<string>;
}
export interface IWinTabItem extends IWintControl {
    activate(): Promise<void>;
    text(): Promise<string>;
    itemIndex(): Promise<number>;
}
class WinTab(WinControl):
	def activate(nameOrndex: Union[str, int]) -> None
	def tabNames(index: Optional[int]=None) -> Union[str, List[str]]
	def findItem(nameOrndex: Union[str, int]) -> "WinTabItem"
	def select(item: Union[str, int]) -> None
	def activeName() -> str
	def activendex() -> int
	def count() -> int
class WinTabItem(WinControl):
	def activate() -> None
	def text() -> str
	def itemndex() -> int

findItem(itemNameOrIndex): IWinTabItem

Get the automation object of the specified tab page, and pass in the index value or title of the tab page.

  • itemNameOrIndex: number or string type, the index value of the target tab or the title of the tab.
  • Return value: TabItem type, synchronously returns an operation object of TabItem type.

activate(itemNameOrIndex): Promise<void>

Activate the target tab page, passing in the index value or title of the tab page.

If it is the activate() method on TabItem, no parameters need to be passed in.

  • itemNameOrIndex: number or string type, the index value of the target tab or the title of the tab.
  • returns: An asynchronous method that returns no value.

activateIndex(): Promise<number>

Get the index value of the active tab in the current interface.

  • returns: number, Tab page index value.

activateName(): Promise<string>

Get the name of the active label in the current interface.

  • returns: string, The name of the tab.

tabNames(index): Promise<string[] | string>

Get the titles of all tab pages. If a number is passed in, get the title of the tab page corresponding to the index value.

  • index: number, The index value of the target tab page, the default value is -1, which will get all the titles.
  • returns: When index is -1, it is string[], which is a string array composed of all tab page titles; when index is other values, it is string, which returns the label corresponding to the target index value Page title.

count(): Promise<number>

Get the number of tabs in the tab bar.

  • returns: number, The number of tabs.

Following are the methods of the TabItem object.

activate(): Promise<void>

Activate tab.

  • returns: An asynchronous method that returns no value.

text(): Promise<string>

Overridden from the text() method of the base class to get the tab title.

  • returns: string, Returns the title of the tab.

itemIndex(): Promise<number>

Get the order of the tabs in the entire tab bar.

  • returns: number, Returns the index value of the tab page.

results matching ""

    No results matching ""