UKHO / winappdriver-demo

An example of using WinAppDriver to drive and test a simple WPF application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WinAppDriverExample

Build Status

WinAppDriver is an application built and maintained by Microsoft which enables Appium to drive native Windows applications using a Selenium style interface.

WinAppDriver is the Microsoft recommended approach to UI testing UWP, WPF, WinForms and MFC applications since the deprecation of CodedUI.

This demo project shows how to set up a UI test using WinAppDriver and to run it in a pipeline.

Using WinAppDriver

Follow instructions on https://github.com/microsoft/WinAppDriver to get WinAppDriver installed and running.

This blog post also has some good pointers on how to get started and complementary tools.

Other tools useful when writing desktop applications

Inspect.exe

Inspect.exe gives access to the UI Automation (UIA) tree used by WinAppDriver to drive the application. It can be accessed by installing the Windows SDK (by modifying your Visual Studio features in the Visual Studio Installer) and navigating to C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\inspect.exe.

Officially this is considered a legacy application and Microsoft recommend the use of Accessibility Insights for Windows instead.

Accessibility Insights for Windows

Accessibility Insights for Windows not only allows access to the UIA tree in a more modern interface than Inspect.exe, it also provides a tool with which to scan a visible UI for common accessibilty violations.

This tool is primarily designed for assessing a Windows application for user accessibility compliance and so there are a few differences to Inspect.exe

  • Navigation

    • Like Inspect.exe, the application watches the cursor and updates the UIA tree to reflect what is currently being hovered upon.
    • Press the pause button to stop watching the cursor.
    • Children and siblings of the current element may not be shown in the navigation tree view. These can be navigated to by using keyboard shortcuts defined in the settings.
  • Details

    • The properties shown can be configured and may not by default include properties important to UI automation such as the AutomationId.

Supported Locators to Find UI Elements

(Copied from https://github.com/microsoft/WinAppDriver/blob/master/Docs/AuthoringTestScripts.md)

Windows Application Driver supports various locators to find UI element in the application session. The table below shows all supported locator strategies with their corresponding UI element attributes shown in inspect.exe.

Client API Locator Strategy Matched Attribute in inspect.exe Example
FindElementByAccessibilityId accessibility id AutomationId AppNameTitle
FindElementByClassName class name ClassName TextBlock
FindElementById id RuntimeId (decimal) 42.333896.3.1
FindElementByName name Name Calculator
FindElementByTagName tag name LocalizedControlType (upper camel case) Text
FindElementByXPath xpath Any //Button[0]

Tips, Common problems and Gotchas

The WinAppDriver team has undergone some turmoil and as a result at the time of writing (May 2020) there are many open issues and outdated documentation.

Here are some pointers that we've found missing or hard to find in the documentation:

  • WinAppDriver only supports Windows 10
  • Run anything that is accessing the UI as administrator. This includes WinAppDriver and Inspect.exe
  • DesiredCapabilities (frequently referenced in the documentation) is deprecated by Appium. Use AppiumOptions instead
  • Use the WinAppDriver task to start/stop WinAppDriver when running in a CI pipeline. Attempting to replicate using powershell can lead to unexpected issues
  • Not all commands supported by Appium are supported by WinAppDriver. Here is a list of the supported APIs - https://github.com/microsoft/WinAppDriver/blob/master/Docs/SupportedAPIs.md

About

An example of using WinAppDriver to drive and test a simple WPF application


Languages

Language:C# 100.0%