Remote Qt Automation

Qt applications support automation through remote execution. The CukeTest application runs on one computer, and the Qt application runs on another computer. For example, CukeTest runs on Windows, and Qt applications run on Linux, and realize automation through remote calls.

For more remote automation information, please refer to Remote Automation

The following is a sample script for remote automation.

JavaScript
const { CukeTest } = require('cuketest');
const { setDefaultTimeout, Given, When, Then } = require('cucumber');

setDefaultTimeout(20 * 1000);
Given("自动化basiclayouts", async function () {

    //Connecting to a Remote Worker
    let auto = await CukeTest.connect({
        wsEndpoint: 'ws://192.168.1.5:3131/ws'
    });
    //Get the remote QtAuto object
    let qtauto = auto.qtauto;

    //Set slow execution
    auto.runSettings.set({slowMo: 1000});

    //Loading Models
    let modelQt = await qtauto.loadModel('./basiclayouts.tmodel');

    //Launching Qt applications "basiclayouts"
    let ret = await qtauto.launchQtProcessAsync('/usr/lib/cuketest/bin/basiclayouts');
    await modelQt.getApplication("basiclayouts").exists(10);

    //Click "Button_1"
    await modelQt.getButton("Button_1").click();

    //Click "Edit"
    await modelQt.getEdit("Edit").click(92, 11);

    //Set the control value to "aabbcc"
    let edit = modelQt.getEdit("Edit");
    
    await modelQt.getEdit("Edit").set("something");

    //Click "Edit1"
    await modelQt.getEdit("Edit1").click(297, 10);

    //Set the control value to"asdf"
    await modelQt.getEdit("Edit1").set("something else");

    //Add SpinBox "SpinBox"
    await modelQt.getSpinBox("SpinBox").increment();

    //Add SpinBox "SpinBox"
    await modelQt.getSpinBox("SpinBox").increment();

    let snapshot = await modelQt.getSpinBox("SpinBox").takeScreenshot();

    this.attach(snapshot, "image/png");

    //Click "OK", exit the application
    await modelQt.getButton("OK").click();

    //Close the remote connection and exit the script
    await auto.close();
});

To run the above script, you can.

  1. create a step "automation basiclayouts".
  2. generate an object model with the above object name by detecting the controls of the basiclayouts sample
  3. change the path of the basiclayouts executable to the corresponding path on the remote machine, and change the value of the wsEndpoint property to the network address of the remote computer

For remote automation, start the Worker service on the remote computer beforehand, and run Start under the Worker unpacked installation package.

In fact, the above code is generated roughly by local recording, and after generating the code, it can be run remotely with the following simple modifications.

Recorded code:

JavaScript
//Set slow execution
    RunSettings.slowMo = 1000;

    //Launching Qt applications "basiclayouts"
    await QtAuto.launchQtProcessAsync("C:/Program Files/LeanPro/CukeTest/bin/basiclayouts.exe");
    await modelQt.getApplication("basiclayouts").exists(10);
    //Loading Models
    let modelQt = QtAuto.loadModel(__dirname + "/recording.tmodel");

Modified code:

JavaScript
//Connecting to a Remote Worker
    let auto = await CukeTest.connect({
        wsEndpoint: 'ws://192.168.1.5:3131/ws'
    });
    //Get the remote QtAuto object
    let qtauto = auto.qtauto;

    //Set slow execution
    auto.runSettings.set({slowMo: 1000});

    //Launching Qt applications "basiclayouts"
    let ret = await qtauto.launchQtProcessAsync('/home/ubuntu/basiclayouts');
    await modelQt.getApplication("basiclayouts").exists(10);
    //Loading Models
    let modelQt = await qtauto.loadModel(__dirname + './basiclayouts.tmodel');

    //......(Operation Code)

    //Close the remote connection and exit the script
    await auto.close();

Among them: CukeTest is used to connect to a remote Worker and has the following methods.

JavaScript
interface CukeTest {
    connect(options: ClientConnectOptions): Promise<IRemoteAuto>
}
The auto instance object returned by the connect method can access all remote automation root objects:

interface IRemoteAuto {
  mouse: IMouse;
  keyboard: IKeyboard;
  screen: IScreen;
  qtauto: IQtAuto;
  runSettings: IRunSettings;
  close();
}

mouse, keyboard, and screen correspond to the local Mouse, Keyboard, and Screen objects, and qtauto corresponds to the local QtAuto object, and they have similar interfaces.

The runSettings pair corresponds to the local RunSettings object, which sets the value through the set method, and gets the value through the get method:

JavaScript
interface IRunSettingsOptions {
    defaultTimeout?: number;
    slowMo?: number;
}

interface IRunSettings {
    set(setting: IRunSettingsOptions): Promise<void>;
    get(): Promise<IRunSettingsOptions>;
}

For example, the following method sets a slow motion of 1 second per step:

JavaScript
auto.runSettings.set({slowMo: 1000});

results matching ""

    No results matching ""