WinAppDriver — Automation of Desktop apps using selenium like tool

Bangadsandeep
4 min readAug 12, 2021

--

WinAppDriver

Windows Application Driver (WinAppDriver) is a service to support Selenium-like UI Test Automation on Windows Applications. This service supports testing Universal Windows Platform (UWP), Windows Forms (WinForms), Windows Presentation Foundation (WPF), and Classic Windows (Win32) apps on Windows 10 PCs.

What makes it such an amazing tool and one of the best tools in the field of automation for desktop applications?

Free of cost

It uses WebDriver protocol

Developed by Microsoft

What does this tool means to QA? Well, it means you can aware of desktop automation technique along with web and mobile apps with selenium like test automation. With this article let us fill the desktop automation knowledge by knowing this amazing tool.

Since this is Selenium-like UI Test Automation we can use the same syntax like we use in Selenium, create Page Object, and use other methods like sendkeys, isdisplayed, etc...

driver.findElement(By.xpath("//Button[@Name='Sign in']")).click();

Configuring the Environment

There are few steps to configure the environment

  • Download and install WinAppDriver from here.
  • Download and install Windows 10 SDK from here.
  • Once WinAppDriver is installed, we need to enable ‘Developer mode’ in our operating system . 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:
  • Initialize WinAppDriver, Before you can run your tests you need to start the WinAppDriver server. By default you can find it here: C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe

Once opened it starts listening on port 4723. In your tests, we connect to this URL. Start the WinAppDriver session and minimize it. It’s ready to accept our test requests.

Why we installed Windows 10 SDK?

Windows SDK comes with a great tool to inspect the application you are testing. This tool allows us to see every UI element of the application through which we are going to perform automation. This inspect.exe tool can be found under the Windows SDK folder which is typically C:\Program Files (x86)\Windows Kits\10\bin\{Windows build version}\x64

Lets open inspect.exe and see how can it help us to find the objects. I have used calculator as application

Other tool which you can use to verify / locate elements is VisualUIAVerifyNative.exe, You can find it under below location

C:\Program Files (x86)\Windows Kits\10\bin\{Windows Build Version}\x86\UIAVerify\VisualUIAVerifyNative.exe.

If you are a Mac user there is also an Appium Mac Driver available.

Locating elements

The locators supported by WinAppDriver are moreover similar like selenium.

We can use one of the below locator strategy in our automation

  • findElement(By.name(“Seven”)
  • By.xpath(“//Button[@Name=’Pay cash’]/preceding::Button[4]”);
  • findElementByAccessibilityId(“CalculatorResults”); // use AutomationId
  • FindElementByClassName(“#32769”); // use Classname
  • FindElementByTagName(“group”); // use LocalizedControlType
  • FindElementById(“42.22.891”); // use RuntimeId ( rarely used as the runtime ID is not a constant like AutomationId or Name.)

How to write automation tests

Before we start with creating our automation tests there are couple of important things which we need to perform.

First :- Add below couple of dependency in our project

https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java

https://mvnrepository.com/artifact/io.appium/java-client

Second :- Understand how to get APP model User ID from here . This is how we invoke our application and attach to WinAppDriver session.

Step 1 :- Initiate the instance of WinAppDriver , setup application path and Specify the IP Address and Port to run our tests on. Make sure IP address and port matches with the address of already running session and Port number respectively. We can wait for 2 sections to invoke the application of create a method to wait till the application is invoked

DesiredCapabilities capabilities = new DesiredCapabilities();capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");CalcSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities);CalcSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

Step 2 :- Create test case i.e perform pressing on button and verifying the output. Below is the example where we perform various calculator operations and verify the end results. In below example you can see I have used different locator strategies so that you can see all of them in action.

CalcSession.findElement(By.name("Seven")).click();CalcSession.findElementByAccessibilityId("minusButton").click();CalcSession.findElementByName("Four").click();CalcSession.findElementByXPath("//Button[@Name='Equals']").click();System.out.println("Your final result for substraction is : - " + CalcSession.findElementByAccessibilityId("CalculatorResults").getText().replace("Display is", "").trim());

Do not forget to dispose the app driver at the end of your tests. Also, always make sure to close the WinAppServer.exe after the tests’ execution.So overall code for simple case look like as below which can converted modular.

We can utilize all set of automation framework key elements with WinAppDriver like page object pattern, a set of guidelines for coding standards , test-data handling , object repository treatment, html reports, etc…

In todays world we have lot of critical processes everyday in our business work which involves several applications, i.e. desktop, Mobile and web applications. This makes it especially challenging to test those processes with conventional methods.

Now knowing automation tool like WinAppDriver, we can leverage our automation by combining WinAppDriver with Selenium/Appium automation and build cross- application Test Automation.

I hope that this tutorial was useful and allowed you to know on how can we perform automation testing for window based apps. You can apply many concepts and improve automation tests and achieve extra mile.

--

--

Responses (1)