xamarinxamarin.androidxamarin.uitestvisual-studio-app-centervisual-studio-app-center-test

How to Push UI Test to App Center Test from Continuous Integration Server


How do you push an UI Test along with the associated app to App Center Test from the command line?

I'm using a CI (Continuous Integration) server to build my app, and I tried using the following command, given by the App Center Test portal, but it isn't working and outputs the error, below:

appcenter test run uitest --app "bminnick/uitestsampleapp" --devices b139e40f --app-path [my apk file path] --test-series "master" --locale "en_US" --build-dir [my UI Test Build Directory]

Command 'appcenter test run uitest' requires a logged in user. Use the 'appcenter login' command to log in

I'm trying to deploy a Xamarin.Android app and a Xamarin.UITest.

enter image description here


Solution

  • Push to App Center Test from CLI

    1. Manually Retrieve an API Token

    The App Center CLI requires the user to be logged in, and we can log in from our build server by providing a login token.

    Using the App Center CLI, enter the following command, replacing [Name Of Token] with whatever you want to name this token

    appcenter login
    appcenter tokens create -d "[Name Of Token]"
    

    It will provide a response like this:

    ID: [Unique Guid]

    API Token: [Unique API Token]

    Description: [Name of Token]

    Created at: [Time Stamp]

    Copy the API Token result. We will use this in our CI script.

    2. App Center Test Script for CI Server

    In your Continuous Integration pipeline, use this bash script to push the APK File + UI Test to App Center Test

    The bash script does the following:

    1. Locate the UI Test Build Directory
      • Replace [My UI Test Assembly Name] with the name of your UI Test assembly
    2. Locate the APK file
    3. Install the appcenter cli
    4. Log in to App Center using the API Token
    5. Push the APK + UI Test to App Center Test
    #!/usr/bin/env bash
    
    UITestDLL=`find . -name "[My UI Test Assembly Name].dll" | grep bin`
    UITestBuildDir=`dirname $UITestDLL`
    
    APKFile=`find . -name *.apk | head -1`
    
    npm install -g appcenter-cli@1.2.2
    
    appcenter login --token [login token from Step 1]
    
    appcenter test run uitest --app "bminnick/uitestsampleapp" --devices b139e40f --app-path $APKFile --test-series "master" --locale "en_US" --build-dir $UITestBuildDir --async