This sample is designed for use in Visual Studio & includes the sourcecode for a Xamarin.Forms app on Android & iOS platforms & a Xamarin.UITest project. It also includes a precompiled APK & IPA incase you want to try only building, running and uploading Xamarin.UITest.
You can either build the entire solution, or you can just build the Xamarin.UITest project.
Compared to running on Mac, Xamarin.UITests have additional requirements and limitations as follows:
ANDROID_HOME
and set it to your Android SDK path. (For example C:\Program Files (x86)\Android\android-sdk
, your location may vary.)ANDROID_HOME
to take effect..ApkFile()
method to point to the APK.You can run the UITest project locally without building the app projects by using precompiled files:
Open "UITestDemo.UITest > AppInitializer.cs"
To point to the app file, unzip the app located in the "precompiledApps" directory of the project & uncomment the line for '.AppBundle' in AppInitializer.cs (You cannot use the precompiled IPA for local testing because it will not be signed for one of your devices. If you build the IPA for the project first though, you can install it on the device and point to it using '.InstalledApp'.)
Build the Xamarin.UITest project.
Running the tests differs slightly if you're using Visual Studio for Mac or Visual Studio on Windows:
You can build individual projects or the entire solution by right-clicking them in the solution pad and selecting "Build [Project/Solution Name]."
Be aware of the following considerations for using Xamarin.UITest with these built projects:
Running the tests differs slightly if you're using Visual Studio for Mac or Visual Studio on Windows:
.ApkFile()
path in the AppInitializer.cs ConfigureApp statementDocumentation reference: https://docs.microsoft.com/en-us/appcenter/build/ This blog also details most of the steps required, though a few details are out of date: https://tomsoderling.github.io/AppCenter-Automated-UI-tests-on-build/
To build apps in App Center, you must own the repository you wish to build from. For example, to use the samples in this repo, you have to fork this repository.
If you have the build working on it's own in App Center Build, then there just a few more steps to enable Test support. These steps are handled by the script called appcenter-post-build.sh in the "Droid" project folder.
For this example, Add the Custom Environment Varaibles to your build settings in App Center:
$API_KEY
- You can use an existing API key or generate a new one (https://intercom.help/appcenter/articles/1841885-how-to-use-app-center-s-api)$TEAM_APP
- This is the argument given to the --app
flag in your Test upload command.$DEVICE_SET
- This is the argument given to the --devices
flag in your Test upload command.Make sure the first time you use the script to manually select "Save & Build" in the App Center Build dialog. Otherwise the build script will be ignored.
To use this script note the following:
Technically all of the commented sections & 'echo' statements are just there to help you understand what the script is doing; the script would work if reduced only to declaring the variables & evaluating statements.
It's important to build the Xamarin.UITest project in the command line; as that is not handled automatically as part of the Android app project build. This is handled by the MSBuild
command in the script.
Your App Center upload command will require a few extra arguments compared to a typical upload:
--aync
- This prevents your build from waiting for the test results and timing out.--token
- Setting an API token since the Cloud Build machine is not logged in to your App Center identity.--uitest-tools-dir
- Explicitly pointing to the Xamarin.UITest package tools folder. (Usually in a local system this is found automatically.)There are 3 types of environment variables used to help the script:
UITEST_PATH
& App_Center_Test_Command