Headless Platform
Introduction
The headless platform in AvaloniaUI provides the capability to run Avalonia applications without a visible graphical user interface (GUI). This allows for testing and automation scenarios on systems that lack a graphical environment, such as servers or continuous integration/continuous deployment (CI/CD) environments.
By utilizing the headless platform, you can perform UI testing, execute application scenarios, and validate functionality in a headless environment, saving time and resources compared to manual testing.
Getting Started
While the Headless platform can be initialized without any dependencies, for convenience, we have created integration packages for common unit testing platforms:
- Headless Testing with XUnit
- Headless Testing with NUnit
- If you are using another platform or need more control: Manual setup of the Headless platform
Simulating User Input
As the headless platform doesn't have any real input, every event needs to be raised from the unit test. The Avalonia.Headless package is shipped with a number of helper methods that can be used:
Window.KeyPress(Key key, RawInputModifiers modifiers)
Simulates a keyboard press on the headless window/toplevel.
Window.KeyRelease(Key key, RawInputModifiers modifiers)
Simulates a keyboard release on the headless window/toplevel.
Window.KeyTextInput(string text)
Simulates a text input event on the headless window/toplevel.
This event is independent of KeyPress and KeyRelease. If you need to simulate text input to a TextBox or a similar control, please use KeyTextInput.
Window.MouseDown(Point point, MouseButton button, RawInputModifiers modifiers)
Simulates a mouse down event on the headless window/toplevel.
In the headless platform, there is a single mouse pointer. There are no helper methods for touch or pen input.