microsoft / appcenter-Xamarin.UITest-Demo

Minimal App for demonstrating Xamarin.UITest functionality within App Center
MIT License
19 stars 37 forks source link

Build Status

Overview (Xamarin.UITest - Cross-Platform)

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.

Building & running locally

You can either build the entire solution, or you can just build the Xamarin.UITest project.

Windows users

Compared to running on Mac, Xamarin.UITests have additional requirements and limitations as follows:

Running locally without building the iOS app

You can run the UITest project locally without building the app projects by using precompiled files:

  1. Open "UITestDemo.UITest > AppInitializer.cs"

  2. 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'.)

  3. Build the Xamarin.UITest project.

  4. Running the tests differs slightly if you're using Visual Studio for Mac or Visual Studio on Windows:

    • VS for Mac - Go to View > Pads > Unit Tests > Run All (When testing on Windows, only Android is supported.)

Running locally with building the Android/iOS apps

  1. You can build individual projects or the entire solution by right-clicking them in the solution pad and selecting "Build [Project/Solution Name]."

  2. Be aware of the following considerations for using Xamarin.UITest with these built projects:

    • 'UITestDemo.Droid' must be built using a "Release" configuration. This is because by default a "Debug" build of a Xamarin.Android project includes the "Shared Mono Runtime" which is not compatible with Xamarin.UITest.
    • 'UITestDemo.iOS' must be built using a "Debug" configuration. This is because by default iOS apps built for distrbution are rejected from the iOS app store if they contain 'Calabash' the testing framework which allows Xamarin.UITest to interact with iOS apps.
    • Android APKs can be run on either a physical Android device or emulator interchangably. iOS must use a '.app' build to run on an iOS simulator & an '.IPA' with a valid signing identity to run on an iOS device.
  3. Running the tests differs slightly if you're using Visual Studio for Mac or Visual Studio on Windows:

Uploading tests

  1. Build the Xamarin.UITest project.
  2. Generate a command line for upload: Directions
  3. Update the upload command with project-specific arguments:
    • OS X paste your command as the value for 'AppCenter_Test_Command' in 'android.sh' or 'ios.sh' depending on the platform. You can run these files using 'sh android.sh' or 'sh ios.sh'.
    • Windows The '.sh' files are not technically compatible with Windows, however it shows how to modify the generated command to upload this sample manually.

See Also

Building in App Center

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

Integrating Test Suite on Android

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.

  1. For this example, Add the Custom Environment Varaibles to your build settings in App Center:

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

Background Info on how the script works

To use this script note the following: