Author : Edwin Hernandez Maynez
This article is a follow up on a previous post titled "UI Automation - Page Object Model and other Design Patterns" and is part of a series of posts related to UI Test automation, if you are interested in UI automation tools in general, we definitely recommend checking out our earlier post: "What are the best UI Test Automation Tools?" which was published on this same blog not so long ago. You may want to have a look at those two articles since it provides a high level view of what tools are available in the market for Functional UI Test automation, either for Web, Mobile or Desktop and then a deeper analysis of code design approaches.
In this article I will describe broadly the technical highlights of how Desktop UI automation is done and I will describe the main features of a relatively new test framework that is becoming a must-use for UI automation for Windows-based applications.
CodedUI is a Microsoft technology created to provide support of Desktop and Web UI automation, this technology is now deprecated and Visual Studio 2019 is the last version of VS that will include it. Microsoft has announced that it recommends the following technologies as replacements:
Given that announcement, if you have an interest or a need to be able to provide Desktop UI automation support for one of your projects, please read forward as I list the main features of WinAppDriver.
WinAppDriver is a test framework developed by Microsoft as an open source project, it's an implementation of Appium which is primarily a Mobile App framework, itself based on Selenium. Therefore WinAppDriver is a Selenium-like automation framework. This project is combining the best of two worlds, on one hand it encapsulates most of the technology of the now deprecated CodedUI and it fuses it with the flexibility, easiness of use and adoption of Selenium.
Just like Selenium, WinAppDriver is a set of libraries that can be integrated into any Test Runner that supports Appium. E.g. WinAppDriver scripts can be developed and executed with MSTest from Visual Studio.
Unlike Web UI automation, when working with Desktop applications, there is more variance on the technologies that could have been used to develop the application you are testing. This has an impact in the toolset's ability to identify and perform actions on a given UI element:
From <https://docs.microsoft.com/en-us/windows/apps/desktop/choose-your-platform>
CodedUI is an umbrella framework for Web and Desktop UI technologies:
UI Automation (UIA) and Microsoft Active Accessibility (MSAA) are two lower-level accessibility technologies used to provide access to UI elements. MSAA is now a legacy library while UIA is newer and more capable. UIA is an accessibility framework not a test framework and it is not meant to be used as such.
Both of these technologies are now under the hood of WinAppDriver, which is why WinAppDriver fully supports the desktop technologies listed above (UWP,WPF,Winforms & MFC).
I will provide a quick start guide and simple scripts on Visual Studio 2019:
using System;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;
namespace Blog
{
[TestClass]
public class UITests
{
[TestMethod]
public void SysInfoTest()
{
Process.Start(@"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe");
WindowsDriver<WindowsElement> SysInfoApp;
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", @"C:\Windows\System32\msinfo32.exe");
SysInfoApp = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);
SysInfoApp.FindElementByName("Help").Click();
SysInfoApp.FindElementByName("About System Info...").Click();
}
[TestMethod]
public void CalculatorTest()
{
Process.Start(@"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe");
WindowsDriver<WindowsElement> Calculator;
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
Calculator = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);
Calculator.FindElementByAccessibilityId("num5Button").Click();
Calculator.FindElementByAccessibilityId("plusButton").Click();
Calculator.FindElementByAccessibilityId("num3Button").Click();
Calculator.FindElementByAccessibilityId("equalButton").Click();
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.