Scenario¶
An application is started as a sub-process and should be automated without hooking into the parent process or modifications of the startup mechanism in the parent process.
For example, a desktop application is started by sending a HTTP request to a Web Service, which is out of Squish' scope. To avoid any changes to the way the Web Service starts the application, a special approach can be used, which makes the desktop application attachable by Squish.
Overview¶
An application can be started with the command-line tools startaut
(Qt), startwinaut
(native Windows) or startjavaaut
(Java). Squish can attach to an application started this way, although it did not start the application directly. This approach can be used to hook into the sub-process in the scenario described above without modifications of the startup mechanism:
To make sure that your application is started in an attachable state, a dummy executable with the filename of the sub-process .exe file has to be created. The dummy executable will start the original sub-process .exe file that has been renamed. The dummy executable makes use of startaut
, startwinaut
or startjavaaut
internally, allowing Squish to attach to the application.
Whenever your application is started, this will be done through the dummy executable, making the approach of attaching transparent to the parent process.
Limitations¶
The approach explained below (rename original sub-process binary file and replace it by a shell script or dummy application that invokes the sub-process binary in a way that Squish can then attach to it) is not suitable for all cases.
Cases where it will probably not work:
When the main process reads/writes to/from the streams (stdin, stdout, stderr) of the sub-process.
When the main process performs actions based on the process ID of the sub-process (because with this approach the immediate sub-process is not the original sub-process executable anymore).
When the main process evaluates the exit code of the sub-process. (This can probably be supported but would require slight modifications to the steps below.)
Example #1¶
Step 1: Rename the sub-process' .exe file¶
Rename the sub-process' .exe file by prepending an underscore to its filename. For example, if the executable has the name sub_process.exe
, rename it to _sub_process.exe
.
Step 2: Set environment variable for the attach command¶
The dummy application we will create in the next step depends on the environment variable SQUISH_ATTACH_CMD
. This variable has to be set to the attach command startaut
, startwinaut
or startjavaaut
and its command-line arguments.
For example, to start a Qt application with C:\Squish for Qt\bin\startaut
that Squish can attach to via port 4711, SQUISH_ATTACH_CMD
would be set to the value
"C:\Squish for Qt\bin\startaut" --port=4711
Step 3: Create a dummy application that starts the AUT in an attachable state¶
Create a dummy application with the original filename of the sub-process .exe file (e.g. sub_process.exe
) and place it in the folder of the sub-process .exe file to replace the original executable. The dummy application will start the original executable _my_aut.exe
using the command that we defined in the environment variable SQUISH_ATTACH_CMD
:
#include "stdafx.h"
#include <windows.h>
#include <string>
int wmain( int argc, wchar_t *argv[ ], wchar_t *envp[ ] )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Environment variable with attach command, e.g.: "C:\Squish for Qt\startaut.exe" --port=4711
std::wstring cmd = _tgetenv(L"SQUISH_ATTACH_CMD");
cmd.append(L" _");
cmd.append(argv[0]);
std::wstring cmdLine = L"";
CreateProcess(NULL,
(LPTSTR)cmd.c_str(),
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi );
return 0;
}
Step 4: Register and configure an "Attachable AUT"¶
To register the "Attachable AUT" and use it in the Squish IDE for recording and playback, please refer to the instructions for the toolkit your application uses:
Example #2¶
Step 1: Rename the sub-process' .exe file executable¶
Rename the sub-process' .exe file by prepending an underscore to its filename. For example, if the executable has the name sub_process.exe
, rename it to _sub_process.exe
.
Step 2 - for Windows: Download and configure dummy application¶
Download and extract the "dummy" application starter-latest.zip .
Copy starter.exe
into the folder with the (renamed) original filename of the AUT and rename it to the original file name (e.g. sub_process.exe
).
Copy starter.exe.bat_qt_subprocess
into the folder with the (renamed) original filename of the sub-process .exe file and rename it to the original file name, and append .bat to the name (e.g. sub_process.exe.bat
)
With this in place, the (renamed) dummy application (starter.exe
, now sub_process.exe
) will start sub_process.exe.bat
, and that in turn will start the original (renamed) executable through startaut.
Note that by default the sub-process will be made attachable on TCP port 4444. You can alter this in the above .bat
file, or you can define the environment variable SQUISH_ATTACHABLE_PORT
and assign the desired port value to it (in cmd.exe
: set SQUISH_ATTACHABLE_PORT=5555
).
Step 2 - for Unix: Use a shell script as dummy application¶
Create a shell script in the folder with the (renamed) original filename of the AUT and rename it to the original file name (e.g. sub_process
).
In this shell script start your application via startaut
:
#!/bin/sh
"$SQUISH_PREFIX/bin/startaut" --port=4711 ./_sub_process
Also, the shell script must have its executable bit set. This can be achieved by executing this command:
chmod 740 sub_process
Step 3: Register and configure an "Attachable AUT"¶
To register the "Attachable AUT" and use it in the Squish IDE for recording and playback, please refer to the instructions for the toolkit your application uses: