Launching Applications with a Custom Working Directory via Squish


For engineers to test certain scenarios, the Application Under Test (AUT) needs to be launched in a so-called "well-defined" state. Applications commonly call on files stored in the current working directory, for example, configuration files or workspace directories. So by changing the working directory, one can have the AUT assume a certain well-defined state (e.g., by pre-populating a given directory with a workspace setup, defining the set of opened documents, and thereby having the AUT use that as its working directory.)

This tip demonstrates how you can customize the working directory in Squish.


We'll show two ways to achieve the above:

  1. Setting a fixed working directory in the test suite settings.
  2. Using a batch/shell script to have the working directory configurable in the script.


Via Test Suite Settings

Within the Squish IDE, you can customize the working directory by specifying it in the Test Suite Settings. To do so, click the Test Suites view's Test Suite Settings toolbar button. Under AUT Working Directory, choose Custom.

The AUT Working Directory is the folder from which the AUT is run. The default is the folder where the AUT's executable resides, but you can specify a custom location where you can either enter a path or browse to choose a path. You could also use an environment variable, for example:


If the environment in which the Squish tools execute has an entry of TEST_ENVIRONMENT=C:\TestFolder, then Squish will execute the AUT with the AUT's working directory set to the C:\TestFolder\myapp directory.

The disadvantage to this approach is that the working directory path is hardcoded in the test suite settings, and needs to be updated manually every time a different working directory is needed.

Via a Batch Script

We'll demonstrate using a batch script to start the application. Our example is the Qt Address Book example application packaged with every Squish download.

When using a batch file to launch a Qt AUT via Squish on WIndows, it's necessary to make a small adjustment to the line which starts the application. To allow Squish to hook into the application, the AUT must be started with a small wrapper application called dllpreload.exe.


:: The first parameter is assumed to be the desired working directory:
cd "%~1"
:: The second parameter is assumed to be AUT that should be launched;
:: hardcode all possible further parameters as properly handling all
:: possible variants is nearly impossible in batch files:
"%SQUISH_PREFIX%\bin\dllpreload.exe" "%~2" "%3"
:: END

When using the above batch file as the AUT, the following usage is without passing any AUT parameters:

startApplication('"path\to\launch_aut_with_working_directory.bat" "working_directory" "path\to\aut.exe"')

Below is a sample test script which uses the above batch file as the AUT, which in turn starts the Windows version of the Qt Address Book example application.

Prerequisites for this test script:

1) The two environment variables are set before the Squish IDE is started:

SQUISH_AUT_WORKING_DIRECTORY contains the path to the working directory.

SQUISH_AUT_EXECUTABLE_PATH contains path to the executable.

2) The batch file above, launch_aut_with_working_directory.bat, resides in the test suite directory.

3) The batch file has been registered as the AUT.

import os

def main():
    helper = squishinfo.testCase + "\\..\\launch_aut_with_working_directory.bat"
    working_directory = os.getenv("SQUISH_AUT_WORKING_DIRECTORY", "C:\\")
    aut = os.getenv("SQUISH_AUT_EXECUTABLE_PATH", "C:\\myaut\\myaut.exe")
    start_application_str = '"' + helper + '" "' + working_directory + '" "' + aut '"

Further Reading:

For more info on using shell or batch scripts as the AUT, take a look at our documentation.


    The Qt Company acquired froglogic GmbH in order to bring the functionality of their market-leading automated testing suite of tools to our comprehensive quality assurance offering.