QtAuto

In CukeTest, the objects related to cross-platform Qt automation are in the leanpro.qt module, which contains the following 2 main classes:

  1. QtModel: Used to load the model file, drag and drop the model into the code to load it automatically;
  2. QtAuto: A library related to the execution of Qt automation;

All the methods listed below are synchronous methods and do not require await.

QtAuto

The object is defined as follows.

JavaScript
Python
class QtAuto {
    static defaultTimeout: number;
    static getApplication(appName: string): IQApplication;
    static launchQtProcess(exePath: string | string[], ...args: string[]): ChildProcess;
    static launchQtProcessAsync(exePath: string | string[], ...args: string[]): Promise<ChildProcess> 
    static launchQtProcessAsync(exePaths: string, args: string[], options: SpawnOptions): ChildProcess;
    static winHookProcess(pidOrNameOrProcess: number | string | object): Promise<void>
    static loadModel(modelPath: string): IQtModel;
}
class QtAuto(QtContainer):
	def launchQtProcessAsync(exePaths: Union[str, List[str]]) -> "ChildProcess"
	def winHookProcess(pidOrNameOrProcess: Union[str, int, TypedDict]) -> None
	def loadModel(modelPath: str) -> "QtModel"

Referenced from the leanpro.qt module, the reference can be written as follows:

JavaScript
Python
const { QtAuto } = require('leanpro.qt');
from leanproAuto import QtAuto

loadModel(modelPath): IQtModel

Load the model from the model file, which provides automation APIs for various controls.

  • modelPath: Type string, the path to the model file.
  • Return value: IQtModel type, model class containing various types of Qt object API

For example, a reference from the leanpro.qt module for a reference could be written as follows:

JavaScript
Python
const { QtAuto } = require('leanpro.qt');
let model = QtAuto.loadModel(__dirname + '/Model1.tmodel');
from leanproAuto import QtAuto
model = QtAuto.loadModel(__dirname + '/Model1.tmodel')

Drag and drop the model file directly from CukeTest's file manager view into the code editor to automatically generate the above model code.

QtAuto is used for the following aspects:

Qt automation timeout

Each Qt automation operation has a timeout period, and an error will be reported for executing the operation beyond the timeout period, in the following cases.

  1. If the operation takes longer than this time, a timeout error will be reported.
  2. If the control does not become visible within the timeout period, an "Object not found" error will be reported. The default timeout for Qt object operations is 5 seconds. When operating, it will wait for this control

defaultTimeout: number

Gets the current timeout setting. The unit is ms, so the default value returned is 5000, or you can assign a new value to it, which will modify the timeout for all Qt operations to that value, set to 10000 i.e. any Qt operation that runs for more than 10 seconds without ending will throw an error.

Operate Qt applications

Used to start the Qt application and to get information about the Qt application.

launchQtProcessAsync(exePath, args, options): Promise<ChildProcess>

Launching a Qt application using the advanced option is usually used to launch the application under test, and is suitable for use when the application under test has requirements for environment variables, working directories, etc. It needs to be distinguished from the launchProcess() method for launching a normal application, because the launchQtProcess() method will automatically load the Qt Agent, and Qt automation can only be executed if the Qt Agent is loaded.

and supports passing in multiple application paths as an array of strings, CukeTest will try each path until it finds a valid path. It can be used in the case of different paths of the tested application between different platforms.

  • exePath: string or string[] type, the path to the application, if passed the string array type string[], will try path by path until a valid path is found and then start.
  • args: (Optional) string[] type, arguments when running the application, for example cuketest --runjs test.js in this command, the last two are the arguments, writing args passing parameters in the form of ["--runjs", "test.js"].
  • options: (Optional) QtSpawnOptions type (extended from SpawnOptions type (/windows/win_shared_api.md#spawn-options)), controls more parameters for process operation, as an object in which you can specify environment variables, working directory, and other options.
    • cwd: Type string, the working directory of the child process, the default value is the directory of the running project, i.e. the value of process.cwd().
    • env: The Object type. Environment key-value pair. Default value: process.env, the environment variable of CukeTest runtime.
    • detached boolean type. A child process runs independently of its parent process (runs free from parent control).
    • shell of type boolean or string. If true, the command is run from within the shell. Use '/bin/sh' on Unix and process.env.ComSpec on Windows. A different shell can be specified as a string. Default value: false (no shell).
    • launchTimeout: (Qt launch method only) number type, the timeout in seconds to prepare the plugin, default value is: 10.

launchQtProcessAsync(exePath, ...args): ChildProcess

Start a Qt application, usually used to launch the application under test. Wait for the process to load the Qt Agent and then return.

and supports passing in multiple application paths as an array of strings, CukeTest will try each path until it finds a valid path. It can be used in the case of different paths of the tested application between different platforms.

  • exePath: string or string[] type, the path to the application, if passed the string array type string[], it will try path by path until a valid path is found and then start.
  • args: (optional) . .string[] type, arguments when running the application, for example cuketest --runjs test.js in this command, the last two are arguments, writing args pass parameters in the form of launchQtProcessAsync(exePath, "--runjs", "test.js").
  • launchQtProcess(exePath, ...args): ChildProcess

    Launches a Qt application, which is typically used to start the application under test. In contrast to launchQtProcessAsync(), this launch method does not wait for the process to load the Qt Agent and then return (because it is a synchronous method), so it is not a safe method for Qt automation and is not recommended.

    and supports passing in multiple application paths as an array of strings, CukeTest will try each path until it finds a valid path. It can be used in the case of different paths of the tested application between different platforms.

  • exePath: string or string[] type, the path to the application, if passed the string array type string[], it will try path by path until a valid path is found and then start.

  • args: (optional) string[] type, parameters when running the application, for example, cuketest --runjs test.js in this command, the last two are parameters, writing args pass parameters in the form of launchQtProcess(exePath, "--runjs", "test.js ").

getApplication(appName): IQApplication

Obtain the automation object of the target application, which can be used for automation operations.

  • appName: string type, the name of the Qt application.

winHookProcess(pidOrNameOrProcess): Promise<void>

Load Qt Agent in an opened Qt application under Windows platform. This function is a no-op on the Linux platform.

  • pidOrNameOrProcess: can be number or string or ChildProcess type
  • If it is of number type, it is pid, which is the id of the Qt application process.
  • If it is string type, it is the executable file name of the process, such as "fetchmore.exe"
  • Or ChildProcess object, such as the object returned by Util.launchProcess. Sometimes the Qt application is already open when the automation script is running, or the Qt application is not directly started by the automation script, then you need to call winHookProcess to load the Qt Agent. For example, in the automation script, application A is started through launchQtProcess, and when A is operated, A opens application B. Then you can execute the following statement to load Qt Agent for B.

JavaScript
JavaScript
await QtAuto.winHookProcess("B.exe");
QtAuto.winHookProcess("B.exe")

Chinese version click here.

results matching ""

    No results matching ""