MSTest.Windows.UIAutomation
4.5.2
Prefix Reserved
dotnet add package MSTest.Windows.UIAutomation --version 4.5.2
NuGet\Install-Package MSTest.Windows.UIAutomation -Version 4.5.2
<PackageReference Include="MSTest.Windows.UIAutomation" Version="4.5.2" />
<PackageVersion Include="MSTest.Windows.UIAutomation" Version="4.5.2" />
<PackageReference Include="MSTest.Windows.UIAutomation" />
paket add MSTest.Windows.UIAutomation --version 4.5.2
#r "nuget: MSTest.Windows.UIAutomation, 4.5.2"
#:package MSTest.Windows.UIAutomation@4.5.2
#addin nuget:?package=MSTest.Windows.UIAutomation&version=4.5.2
#tool nuget:?package=MSTest.Windows.UIAutomation&version=4.5.2
MSTest.Windows.UIAutomation
MSTest.Windows.UIAutomation integrates MSTest lifecycle management with the built-in Windows UI Automation API.
It launches a full-trust desktop application, discovers a window as an AutomationElement, and stops the application after each test.
This preview targets unpackaged Win32, WinForms, and WPF applications running in an interactive Windows session. It does not provide packaged MSIX/UWP/WinUI activation, elevated-process automation, a headless desktop, locators, automatic waits, screenshots, or a multi-window object model.
Getting started
Enable the feature when using MSTest.Sdk:
<Project Sdk="MSTest.Sdk/4.5.0">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<EnableWindowsUIAutomation>true</EnableWindowsUIAutomation>
</PropertyGroup>
</Project>
Then derive your test class from WindowTest:
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting.Windows.UIAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[STATestClass]
public sealed class MyAppTests : WindowTest
{
protected override ProcessStartInfo CreateProcessStartInfo()
=> new(@"C:\MyApp\MyApp.exe");
[TestMethod]
public void MainWindowIsAvailable()
=> Assert.IsNotNull(MainWindow);
}
ApplicationTest provides process lifecycle management. WindowTest additionally waits for a window and exposes it through MainWindow. Override FindWindow for launcher processes, splash screens, or applications whose desired window is not Process.MainWindowHandle. If the selected window belongs to a process other than the process created by CreateProcessStartInfo, also override StopApplication to track and stop that process.
Concrete test classes must declare [STATestClass]; MSTest test-class attributes are not inherited.
The package uses the UIA2 System.Windows.Automation API. Additional UI automation libraries can be layered on top when richer element interaction is needed.
Without MSTest.Sdk
Reference MSTest.Windows.UIAutomation together with MSTest.TestFramework, MSTest.TestAdapter, and Microsoft.NET.Test.Sdk, then import Microsoft.VisualStudio.TestTools.UnitTesting.Windows.UIAutomation. The package version should match the MSTest framework and adapter versions.
When restoring or building the Windows-targeted project on Linux or macOS, set:
<EnableWindowsTargeting Condition=" '$(EnableWindowsTargeting)' == '' and '$(OS)' != 'Windows_NT' ">true</EnableWindowsTargeting>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net9.0-windows7.0 is compatible. net10.0-windows was computed. |
-
net8.0-windows7.0
- MSTest.TestFramework (>= 4.5.2)
-
net9.0-windows7.0
- MSTest.TestFramework (>= 4.5.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
See the release notes at https://github.com/microsoft/testfx/blob/main/docs/Changelog.md#4.5.2.