What is Appium?
Appium is a great framework for testing UWP apps. It is explained in details here, so in this post I would like to show you how to get it running in a few simple steps.
First steps: a simple Calculator app UI test
The steps below explain how to setup Appium and run a very simple UI test on the Windows 10 Calculator app.
1. Install Microsoft WinAppDriver
2. In Visual Studio, create a new Unit Tests project:
3. Install the Appium.WebDriver nuget package in your project:
4. Create a base class for all unit tests. This will keep the Appium code in one place:
5. Add your first test method:
6. Build the project and run the tests. Make sure the WinAppDriver is also running. You should see the Appium opening the Calculator app, taking control of your mouse pointer and clicking the 5 button in the app.
More advanced scenario
In your project use meaningful names for the class and unit tests. Leaving them as 'TestMethod1', 'TestMethod2' is a crime!
What is the package family name of my app?
In our test base class we use the Calculator package name: Microsoft.WindowsCalculator_8wekyb3d8bbwe!App. Obviously, you want to replace it with your app package name, so let me show you two ways of doing that:
Visual Studio
Build your UWP project in Visual Studio and open the vs.appxrecipe file in the text editor. You can find this file in the project output directory, for example bin\x64\Debug\AppX\vs.appxrecipe. Now search for RegisteredUserModeAppID, which is your Appium package name, for example myapp!vstest.executionengine.universal.App.Get-AppxPackage
You can find the package names of all apps installed on your PC. Open the PowerShell in the Administrator mode and run this command:Get-AppxPackage | Select Name
Find the package you are interested in, note the name and run another command to see more details about it. The details for the Calculator app:
Get-AppxPackage -Name Microsoft.WindowsCalculator
You can see the package in the details:
PackageFamilyName : Microsoft.WindowsCalculator_8wekyb3d8bbwe
Before you use it in the your test, add the !App at the end of the package family name. I am not sure what is the rule here, so if you are unable to run the app due to invalid package name, Google is your friend :)
How to access the controls in the app
In the examples above, you could see I am using methods FindElementByName and FindElementByAccessibilityId to identify UI controls in the app. You can find the name, accessibility ID and many more details of any app running on your PC by using the Inspect tool, which is a part of the Windows 10 SDK. For example, open the Calculator app and check details of the 'Five' button:
Now you can try to use these details to interact with the 'Five'button in your code. All the methods in the example below return the same button:
Hint: speed up the process of finding elements, just pause the execution of the test(just put a breakpoint anywhere in your test), open the Immediate Window (my favourite debug tool) and test your code there: