Choose a testing helper
The testing helpers are included in ProTest.Avalonia.Headless, and therefore in both xUnit adapter installations. Use them inside an Avalonia test or a manual headless session.
| Goal | API | Reference |
|---|---|---|
| Exercise platform keyboard/mouse processing | HeadlessWindowExtensions | Platform input |
| Raise pointer events on a selected control | TouchInputSimulator, MouseInputSimulator | Touch, mouse |
| Compose keyboard shortcuts and text input | KeyboardInputSimulator | Keyboard |
| Raise processed gesture events | GestureSimulator | Gestures |
| Feed pointer events through actual recognizers | GestureRecognizerTestHelper, MultiTouchTestHelperFactory | Recognizers, multi-touch |
| Find descendants and inspect ancestry | VisualTreeTestHelper, LogicalTreeTestHelper | Visual, logical |
| Combine type, state, name, and property filters | ControlFinder | Control finder |
| Query with path expressions | TreeXPath | XPath |
| Validate or compare a tree | TreeValidator, TreeComparer, TemplateComparer | Validation, comparison, templates |
| Use Appium-style locators and action chains | AvaloniaDriver, By, Actions, TouchAction | Automation |
| Wait for changing UI state | DriverWait, ExpectedConditions, WaitHelper | Waits |
| Capture a sequence of frames | HeadlessScreenRecorder, RecordedTouchSimulator | Recording |
| Convert recorded PNGs into a video | VideoConverter | Video conversion |
Namespaces
using Avalonia.HeadlessTestingFramework;
using Avalonia.HeadlessTestingFramework.Appium;
using Avalonia.HeadlessTestingFramework.Recording;
The helpers operate in process. They do not launch a native window or connect to a WebDriver server. Pointer-event helpers target the supplied control; the platform's Window.MouseDown / MouseUp methods exercise hit testing from window coordinates.
Query a control tree
var panel = new StackPanel
{
Children =
{
new Button { Name = "Save", Content = "Save" },
new TextBox { Name = "Title", Text = "Draft" }
}
};
var window = new Window { Content = panel };
window.Show();
try
{
var save = window.GetByName<Button>("Save");
Assert.True(ControlFinder.From(window).OfType<TextBox>().Any());
Assert.Equal("Save", save.Content);
}
finally
{
window.Close();
}
For recognizer-based gestures, configure handlers and recognizers before attaching the control to a window. See gesture registration.
The API catalog lists every imported source component and its public signatures.