logo logo

WinAppDriver – Free Test Automation Tool for Windows Desktop Applications

WinAppDriver

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?

  • It’s free
  • It’s developed by Microsoft
  • 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.

Table of Contents

Configuring the WinAppDriver Environment

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

  1. Initial setup is 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();
}

Pros of WinAppdriver:

  • It is an open-source tool and it uses the web driver protocol.
  • It is free and developed by Microsoft.
  • WinAppDriver can integrate with selenium and Appium projects in the same language.
  • You can use any programming language in WinAppDriver.
  • You can use Xpath and other properties to locate UI elements.

Cons of WinAppDriver:

  • It doesn’t support all operating systems. It supports only Windows 10, not macOS or Linux.
  • It doesn’t have a record and playback option.
  • No built-in support for ALM integrations.

Conclusion

Many automation tools for windows applications are available in the market for website automation or for mobile apps automation, such as selenium which works well with any browser like Chrome, Firefox, etc. However, Selenium is better to use for web applications, while there are tools like Appium that are used for testing Android/iOS applications.  

Not only Selenium there are numerous options available with the applications when it comes to testing desktop apps, but the Winium desktop testing solution also allows to cover the automation of all types of desktop apps. Winium is executed on the protocol of JSONWire, which is used by Selenium and it can be used for inspecting window-based application elements for effective desktop test automation. 

Already tried out WinAppDriver? Share your experience in the comments! 💫

Reference: http://atidcollege.co.il

About the author

Yoni Flenner

A software engineer who likes to test things programmatically, and he’s doing it for a living for the past 10 years: https://atidcollege.co.il

Comments

14 3 comments
  • poras vedi November 15, 2021, 4:32 pm

    Nice article! I tried out WinAppDriver and Appium to automate 3rd party applications, there is a small thing that concerns stable versions for Appium, for ex: Appium -python-client v2.0 is not working with WinAppDriver v1.2.1, but the same works with Appium v1.1 so my question is that is stable or not?

  • sebastian svensson January 13, 2022, 10:10 am

    Good information!
    I’ve got a current project where I use WinAppDriver for testing a .Net client, is there anyway to implement UI testing for Windows applications in TestProject? I’ve tried it out with the GenericDriver but I’m having some problems where the agent just skips the test, am I missing something here?

  • Karen Teboulle January 16, 2022, 4:43 pm

    Hi Sebastian,
    TestProject does not support Windows apps (we support testing Web / Android / iOS native & hybrid apps). For Windows app testing I’d recommend you explore our parent company’s solution – Tricentis Tosca: https://www.tricentis.com/products/automate-continuous-testing-tosca/

Leave a Reply

FacebookLinkedInTwitterEmail