How to automate tests for an older desktop application
Updated:
An older application, often described as a legacy application, may have handled invoicing, warehouse operations or production for years, even though its documentation is no longer complete and its original authors are unavailable. Concern about side effects then slows down every change. Automated tests can reduce the risk, but the technical state of the application and its environment needs to be verified first.
Why testing an older application is challenging
The age of the code is not the only problem. The application may depend on a specific version of Windows, a local database, a shared drive or a service that nobody has documented accurately. Test data is prepared manually, and often only an experienced user knows the correct outcome of a scenario.
The user interface may combine Win32, WinForms, WPF and custom components. Some elements are visible through Windows UI Automation, while others provide little information or can only be controlled with the keyboard. It is therefore not accurate to promise that every older application can be automated without modifications and without access to the source code.
Another risk is making the initial scope too large. Trying to convert an entire long-standing manual regression checklist at once creates an expensive suite before the team has verified that its foundations are stable.
How to proceed in smaller, verifiable steps
We begin by describing one critical process together. An experienced user demonstrates the input data, individual steps and the outcome they consider correct. This creates the first clear specification even in a project without documentation.
We then perform a technical assessment:
- identify the technologies used and the environment dependencies,
- inspect the elements through the Win32 interface and Windows UI Automation,
- find stable identifiers and the places where they are missing,
- prepare repeatable test data and a way to restore the state,
- create a pilot that checks the outcome, not just the clicks.
We can use pywinauto or FlaUI for control. If an element is unavailable through the system interface, we first consider a small change to the application, such as adding an identifier. We use images, keyboard shortcuts or coordinates only for specific purposes and with an understanding of their limitations. The reasons are explained in Why desktop tests should not rely on coordinates and images.
After a successful pilot, we add scenarios according to business impact and frequency. Installation, updates and data migration deserve separate attention because they connect the old and new versions as well as their data formats.
Observed behaviour is not necessarily correct
When documentation is missing, record what the application does today, but distinguish it from the required outcome. An experienced user may also know a workaround for a long-standing bug. A test that adopts it without discussion could later obstruct a fix.
For each scenario, record the input, observed result, approved expectation and open questions. If the user and developer disagree on the result, leave that part undecided. Automation should not replace a business decision. Start with a flow the team understands and whose output it can check independently.
Build a recoverable test environment
Record the program and Windows versions, data schema, connection settings and required supporting components. Include dependencies users do not see while working, such as an export directory or source of reference data. This is information needed to repeat your specific process, rather than a list of mandatory technologies.
Check that the program uses a test database and test directories. Restoring only a local database may not undo changes on a shared drive or in an external service. Prepare a recovery procedure for every place the scenario writes to. Copies of real data need a separate data-protection assessment, since environment separation alone is insufficient.
Before expanding the suite, restore the initial state and repeat the pilot without manually supplying missing data. If setup fails, mark the scenario as unverified. The report should distinguish a failed startup from a failure in the business process.
Choose a tool based on the actual controls
The pywinauto getting started guide recommends inspecting the available Win32 or UI Automation interface first. Check the main window, table, row editor and error dialog in the same process. A tool that finds the main window may still be unable to read cells in a custom table.
Limit searches to the correct application instance and check that the element matches uniquely. A window title may contain the open document’s number, and a button’s position in a list may shift after a screen change. Check the combination of identifier, control type and parent window in different states. Wait for an available control or a specific result with a time limit, rather than use an arbitrary pause.
pywinauto provides a Python interface, while FlaUI targets .NET. The choice should also reflect the language the team can maintain. If control information is missing, the assessment may recommend an application change or leaving part of the scenario for manual checking.
An illustrative pilot: issue two units from inventory
Consider a test warehouse application with item TEST-A, which initially has five units. The approved requirement says that a saved issue of two units must leave three units and one stock-issue record.
| Step | Expected result |
|---|---|
| Prepare owned data | The item has five units and no stock issue from this test exists. |
| Create the stock issue | The record contains the correct item and a quantity of two. |
| Save | One stock issue is created and three units remain. |
| Close and reopen the program | The saved stock issue and quantity remain intact. |
| Restore test data | The next run can start from the same conditions. |
Check the saved result through an available output, export or authorised access to test data. A “Saved” message alone does not confirm the stock level. Separately try cancelling an unfinished issue and entering an invalid quantity. The product must define the expected response, rather than let the test derive it solely from today’s screen.
The pilot must also work in the intended run environment
If the suite will run on a remote machine, try it there. The pywinauto remote execution guide identifies limitations with minimised or disconnected RDP sessions and locked desktops. Some methods need an active desktop, while others may work depending on the application. Success on a developer’s computer is therefore insufficient.
For scenarios sending actual keyboard or mouse input, reserve a session without another user’s interference. Check startup through the same mechanism CI will use. Do not disable workstation security rules for testing. If a dedicated test environment is needed, agree on its operation and access.
For a failed run, save the program version, prepared state, last completed step, available screenshot and observed result. Before adding automation, assess whether repeated runs check the same process and whether failures can be explained. Expand coverage after that. The number of scenarios clicked through alone does not establish that the suite is maintainable.
What you gain
Critical processes gain repeatable checks, while living documentation of their expected behaviour is created at the same time. The team can make safer changes to parts of the application that currently rely only on the memory of a few people.
Automation can also reveal obstacles: missing identifiers, unstable data or a dependency on a single environment. These findings help determine what is worth fixing and what should remain subject to manual verification for now.
Next step
Choose one frequently used process with a clear outcome and prepare recoverable test data for it. A pilot helps assess how reliably elements can be controlled and which modifications are needed. The article on automating these applications also explains the technical foundations for WPF and WinForms.