Attaching to Running Applications
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.
In order for Squish to be able to connect to the AUT, you must start the AUT using Squish's start*aut 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.
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.
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 panel. 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 ApplicationContext attachToApplication(autName), and the Port: must match the port number used when starting the AUT with start*aut. In the case where the attachable AUT is running on a different host from squishserver, you would specify the Host: here as well.
It is also possible to register an attachable application on the command line, without using the Squish IDE at all. For example:
$ squishserver --config addAttachableAUT addressbook localhost:9999
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 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 ApplicationContext attachToApplication(autName) 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.
It is possible to record a test script if we are attched to an AUT. To do so, we can simply click Record ( ). 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).
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.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.