The New Microsoft UI Automation Library, Part II

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 =
AutomationElement aeForm =
AutomationElement aeButton = aeForm.FindFirst(TreeScope.Children,
  new PropertyCondition(AutomationElement.NameProperty, "button1"));
AutomationElement aeTextBox = aeForm.FindFirst(TreeScope.Children,
  new PropertyCondition(AutomationElement.ControlTypeProperty,
InvokePattern ipClickButton1 =
Console.WriteLine("\n . . .check value in textBox1 and
  print pass/fail here");
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.
This entry was posted in Software Test Automation. Bookmark the permalink.