Recoring Qt Operation

CukeTest's script recording feature supports the recording of Qt applications. Scripts recorded on one operating system can be executed on other platforms.

Principle of recording

The principle of recording is still based on CukeTest's own object recognition technology, so for controls that can be accessed, the generated scripts are directly manipulating the control and calling methods on the control to reproduce the events, ensuring reliability and stability.

Also CukeTest recording records the relative coordinates of the operation point to record which position of the control is currently being operated on. This ensures that some operations that require coordinates (such as drawing, line drawing, dotting, etc.) are not easily affected by the environment and application size, as they are relative to the coordinates of the control itself rather than traditional desktop coordinates. For some controls that do not require relative coordinates, such as Button clicks, no relative coordinates are recorded. If it is sufficient for the user to click on the center area of the control and precise relative coordinates are not needed, you can delete the unwanted coordinate information after recording.

Steps to record Qt script

  1. Create a Qt project in CukeTest.
  2. Configure the Qt recording in recording settings. The recording settings work globally, so you only need to configure them once.
  3. Click the drop-down arrow next to the Record button and select the "Qt Record" option to switch the Record button to Qt Record.
  4. Click the Record button to start recording
  5. Operate the Qt application
  6. Stop the recording.

The recording generates two files: script and model. The script maintains the operation information and the model maintains the positioning information of the manipulated control, thus making maintenance easier. The following describes the generated script code.

Code Generation

The scripts generated by CukeTest's recording are very easy to understand and edit, here is the generated script:

JavaScript
Python
const { RunSettings } = require("leanpro.common");
const { QtAuto } = require("leanpro.qt");
let model = QtAuto.loadModel(__dirname + "/recording.tmodel");
RunSettings.slowMo = 1000;

(async () => {

  //Launching Qt applications "standarddialogs"
  await QtAuto.launchQtProcessAsync("C:/Program Files/LeanPro/CukeTest/bin/standarddialogs.exe");
  await model.getApplication("standarddialogs").exists(10);

  //Click "QInputDialog::getInt()"
  await model.getButton("QInputDialog::getInt()").click()

  //Set the control value to "12"
  await model.getSpinBox("SpinBox").set("12")

  //Click "OK"
  await model.getButton("OK").click()

  //Click "QInputDialog::getDouble()"
  await model.getButton("QInputDialog::getDouble()").click()

  //Close the Qt application "standarddialogs"
  await model.getApplication("standarddialogs").quit();
})();
import os
from leanproAuto import RunSettings, QtAuto
RunSettings.set({"slowMo": 1000, "reportSteps": True})
modelQt = QtAuto.loadModel(os.path.dirname(__file__) + "/recording.tmodel")
#Launch Application "SimpleStyles.exe"
QtAuto.launchQtProcessAsync("C:/Program Files/LeanPro/CukeTest/bin/standarddialogs.exe")

modelQt.getApplication("standarddialogs").exists(10)

#Click "QInputDialog::getInt()"
modelQt.getButton("QInputDialog::getInt()").click()

#Set the control value to "12"
modelQt.getSpinBox("SpinBox").set("12")

#Click "OK"
modelQt.getButton("OK").click()

#Click "QInputDialog::getDouble()"
modelQt.getButton("QInputDialog::getDouble()").click()

#Close the Qt application "standarddialogs"
modelQt.getApplication("standarddialogs").quit()

In addition to the reference at the top, the (async () => { and })() wrapped around the script call is called an asynchronous IIFE (Immediately Executable Function Expression), helping the user to run directly scripts .

Each operation in the script is accompanied by a line of comments describing the step-by-step operation. Each call can be divided into three sections describing the components of the operation:

  1. control type: asserts the type of the currently manipulated control.
  2. object name: the name of the target node in the model file tmodel.
  3. operation method: the operation to be performed on the control.
    JavaScript
    Python
    //--|Control Type|Object Name|Operation Method| 
    model.getButton("OK").click()
    #--|Control Type|Object Name|Operation Method| 
    model.getButton("OK").click()

Generate Model

The model generated by recording has the same name as the script file, for example, if the recorded script file is named recording.js, then the corresponding model file is recording.tmodel. Open the model, which holds the information of all the controls manipulated in the script. Click on it and it will open in the model manager. Right-click on the root node and select Start Application to open our measured application. Then select an object inside the model and you can see that its corresponding control in the application under test is highlighted.

Recorded generated models

Generate start/close application code

All cross-platform Qt applications should be started in the specified way before being automated for operation, and recording is no exception. There are several ways to start it as follows.

  1. You can set the application to start when recording directly in the Recording Settings panel. The operation of starting the application will be recorded.
  2. You can launch the application after recording the launch by one of the ways in Qt application launch. This way the operation of launching the application will also be recorded.
  3. If the Qt application is started before recording, the code to start the application will not be generated. So make sure the application the script is going to operate on is started before playing it back.

Launching an application usually generates two codes.

JavaScript
Python
//Launching Qt applications "standarddialogs"
await QtAuto.launchQtProcessAsync("C:/Program Files/LeanPro/CukeTest/bin/standarddialogs.exe");
await model.getApplication("standarddialogs").exists(10);
#Launching Qt applications "standarddialogs"
QtAuto.launchQtProcessAsync("C:/Program Files/LeanPro/CukeTest/bin/standarddialogs.exe")
modelQt.getApplication("standarddialogs").exists(10)

The first line is to run the application and the second line is to wait for the application to actually load, by default up to 10 seconds. If your application actually takes longer than this time to load, you can manually modify the generated code.

An exit code like the one below is generated when the application exits.

JavaScript
Python
//Close the Qt application "standarddialogs"
await model.getApplication("standarddialogs").quit();
#Close the Qt application "standarddialogs"
modelQt.getApplication("standarddialogs").quit()
If the exit from the application is triggered by a click action and the click action has generated code, you can manually remove this exit code line.

Generate playback speed control code

CukeTest's recording has the slowMo ("slow motion") switch turned on by default and set to 1000, as well as extending the interval between operations to at least 1 second in order to watch it play back. If you want the automation to run as fast as possible, this can be set to 0, or comment out the line of code.

The value of slowMo is set in the generated script.

JavaScript
Python
const { RunSettings } = require("leanpro.common");  
// ……  
RunSettings.slowMo = 1000;
from leanproAuto import RunSettings
RunSettings.set({"slowMo": 1000})

Post-processing of recorded generated scripts

Like script recording for other types of applications, recorded scripts record the various actions of manual operations. However, not all operations are of interest to automated testing, so after recording, you can manually remove unneeded operation code as needed, then play back and verify, and after verification, add the recorded script fragments to the complete script project.

For example, the hover() operation on the MenuItem is generated when the mouse hovers over the menu. If you think that actually triggering the menu item with a click is enough, you can manually delete the extra hover() operation. Of course, not deleting such an operation is not harmful to the execution of the test.

What if the script generated by the recording is wrong in the playback? Do I need to re-record? Usually, there is no need to re-record, and you can easily and quickly edit the generated recordings. Modifying scripts or models can change the effect of automated tests without always re-recording them. For example, in playback validation, if you report that the object was not found in playback, you can open the model and view the object that was not located in the corresponding model, its identifying properties, and the location results of its parent object. Some object properties of the application under test may change between runs, and it will be necessary to adjust the information about these localization parameters.

results matching ""

    No results matching ""