How to use WinApp driver with Python for desktop application automation?

Posted by: admin September 19, 2023 No Comments
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.

Winapp is a Product of Microsoft, using this driver we can automate Windows applications, classic Windows applications, universal Windows applications, and mobile applications. We can use this driver on the top of an Appium library.

Pre-requisites:

  • Windows 10 OS
  • Winappdriver.exe
  • Inspect.exe for identifying your element value
  • Appium-Python-Client
  • App for automate
  • Your PC should be on Developer mode (ON)

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

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.

Configuring the WinAppDriver Environment

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

Step 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.

Step 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:

1

Step 3: Download and install Windows SDK from link below. 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:

https://go.microsoft.com/fwlink/p/?linkid=2083338&clcid=0x409

2

Downloading Appium

You can download the Appium for python from the command below:

pip install Appium-Python-Client

Using Inspect.exe

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

3

Writing the Automation Code

With WinAppDriver you can use a variety of programming languages. In this example, I’ve decided to use Python. Below is the code I used to launch the session to the Calculator application:

4

Finding UI elements with Inspect.exe

UI elements can be identified mainly using following 2 control locators:

  1. Automation Id
  2. Name
  3. Class Name

Following screenshot demonstrate how and where these locators appear on inspect.exe:

5

Running Test cases

You must start WinAppDriver first to start the session and then run your code.

6

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:

7

Once we run the code, you will see your test cases in action.

Leave a Reply