7.8. Attaching to Running Applications

Table of Contents

7.8.1. Overview
7.8.2. Start the AUT
7.8.3. Register the Attachable 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.

Usage:

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).

Example:

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 Attachable AUT

AUTs that are attached to must be registered in the squishserver settings. In the Squish IDE, from Server Settings, select Manage AUTs... to pop up the Manage AUTs dialog (Section 8.3.8). Select the Attachable AUTs list entry, and press the Add... button. This will pop up the Add Attachable AUT dialog. The Name: must match the first argument passed to attachToApplication, and the Port: must match the port number used when starting the AUT with start*aut (Section 7.4.7). In the case where the attachable AUT is running on a different host from squishserver, you would specify the Host: here as well.

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. 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.

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. If you are using a local squishserver only the first argument (the attachable AUT name) needs to be provided.

Like the startApplication, the attachToApplication returns 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.21).