In my last blog entry I described what the new Microsoft UI Automation (MUIA) library is. Now let me walk you through a very simple Hello World example for Microsoft UI Automation. Check out the image below to see where I’m headed. The screenshot shows I created a console application test harness which uses MUIA to test a simple .NET form-based application. Prepare the example by installing the .NET Framework version 3.0 on your machine if necessary. Begin by creating a simple .NET form-based application named HelloWorld at a directory named C:\MUIADemo which simply displays "Hello world" in textBox1 when button1 is clicked. Now create a new C# console application Project named TestAuto at C:\MUIADemo. In TestAuto, locate and add Project References to the UIAutomationClient.dll and UIAutomationTypes.dll libraries. Now add a "using System.Windows.Automation" statement to your code. Then add using statements to System.Diagnostics and System.Threading. Now type this code into the Main() method of your test harness:
Console.WriteLine("\nMUIA test automation demo \n");
Console.WriteLine("Launching app, clicking button1 now");
Process p =
Process.Start("..\\..\\..\\HelloWorld\\bin\\Debug\\HelloWorld.exe");
Thread.Sleep(5000);
AutomationElement aeForm =
AutomationElement.FromHandle(p.MainWindowHandle);
AutomationElement aeButton = aeForm.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, "button1"));
AutomationElement aeTextBox = aeForm.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.ControlTypeProperty,
ControlType.Edit));
InvokePattern ipClickButton1 =
(InvokePattern)aeButton.GetCurrentPattern(InvokePattern.Pattern);
ipClickButton1.Invoke();
Console.WriteLine("\n . . .check value in textBox1 and
print pass/fail here");
Console.ReadLine();
Process.Start("..\\..\\..\\HelloWorld\\bin\\Debug\\HelloWorld.exe");
Thread.Sleep(5000);
AutomationElement aeForm =
AutomationElement.FromHandle(p.MainWindowHandle);
AutomationElement aeButton = aeForm.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, "button1"));
AutomationElement aeTextBox = aeForm.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.ControlTypeProperty,
ControlType.Edit));
InvokePattern ipClickButton1 =
(InvokePattern)aeButton.GetCurrentPattern(InvokePattern.Pattern);
ipClickButton1.Invoke();
Console.WriteLine("\n . . .check value in textBox1 and
print pass/fail here");
Console.ReadLine();
Build and run your harness. Let me point out that this is just a simple example to get you started with Microsoft UI Automation. The code above has many problems and isn’t usable in a production environment. I just finished writing up a thorough introduction to Microsoft UI Automation for my monthly Test Run column which appears in MSDN Magazine and I’m hoping that the article will be printed sooner rather than later.
.NET Test Automation Recipes
Software Testing
SciPy Programming Succinctly
Keras Succinctly
R Programming
2026 Visual Studio Live
2025 Summer MLADS Conference
2026 DevIntersection Conference
2025 Machine Learning Week
2025 Ai4 Conference
2026 G2E Conference
2026 iSC West Conference