7.7. Record / Replay on Sub-Processes started by the AUT

Table of Contents

7.7.1. Hooking up Java Sub-Processes in Squish for Java
7.7.2. Hooking up Qt Sub-Processes in Squish for Qt
7.7.3. Hooking up Sub-Processes in Squish for Windows
7.7.4. Hooking up Sub-Processes in Squish for macOS

7.7.1. Hooking up Java Sub-Processes in Squish for Java

Squish for Java hooks up Java sub-processes automatically, if they are launched through java (or java.exe, javaw.exe). However, further setup steps may be required. Please contact Squish technical support in case record/replay on Java sub-processes does not work for you.

When recording sub-processes, the test script will contain calls to the waitForApplicationLaunch function. This function returns an ApplicationContext object for each application started as a sub-process. (See also, Application Context (Section 6.3.12).) Using context objects makes it possible to tell Squish which application it should be interacting with at various points in the test script's execution. (See How to Use ApplicationContext Objects (Section 5.12.3) for details about working with application contexts.)

7.7.2. Hooking up Qt Sub-Processes in Squish for Qt

By default, Squish for Qt hooks into the application which is started by the test and ignores any sub-processes that the AUT may start. However, Squish for Qt generally supports testing of programs started as sub-processes, when this is enabled in Squish for Qt.

To enable recording and replaying on Qt sub-processes open the test suite settings by clicking the project's Test Suite Settings to make the Settings view (Section 8.2.16) appear, then check the Hook into sub-processes launched by the application checkbox.

Please note that the additional setup steps described in Additional Setup for Hooking up Qt Sub-Processes on Windows (Section 7.7.2.1) or Additional Setup for Hooking up Qt Sub-Processes on Windows Non-Invasively (Section 7.7.2.2) must be applied for recording and replaying on Qt sub-processes on Windows, as well.

When recording sub-processes, the test script will contain calls to the waitForApplicationLaunch function. This function returns an ApplicationContext object for each application started as a sub-process. (See also, Application Context (Section 6.3.12).) Using context objects makes it possible to tell Squish which application it should be interacting with at various points in the test script's execution. (See How to Use ApplicationContext Objects (Section 5.12.3) for details about working with application contexts.)

7.7.2.1. Additional Setup for Hooking up Qt Sub-Processes on Windows

(Also see Additional Setup for Hooking up Qt Sub-Processes on Windows Non-Invasively (Section 7.7.2.2) for an alternative approach to this.)

To enable Squish for Qt to hook up sub-processes of the AUT on Windows a small change to the AUT's source code is required, which essentially results in starting the sub-process through a wrapper program (SQUISH_DIR/bin/dllpreload.exe).

The required change to the AUT can be made so that it is only enabled when the AUT gets started via Squish, for example by checking for the existence of an environment variable called SQUISH_PREFIX. (Squish sets this environment variable for the AUT process.)

For example, suppose that the AUT had the following source code to start a sub-process:

QProcess process;
process.start("subprogram.exe");

To change this to work with Squish, change the AUT in two ways. First add a new command line argument, say --testing, that when given sets a global Boolean, say, TESTING to true. Now update the code that calls the subprocess as follows:

QProcess process;
QStringList commands;
#ifdef Q_OS_WIN32
if (TESTING)
    commands.append("dllpreload.exe");
#endif
commands.append("subprogram.exe");
process.start(commands[0], commands.mid(1));

When TESTING isn't defined the commands string list will only contain one item ("subprogram.exe"), and commands.mid(1) will harmlessly return an empty list.

To make the change effective, in the Settings view (Section 8.2.16) (or for Squish 3, the Test Suite Settings dialog), add --testing to the AUT's Arguments.

Now, when Squish executes the AUT on Windows and the sub-process is started, what will actually happen is that Squish's dllpreload.exe program will be started with the intended application (e.g., subprogram.exe) as its first argument, and any other arguments passed as arguments to the intended application as normal. This means that the AUT and sub-process' behavior will be exactly what it was before.

When recording sub-processes, the test script will contain calls to the waitForApplicationLaunch function. This function returns an ApplicationContext object for each application started as a sub-process. (See also, Application Context (Section 6.3.12).) Using context objects makes it possible to tell Squish which application it should be interacting with at various points in the test script's execution. (See How to Use ApplicationContext Objects (Section 5.12.3) for details about working with application contexts.)

7.7.2.2. Additional Setup for Hooking up Qt Sub-Processes on Windows Non-Invasively

(Also see Additional Setup for Hooking up Qt Sub-Processes on Windows (Section 7.7.2.1) for an alternative approach to this.)

To enable Squish for Qt to hook up sub-processes of the AUT on Windows without a change to the AUT's source code (as described in the alternative approach at Additional Setup for Hooking up Qt Sub-Processes on Windows (Section 7.7.2.1)) the following steps must be performed:

  1. Rename the AUT's executable to have an underscore before the period (e.g., rename myapp.exe to myapp_.exe)

  2. Copy dllpreload.exe into the same directory as myapp_.exe

  3. Rename the copied dllpreload.exe to the AUT's original name (e.g., to myapp.exe)

Now, when the AUT is executed, it is really dllpreload.exe that gets executed, and dllpreload.exe is smart enough to check the name it was called as and will try to execute the executable with the same name but with an underscore before the period.

7.7.3. Hooking up Sub-Processes in Squish for Windows

Squish for Windows hooks up sub-processes automatically. No additional settings or setup steps are required.

7.7.4. Hooking up Sub-Processes in Squish for macOS

To enable recording and replaying on native macOS sub-processes open the test suite settings by clicking the project's Test Suite Settings to make the Settings view (Section 8.2.16) appear, then check the Hook into sub-processes launched by the application checkbox.