7.8. Attaching to Running Applications

7.8.1. Overview
7.8.2. Start the AUT
7.8.3. Register the AUT
7.8.4. Attaching from a Script

7.8.1. Overview

Squish's default behavior is to automatically start the application you want to test, and to terminate the application once the test case is finished. But it is also possible to test an already running application by attaching to it. One important difference when attaching is that at the end of the test case Squish does not terminate the application it attached to.

One benefit of attaching is that it allows you to test your application with the squishserver running on another machine. However, the attaching approach also suffers from an important limitation: you can have only one squishserver attached to your application at a time.

Using the attaching approach is a three step process: first start the AUT; second, register the AUT; and finally, attach to the AUT from a script. We'll now discuss each of these steps in turn.

7.8.2. Start the AUT

In order for Squish to be able to connect to the AUT, you must start the AUT using Squish's start*aut (Section 7.4.7) command line tool.


startaut --port=port aut [aut-command-line-options]

You must specify a network port number as the argument to the --port option. The AUT listens on this port number for a connection from the squishserver.

It is important that the --port option is given before the AUT because any aut-command-line-options options specified after the AUT are passed as options to the AUT and are not used by start*aut (Section 7.4.7).


startaut --port=9999 addressbook

Once the AUT is running we are ready to connect to it. But first we must register the attachable AUT in order to be able to access it from test scripts.

7.8.3. Register the AUT

Just the same as with AUTs that are started and terminated by Squish, AUTs that are attached to must be registered. This is easily done using the Squish IDE. For Squish 4, click File|Server Settings|Manage AUTs... to pop up the Manage AUTs dialog (Section 8.3.4). For Squish 3, click Edit+Preferences to pop up the Preferences dialog, then click the Server Settings tab. Select the Attachable AUTs entry (which might be near the bottom of the tree view), and press the Add... button. This will pop up the Add Attachable AUT dialog. Use this dialog to enter the name of the AUT you want to be able to attach to—the name is just an acronym to stand for the AUT and for use in test scripts. Also, you must set the port number to the same one that you used when starting the AUT with start*aut (Section 7.4.7). In addition, you can specify the hostname—this is necessary only if you want to run the AUT on a different machine from the one that runs the squishserver.

7.8.4. Attaching from a Script

First you must tell Squish not to automatically start the AUT you wish to attach to when a test case is run. For Squish 4, click the Suite Settings item in the project tree, and in the Application Under Test (AUT) section, change the Application combobox's item to the <No Application> item. For Squish 3, click Test Suite+Settings to pop up the Test Suite Settings dialog, and on the General tab, change the Application combobox's item to the <No Application> item.

Now Squish will not start up the AUT for test cases in this test suite. We have already seen earlier how to start the AUT using the start*aut (Section 7.4.7) application. But to be able to connect to the application and interact with it our test script must attach to it. This is done by putting a call to the attachToApplication function in the test script, and passing it the arguments it needs to attach to the AUT. In fact, the only mandatory argument is the name we gave the AUT when we registered it.

Just as we use the attachToApplication function to attach to a running application, similarly we can use the startApplication function to start an application. And both these functions return an application context object (see Application Context (Section 6.3.12)).

It is possible to record a test script if we are attched to an AUT. To do so, we can simply click the Record toolbar button. A list of all registered AUT will be displayed, which allows selecting the application to record on.

When we are finished, simply press the Stop Recording toolbar button in Squish's control bar and the new test script will become visible in Squish's editor. (see How to Record After a Breakpoint (Section 5.21.2)).

By default Squish allows the AUT up to 20 seconds from Squish's initial connection to the AUT's first response. This can be changed; see Squish Server Settings dialog (Section 8.3.16).