« Back to News

Getting Hands-on with WinAppDriver Test Automation Framework

Application automation always adds value to any Agile project. Most folks, including me, automate web applications using Selenium-like tools or Appium for mobile apps automation.

In a recent project, we worked with a Selenium and Java built framework. One of the core challenges while selecting an automation tool that can integrate with this framework was working with a Windows application. While there are several tools in the market such as UFT/QTP that can automate Windows application, they are cost-prohibitive. This has primarily been the reason they are not widely used. 

In this post, we show how to automate Windows applications using WinAppDriver, a free tool provided by Microsoft. 

Current open-source and freeware test automation frameworks

A few noteworthy freeware do exist, however, each tool has its own limitation.

Sikuli – Sikuli can automate anything that is displayed on the screen. It identifies screen objects using image recognition and controls GUI (Graphical User Interface) components. Since it is based on image comparison, the slightest difference between two machines (such as screen resolutions, operating system upgrades , etc.) will break the automation code. This makes Sikuli-based systems unsustainable and unmaintainable.

AutoIt – Auto-It is a BASIC-like scripting language designed for automating Windows GUI elements and general scripting. However, it uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). The lack of common scripting languages gives AutoIt a steep learning curve. 

WiniumWinium is a Selenium-based tool for testing and automating desktop applications on a Windows desktop. It uses selenium-based libraries however the community has made only two releases and there is no active work or maintenance since then.

WinAppDriver – WinAppDriver uses selenium-like libraries and is actively supported by the community and is developed by the makers of Windows OS – Microsoft. Windows Application Driver supports Selenium-like UI test automation for Windows applications. The service supports automated testing of Universal Windows Platform (UWP), Windows Forms (WinForms), Windows Presentation Foundation (WPF), and Classic Windows (Win32) apps on the Windows 10 operating system. Winappdriver complies with the JSON Wire Protocol and some application management functionalities defined by Appium. This service provides better support for using Appium to test Windows Applications.

Why is WinAppDriver preferred over other tools? 

  • It uses the WebDriver protocol
  • WinAppDriver is free and developed by Microsoft
  • Easily integrates with existing framework
  • It can run as a standalone app and as a plugin for Appium

Installing and Running Windows Application Driver

WinAppDriver runs on a Windows 10 PC and needs any Appium test runner (Samples and Tests in this repository use Microsoft Visual Studio as the test runner)

  1. Download Windows Application Driver installer from https://github.com/Microsoft/WinAppDriver/releases
  2. Run the installer on a Windows 10 machine where your application under test exists and will be tested
  3. Enable Developer Mode in Windows settings

To run the application, simply start WinAppDriver.exe from its installation directory (E.g. C:\Program Files (x86)\Windows Application Driver)

Windows Application Driver will then be running on the test machine listening to requests on the default IP address and port (127.0.0.1:4723). You can now run any Tests or SamplesWinAppDriver.exe can be configured to listen to a different IP address and port as follows:

WinAppDriver.exe 4727
WinAppDriver.exe 10.0.0.10 4725
WinAppDriver.exe 10.0.0.10 4723/wd/hub

Note: You must run WinAppDriver.exe as an administrator to listen to a different IP address and port.

Inspect a windows UI element 

To start inspecting a windows UI element, we need the Windows kit which can be downloaded from here: https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk

The latest version of Microsoft’s Visual Studio includes the Windows SDK by default along with the Inspect tool to inspect the application under test. This tool shows every UI element/node which can be queried using the Windows Application Driver. 

The inspect.exe tool can be found under the Windows SDK folder which is typically C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64

In this example, I am inspecting the elements of the Calculator application.

Writing the Automation

You can use several programming languages with WinAppDriver to code the automation. In this example, I am using Java with TestNG. Listed below is the code to launch the session for the Calculator application:

@Setup
public void TestInit()
{
  DesiredCapabilities appCapabilities = new DesiredCapabilities();
  appCapabilities.setCapability ("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App ");
  appCapabilities.setCapability ("deviceName", "WindowsPC");
  WindowsDriver driver = new WindowsDriver(new URL("http://127.0.0.1:4723/") ,appCapabilities);
  driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
}

Locators:

Appium supports several locators such as accessibility ID, class name, ID, name, tag name , and xpath.

Most widely used attributes are ID, name, xpath and accessibility ID. The preferred way to automate the application is by using the accessibility ID. Test cases using accessibility ID are faster as when compared with ones using name and xpath. Obtaining certain accessibility IDs needs developer attention.

Conclusion

WinAppDriver is a great open-source tool from the makers of the Windows OS. With support for different scripting languages and easy integration with Selenium and Appium, WinAppDriver has become the go-to choice for test automation of Windows applications. 

Get WinAppDriver from Github. More detailed documentation is available on the Wiki

Leave a Reply

About the Writer

  • Vrushalee Ajotikar

    Vrushalee is QA lead at Synerzip. She has about a decade of experience in Core Java, Selenium, Appium, and Gatling and loves exploring newer automation technologies. Vrushalee is an SCJP certified professional and holds a Masters in Computer Science from Pune University.

How can Synerzip Help You?

By partnering with Synerzip, clients rapidly scale their engineering team, decrease time to market and save at least 50 percent with our Agile development teams in India.