Running Windows desktop tests from Linux with disposable VMs
Testing Windows desktop applications has been a highly requested feature from customers, but the infrastructure to parallelize thousands of runs per month does not exist. Web testing infrastructure is relatively easy, as headless browsers start quickly in Linux containers, cost a fraction of a cent, and are discarded after each test.
However, there is no equivalent for testing Windows desktop apps. To address this challenge, a new approach was taken: treating Windows machines as disposable devices similar to smartphones, rather than servers.
The basic architecture borrows from the existing mobile testing infrastructure due to similar constraints. Windows machines are modeled as devices in Kubernetes, allowing tests to request a VM with a DeviceClaim, control the device remotely, and release it when the test is complete. To support this, Windows needed two extensions to the device model: the ability for a device to live outside the Kubernetes cluster (e.g., a GCE VM) and for a claim to return a desktop's connection addresses, including Chrome DevTools Protocol (CDP) for browsers.
The runner follows a lifecycle that mirrors that of mobile runners (claim, heartbeat, record, connect, run, release). Tests communicate with native apps through WebdriverIO and Appium, just like mobile tests. Private Windows pools function similarly to private iOS device pools.
The Windows runner communicates with the VM using three connections: Playwright connects through CDP for browser interactions, and Appium handles native Windows apps. A WebRTC stream carries the screen so that test results can be viewed live and recorded afterwards.
When a Windows test needs a machine, it asks the device scheduler, the same in-house service already handling Android emulator requests. The scheduler has two new jobs: maintaining a stock of VMs rented from Google Compute Engine and assigning one to each test that requests it. The scheduler tracks the fleet through Kubernetes custom resources, ensuring the fleet's state is durable and visible.
If the scheduler restarts, it reads the records and resumes where it left off, allowing engineers to inspect any pool or VM using standard Kubernetes tools. Giving a machine to a test starts with a DeviceClaim, the same object used to claim an emulator. The scheduler matches the claim to a ready VM from the appropriate pool and returns its connection addresses to the runner.
Keeping the fleet stocked is the reconciler's responsibility within the scheduler. It continuously compares the records against what's running in GCE and creates additional machines if needed. When a test releases its claim, the VM is deleted. Windows VMs take several minutes to create and boot, so the reconciler manages them in short passes and updates their records accordingly. A slow boot does not disrupt other tasks handled by the scheduler.
The key challenge in desktop test infrastructure is balancing the need for clean machines and fast machines. Rebooting a machine from a fresh image takes minutes, while reusing a machine means inheriting any changes from the previous test. Making machines disposable eliminates a significant amount of work typically associated with managing a Windows fleet, such as patching long-running machines, cleaning up after tests, and resolving discrepancies between machines.
Native apps cannot run automated UI tests on a clean Windows machine, so a base machine image must be built with Appium, the Appium Windows driver, and Microsoft's WinAppDriver installed, configured, and running inside a live desktop session before the first test arrives.
Rewritten by urgent.news; may contain errors — check the original.
Sources: qawolf.com · dev.to