Introduction
This blog takes user for setting up Visual studio appcenter for uploading and running Xamarin Automation tests. This article assumes below prerequisites are enabled.
Prerequisites
- Azure subscription with billing enabled as per contract to use Appcenter(contact IT admin for setup) or a Trial account can be setup for 30 days for Testing and unlimited build uploads.
- Appcenter account with billing enabled via Azure subscription(for more info visit.
- Node is installed and able to access npm commands(Link for Node installer which has both windows and Mac versions and users are expected to download the stable version)
Instructions
- Login to Appcenter and create a new App by clicking Add App in right corner (in our case App is already created)
- Select OS as Android or iOS and platform as Xamarin as shown below,
Figure 1.1 Create a new app and selecting the OS
- Once the app is created Navigate to below page by clicking on Test and under Test Runs from left side Hamburger menu.
Figure 1.2 Test Run selection
- Click on New Test Run button and select Devices for test and click in select device. The devices can be filtered based on OS, make and model.
Figure 1.3 Create a new app and selecting the OS
Figure 1.4 Filter selection for devices based on OS and make
- In next screen select Test framework as Xamarin Ui test and leave everything as it is default settings.
Figure 1.5 Configuring Test run to use Xamarin UI test as platform
- In this step we need to install node and install the required npm packages as shown below
Figure 1.6 NPM commands
- Now in PC or Mac open command prompt and run the commands as below,
npm install -g appcenter-cli and setup will be completed and we are ready for uploading the tests to appcenter.
- Build the iOS and android apps for the first time and deploy to devices locally(can be automated in complete CI setup)
- Run the automation scripts files from local machine or from CI Pipelines
- The tests will be uploaded to appcenter and wait for them to finish as shown below
Figure 1.7 Progress screen for Test run
- The scripts can be uploaded as post build script in visual studio or CI tool to directly upload tests to appcenter.
Reference script
- AppCenterAPIToken=’your token’
- AppCenterLogin=’appcenter login — token $AppCenterAPIToken’
- AppCenter_Test_Command=’appcenter test run uitest — app “innovativetechiesltd/AppcenterAppname” — uitest-tools-dir “/Path to solution/packages/Xamarin.UITest.3.0.5/tools” — devices 0e13ce56 — app-path pathToFile.ipa — test-series “master” — locale “en_US” — build-dir pathToUITestBuildDir’
- # Step 1 Provide the (absolute or relative) path to the IPA
- app_path=’/Your path/bin/iPhone/Release/your apkfile.apk’
- # Step 2 Provide the (absolute or relative) path to the UITest project bin folder
- build_dir=’/Your path/Your app.UITests/bin/Release’
- # Step 3 run using the command “sh ios.sh”
- # Script injects app_path & build_dir and executes resulting command
- AppCenter_Test_Command=${AppCenter_Test_Command/’pathToFile.ipa’/$app_path}
- AppCenter_Test_Command=${AppCenter_Test_Command/’pathToUITestBuildDir’/$build_dir}
- echo $AppCenter_Test_Command
- eval $AppCenterLogin
- eval $AppCenter_Test_Command
This is a simplest form of uploading tests to app center and may vary with projects and infrastructures.
References