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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MSTest.Windows.UIAutomation" Version="4.5.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MSTest.Windows.UIAutomation" Version="4.5.2" />
                    
Directory.Packages.props
<PackageReference Include="MSTest.Windows.UIAutomation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MSTest.Windows.UIAutomation --version 4.5.2
                    
#r "nuget: MSTest.Windows.UIAutomation, 4.5.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MSTest.Windows.UIAutomation@4.5.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MSTest.Windows.UIAutomation&version=4.5.2
                    
Install as a Cake Addin
#tool nuget:?package=MSTest.Windows.UIAutomation&version=4.5.2
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.5.2 93 10/27/2026
4.5.1 175 10/7/2026