💻 Desktop Automation Guide / Masaüstü Otomasyon Rehberi
This guide explains how to test Windows desktop applications (WinForms, WPF, WinUI) with Automation Sandbox.
💡 Select Language / Dil Seçin:
🇬🇧 English Guide
How Desktop Capture Works
- FlaUI.UIA3 attaches to your running Windows process (e.g.
WinFormsApp.exe). UiTreeWalkerreads all controls (Buttons, TextBoxes, DataGrids, Windows).- The UI tree is converted into a standard
UiElementInfoobject structure.
Complete C# Desktop Capture & Test Example
using System;
using AutomationSandbox.Discovery;
using FlaUI.Core;
using FlaUI.UIA3;
using AutomationSandbox.UiModel;
using AutomationSandbox.SelfHealing;
class DesktopTest
{
static void Main()
{
// 1. Configure scan options
var options = new DiscoveryOptions
{
MaxDepth = 10, // How deep to scan
MaxElements = 3000, // Maximum controls limit
Timeout = TimeSpan.FromSeconds(5), // Safety timeout
IncludeOffscreen = true // Also capture offscreen controls
};
// 2. Attach to running Windows application
using var automation = new UIA3Automation();
var app = Application.Attach("WinFormsApp.exe");
var mainWindow = app.GetMainWindow(automation);
// 3. Capture live UI tree
DiscoveryResult result = UiTreeWalker.Discover(mainWindow, options);
Console.WriteLine($"Captured {result.CapturedCount} controls in {result.Elapsed.TotalMilliseconds}ms.");
// 4. Resolve broken locator against captured live tree
var expected = new UiElementInfo
{
ControlType = "Button",
AutomationId = "btnSave_Old",
Name = "Save Changes"
};
HealResult healResult = SelfHealingResolver.Resolve(expected, result.Root);
if (healResult.IsConfident)
{
Console.WriteLine($"✅ Found matched control: {healResult.Matched?.AutomationId} (Score: {healResult.Score:F2})");
}
}
}
To point this at any real desktop application instead of a hand-authored expected snapshot -
by exe path or by attaching to an already-running process - see the runnable
samples/DesktopAppExplorerQuickstart
sample, which also reports locator health (empty/duplicate AutomationId counts) across the
whole captured tree.
🇹🇷 Türkçe Kılavuz
Masaüstü Yakalama Nasıl Çalışır?
- FlaUI.UIA3 kütüphanesi çalışan Windows uygulamanıza (
WinFormsApp.exe) bağlanır. UiTreeWalkersınıfları ekrandaki tüm elemanları (Butonlar, Metin Kutuları, Tablolar) tarar.- Ekran ağacı standart
UiElementInfoformatına dönüştürülür.
Tam C# Masaüstü Tarama ve Test Örneği
using System;
using AutomationSandbox.Discovery;
using FlaUI.Core;
using FlaUI.UIA3;
using AutomationSandbox.UiModel;
using AutomationSandbox.SelfHealing;
class DesktopTest
{
static void Main()
{
// 1. Configure scan options
var options = new DiscoveryOptions
{
MaxDepth = 10, // How deep to scan
MaxElements = 3000, // Maximum controls limit
Timeout = TimeSpan.FromSeconds(5), // Safety timeout
IncludeOffscreen = true // Also capture offscreen controls
};
// 2. Attach to running Windows application
using var automation = new UIA3Automation();
var app = Application.Attach("WinFormsApp.exe");
var mainWindow = app.GetMainWindow(automation);
// 3. Capture live UI tree
DiscoveryResult result = UiTreeWalker.Discover(mainWindow, options);
Console.WriteLine($"Captured {result.CapturedCount} controls in {result.Elapsed.TotalMilliseconds}ms.");
// 4. Resolve broken locator against captured live tree
var expected = new UiElementInfo
{
ControlType = "Button",
AutomationId = "btnSave_Old",
Name = "Save Changes"
};
HealResult healResult = SelfHealingResolver.Resolve(expected, result.Root);
if (healResult.IsConfident)
{
Console.WriteLine($"✅ Found matched control: {healResult.Matched?.AutomationId} (Score: {healResult.Score:F2})");
}
}
}
Bunu elle yazılmış bir expected snapshot yerine gerçek herhangi bir masaüstü uygulamasına
yöneltmek için - exe yoluyla ya da zaten çalışan bir işleme bağlanarak - çalıştırılabilir
samples/DesktopAppExplorerQuickstart
örneğine bakın; bu örnek yakalanan ağaçtaki locator sağlığını da (boş/tekrarlanan
AutomationId sayıları) raporlar.