Usually Squish hooks only into the application which is started by the test and does not care about sub-processes started by the AUT. If test scripts should also access sub-applications started by the AUT for recording and replay, Squish needs to be told about that.
First, in the test suite settings of the test suite, the option Hook into Sub-Processes started by the Application in the General tab of the test suite settings dialog needs to be checked.
Secondly:
Unix and Mac OS X: The sub-appliction(s), which are started by the AUT and which Squish should hook into, need to be whitelisted. Squish will only hook into known (whitelisted) applications. Whitelisting is done by just adding the program as known AUT to Squish or by adding its path as AUT path. Adding an AUT or AUT path can be done on the command line or through the Squish IDE. See AUT Paths and Mapped AUTs (Section 16.3.2) for details.
Windows: On Windows
this requires a small change to AUT which starts the
sub-applications though: To allow Squish to hook into the started
sub-application, the applications needs to be started with a small
wrapper application called dllpreload.exe.
So, let's assume you have the following code in your AUT which starts the sub-AUT mysubapp:
QProcess p; p.addArgument( "mysubapp" ); p.start();
Now change it to
QProcess p;
if (testing) {
#if defined(Q_OS_WIN32)
p.addArgument( "dllpreload.exe" );
#endif
}
p.addArgument( "mysubapp" );
p.start();
The variable testing you would e.g. set to
true if the application is started with an
--testing option which you use when starting
the AUT from Squish This way, when using Squish the
sub-application would be started using the wrappers, and when the
application is ran outside of Squish this won't be
used.
After those preparations you can now record tests where your AUT starts sub-processes and Squish will also record actions on the sub-processes and generate a test script for that.
You will then find waitForApplicationLaunch
calls generated in the test script which returns an
ApplicationContext object for each start of an
sub-application. The returned ApplicationContext objects
can then be used to make sure you access the correct application from
the test script. See Working with ApplicationContext (Section 16.1.9.2) for details
about working with application contexts.
Squish usually starts the application you want to test. But it is also possible to test an already running application by attaching to it. At the end of one test case, Squish does not terminate the application it attached to (unlike with AUTs Squish started itself).
In order to allow Squish to connect to the AUT, you need to include just one line extra code in your application. This code dynamically loads another library and the application is listening on a specific port for the squishserver to connect (i.e. for Squish to attach to the application for testing).
This approach allows even allows you to test your application with the squishserver running on another machine.
There is one important limitation, though: you can only have one squishserver attached to your application at a time.
To make an application attachable, you have to call the function
Squish::allowAttaching after the
QApplication constructor. The argument to this
function is a port number that the application should listen
on for a squishserver to connect to. The function is declared in
qtbuiltinhook.h.
Here is the standard pattern for making an application attachable:
#include <qapplication.h>
#include "qtbuiltinhook.h"
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
Squish::allowAttaching( 11233 );
...
return a.exec();
}
If you start the application now, it won't listen on that port. You have to set two environment variables for the AUT:
You have to set the environment variable
SQUISH_PREFIX to point to Squish's base
directory.
You have to set up the dynamic library paths
(LD_LIBRARY_PATH on Linux and PATH on Windows)
to contain Squish's lib directory
(bin on Windows).
Like with normal AUTs, you need to register attachable AUTs as well. For this open the preferences dialog with + and change to the Server Settings tab. Select the Attachable AUTs entry and press the button.
In the Add Attachable AUT dialog, you have to specify a Name for the AUT. This is the name you will use in the script to attach to the AUT - there is no need for the name to match the actual application name. In the Port spinbox, you should enter the port number your AUT listens to (with our code snippet above we should enter 11233).
If you want to run the squishserver and your AUT on different machines, you have to enter the host in the line edit Host.
From the script you attach to a registered AUT with
the attachToApplication script function. This function
takes one obligatory argument: the name of the registered
AUT. It returns the new application context. The
attachToApplication works like the
startApplication but rather attaches to an application
than starting a new one (see Application Context (Section 17.1.2.8) for more
information).