Object APIs

The objects API fall into two categories, operations and properties. The operation does operation on the control, and the property is the actual property of the control. Because it is asynchronous, the "get" property is also in the form of a method, that is, it needs to be bracketed "()", and the return value is Promise object. The actual return value can be obtained by adding await in the async function.

Common APIs

Different types of object operations have different operations and properties. They all have some common operations and properties, as follows:

JavaScript
Python
export interface IWinControl extends IWinContainer {
  click(x?: number, y?: number, mousekey?: number): Promise<void>;
  dblClick(x?: number, y?: number, mousekey?: number): Promise<void>;
  wheel(value: number): Promise<void>;
  exists(time: number): Promise<boolean>;
  hScroll(value: any): Promise<void>;
  vScroll(value: any): Promise<void>;
  property(propertyIds: PropertyIds): Promise<string | boolean | number>;
  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): Promise<void>;

//properties
  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>;
  processId(): Promise<number>
}
class WinControl(WinContainer):
	def click(x: Optional[int]=None, y: Optional[int]=None, mousekey: Optional[int]=None) -> None
	def dblClick(x: Optional[int]=None, y: Optional[int]=None, mousekey: Optional[int]=None) -> None
	def moveMouse(x: Optional[int]=None, y: Optional[int]=None, seconds: Optional[int]=None) -> None
	def wheel(value: int) -> None
	def exists(time: Optional[int]=None) -> bool
	def hScroll(value: int) -> None
	def vScroll(value: int) -> None
	def property(propertyds: str) -> Union[str, int, bool, Rect]
	def waitProperty(propertyds: str, value: str, timeoutSeconds: Optional[int]=None) -> bool
	def drop(x: Optional[int]=None, y: Optional[int]=None) -> None
	def drag(x: Optional[int]=None, y: Optional[int]=None) -> None
	def pressKeys(keys: str, opt: Optional[Union[int, PressKeysOptions]]=None) -> None
	def takeScreenshot(filePath: Optional[str]=None) -> Union[str, None]
	def highlight(duration: Optional[int]=None) -> None
	def type() -> str
	def text() -> str
	def name() -> str
	def hwnd() -> int
	def x() -> int
	def y() -> int
	def height() -> int
	def width() -> int
	def enabled() -> bool
	def focused() -> bool
	def helpText() -> str
	def labeledText() -> str
	def value() -> Union[str, int]
	def processId() -> int
	def rect() -> "Rect"
	def firstChild(controlType: Optional[str]=None) -> "WinControl"
	def lastChild(controlType: Optional[str]=None) -> "WinControl"
	def next(controlType: Optional[str]=None) -> "WinControl"
	def previous(controlType: Optional[str]=None) -> "WinControl"
	def parent() -> "WinControl"
	def findControls(*conditions: List[Union[str, Dict]]) -> List[WinControl]
	def modelmage(encoding: Optional[str]=None) -> Union[str, bytearray]
	def modelProperties(all: Optional[bool]=None) -> TypedDict
	def allProperties() -> TypedDict
	def doDefaultAction() -> None
	def rawText() -> str

Specific help for each operation and property can be found in the Model Manager.

Each object's own API

Other objects, because they inherit IWinControl, have some other operations and properties in addition to these operations and properties. E.g:

The CheckBox control has check operation, which is used to set whether to check or clear the check, and checked property, which is used to determine the check state of the CheckBox:

JavaScript
Python
export interface IWinCheckBox extends IWinControl {
  check(value: boolean): Promise<void>;
  checked(): Promise<boolean>;
}
class WinCheckBox(WinControl):
	def check(checked: bool) -> None
	def checkState() -> Union[bool, str]
	def toggleCheck(checkState: Union[bool, str]) -> None

The following are the operations and properties specific to ComboBox:

JavaScript
Python
export interface IWinComboBox extends IWinControl {
  options(index: number): Promise<string>;
  itemCount(): Promise<number>;
  selectedName(): Promise<string>;
  select(value: string | number): Promise<void>;
  open(): void;
}
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

More help for the operation and properties of the controls can be found in the Model Manager.

Window

Window is usually the top-level control (or container) of an application, so it provides several APIs for window operations:

  • activate(): Activates the window so that it floats up to the top. Invalid if the window is minimized.
  • close(): Close the window.
  • maximize(): Maximize the window. Invalid if the window is minimized.
  • minimize(): Minimize the window and collapse the target window to the taskbar.
  • restore(): Restore the window, exit the window from the minimized or maximized state, and restore the default size.

Type files are defined as follows:

JavaScript
Python
export interface IWinWindow extends IWinControl {
    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

Flexible call window operation

Although in most cases the top control of the application will be a Windows control, there are differences between the implementations of desktop application frameworks, The top-level control of some applications may be the container of other applications, such as panel control Pane and custom control.How to perform window operation in this case? In fact, the window operation in CukeTest does not strictly require that the control type be Window, So if the top level of the target application is assumed to be Pane("New Tab")(Chrome window will be recognized as Pane), There are two script writing methods to call window operation methods:

Method I:

JavaScript
Python
await model.getPane("New Tab").maximize();
model.getPane("新标签页").maximize()
Since window operation does not limit the control type, this writing method is legal, but there is a problem that this writing method does not support code prompts, so the window operation method will not be seen in the pop-up instructions. However, you can see these methods in the Model Explorer and copy them directly.

Therefore, the following writing method is recommended.

Method II:

JavaScript
Python
await model.getWindow("New Tab").maximize();
model.getWindow("新标签页").maximize()
Even though the control type of the test object "New Tab" is "Pane", the object can still be obtained through the "getWindow()" method to perform window operations on it.

Notice: The above operations are allowed, but if the target control is not a top-level control, but a container at a certain level in the application, then the window operation will not work.

More control operations and property help can be found in the Model Explorer.

Virtual Control API

A virtual Control is a special control, so its operation is different from other controls. It has no operations and properties common to other Windows controls. It has only the following operations and properties. More about Virtual Control: Virtual Control

results matching ""

    No results matching ""