WinAppDriver – Free Test Automation Tool for Windows Desktop Applications

Almost every tester out there is familiar with Selenium WebDriver for automating Web applications, and many are also familiar with Appium for automating Mobile apps. However, not as many are familiar with automation tools for desktop applications. This post will discuss one of the most popular tools in the field of test automation for desktop applications – WinAppDriver (short for Windows Application Driver).

A while back, I wrote a post reviewing the pros and cons of 9 open source test automation tools for desktop applications. In this post I will discuss one that is not included in that list, that is relatively new and that comes from a great “home”  😉  – From Microsoft, and it makes perfect sense to test Windows desktop apps using a tool from the same company.

WinAppDriver is a free tool (currently the WinAppDriver code is not open source, but in their FAQs it’s mentioned that they are considering the option to open source it). It is supported on machines running Windows 10 operating system (Home and Pro) and Windows Server 2016, and it supports all Windows applications based on: WinForms (Windows Forms), WPF (Windows Presentation Foundation), UWP (Universal Windows Platform) and the classic Win32.

What makes it such an awesome tool and leader in its field of automation for desktop applications?

  1. It’s free
  2. It’s developed by Microsoft
  3. And most importantly – it uses the WebDriver protocol

What does this mean? Well, it means that if you’re from the web/mobile automation world and you already know how to develop using the WebDriver environment, then the transition to WinAppDriver will be easy, quick and clear for you. As in the WebDriver environment, with WinAppDriver’s environment we will also identify elements with findElement, we will also work with Page Object and we will also use the same methods such as: clear, sendKeys, click, etc.

It’s important to mention that WinAppDriver can run as a standalone as well as a plugin for Appium. Thus, if you are already running Appium’s server, then a request for Win10 app automation will launch WinAppDriver.exe.

 

Configuring the WinAppDriver Environment

There are few steps we’ll have to go through in order to work with WinAppDriver.

1) Download and install WinAppDriver from: https://github.com/Microsoft/WinAppDriver/releases (you need to choose the file: WindowsApplicationDriver.msi). It’s a simple “next-next” installation.

2) Enable “Developer Mode” in our operating system (Win10): Let’s open the Settings menu, go to Update & Settings and choose the option “For Developers” and then click on “Developer Mode” as seen in the image below:

WinAppDriver 1

 

3) Download and install Windows SDK. In order to identify the elements in our Desktop application, we’ll need to use a tool for that, called: inspect.exe. This tool comes as part of the Windows SDK package we will install:

WinAppDriver2

WinAppDriver3

In the Nuget Package Manager (with Visual Studio) we will configure the relevant libraries:

  • Selenium.WebDriver
  • Selenium.Support
  • Nunit
  • Nunit3TestAdapter
  • Appium.WebDriver

WinAppDriverNuget

 

Using Inspect

We will use Inspect tool to identify UI Elements of the application under test. In this example, I’ve opened the Sticky Notes application and tried to identify the elements of this application with Inspect:

WinAppDriverInspect

Writing the Automation

With WinAppDriver you can use a variety of programming languages. In this example, I’ve decided to use C# with Nunit. Below is the code I used to launch the session to the Sticky Notes application:

[SetUp]
public void TestInit()
{
  var appCapabilities = new DesiredCapabilities();
  appCapabilities.SetCapability("app", @"Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe!App");
  appCapabilities.SetCapability("deviceName", "WindowsPC");
  driver = new WindowsDriver(new Uri("http://127.0.0.1:4723"), appCapabilities);
  driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
}

In this code example you can see how I used the driver object from WindowsDriver class that inherits from the AppiumDriver class (which implements the RemoteWebDriver). You can see the hierarchy in the screenshot below:

WinAppDriverWindowsDriver

 

Once we reach the step of initiating the driver, we need to turn to the local address (in our example) with port 4723, which is the default port of Appium Server. Now, once our driver has been initiated, we can start working with it in order to execute methods from the familiar WebDriver protocol:

[Test]
public void Test01()
{
  driver.FindElement(By.Id("ContentElement").Click();
        driver.FindElement(By.Id("NoteMenuButton")).Click();
        driver.FindElement(By.Name("All notes")).Click();
}

[TearDown]
public void TestCleanup()
{
  driver.Quit();
}

 

Have you already tried out WinAppDriver? Share your experience in the comments below!  🙂

 

Reference: http://atidcollege.co.il