Microsoft announced some time ago that Coded UI automation was being deprecated - and that the recommended replacement for testing was Appium with WinAppDriver.
I plan to show how easy it is to get started automating with Appium for a basic DotNet Core application. We will be using python for reasons mentioned below.
Please clone the git repository from here to go along with this article.
Why use python - my app is in C# and Winforms (or WPF) and there are Nuget packages for connecting Appium... what gives? That's a valid point, and I wouldn't fault one for using C# directly for the tests. However, a strong argument for using python instead is that building your automation test just to run it is an unneeded step - you just check your scripts into your repository and checkout/run as an automated process.
Also, python is a interpreted language with an awesome interactive shell - one can write & debug at the same time. While there are ways to alter running .Net code during debugging, it is not very practical.
Being able to write a UI test, set a break point (e.g. with a python IDE, Visual Studio Code, etc), execute the script; and once the break point is hit, having the ability to run any additional python commands in the shell - UI Element lookup, an Assert, or some kind of debug dump - is priceless.
In fact, you could leave a shell up for an indefinite amount of time, keeping the Appium WebDriver instance in scope and develop a whole scenario, interactively. Using C#, that is not possible out of the box (without writing a custom shell / interactive terminal)...
You will need to be on Windows 10 and install (or already have) the following prerequisites:
Getting sample code, and building the .Net Core Winform sample. dotnet run will simply launch the app to ensure it built. After the application starts, you can close it - WinAppDriver will start the app up during automation run.
git clone https://github.com/pjcast/apium_winform_samples.git cd apium_winform_samples/winforms/basic/Basic dotnet restore dotnet build dotnet run
Start Win App Driver in separate cmd prompt (leave running)
C:\Program Files (x86)\Windows Application Driver>WinAppDriver.exe Windows Application Driver listening for requests at: http://127.0.0.1:4723/ Press ENTER to exit.
Run Python sample:
You should see the sample application startup, tab around, check some UI state, then type some characters, and finally app exits.
Files in python\ folder:
The basic sample app and python script are just meant to be a very quick introduction of the power and extensibility afforded by python. While creating a very small framework to build off of, hopefully that will prove useful to you.
As time permits, will be looking to extend the examples and provide python wrappers for interacting with more complex Winform Controls (such as DataGridViews). Your UI tests should be as lean as possible, and build off of reusuable UI object repositories (JSON in this case), and reusable python UI wrappers. You don't want to have code to select X row, X column in a data grid in dozens of different python script files.
Win App Driver / Appium is definitely a welcome replacement for Coded UI. Appium is very accessible to anyone - free, open source, and with the support of Microsoft (via Win App Driver), definetly worth looking into. It is also fantastic that Microsoft open sourced their example automation tests and their UI Recorder app. Although, the recorder app needs some work, the source is there to improve.
The most important part of the Windows Appium integration (WinAppDriver) has yet to be open sourced... If Microsoft open sourced that, improvements on xpath query performance and other lacking features could be done by community members.
Create your free account to unlock your custom reading experience.