Testing Xamarin Forms Applications in TestComplete 12.5

Apr 18, 2018

Congratulations to the entire SmartBear team for releasing TestComplete 12.5 on April 10th 2018

I have been happily using TestComplete since its release 2 decades ago and I have been consulting and training successfully on the product since 2001 for over 300 corporate customers worldwide.

The new release comes with several new features and enhancements that you can read about here 

In this blog, I will introduce you to the Xamarin Forms testing feature that was introduced in the new release of 12.5.

UPDATE: you can view the video for this blog here

TestComplete has been supporting Xamarin Native applications for several years now and I had the pleasure of releasing an add on to the previous Xamarin Marketplace to allow for the instrumentation of Android and iOS apps written in Xamarin way before the feature was added to the product few years ago.

In the new release, they added the ability to instrument Xamarin Forms applications and that is huge because now I can write my Script code or Keyword tests against Android and run the same exact test on my iOS application without modification even though the UI might a bit different, TestComplete will still execute the correct object-based tests correctly on both platforms with the same testing code.

Let’s get started!

First, I wrote a small app in Visual Studio 2017 to display a list of some of SmartBear’s great products and I ran on my Samsung device and I also tested it in my Genymotion Emulators.

The nice thing about testing with Genymotion is the ability to test with so many different devices and API levels without having the physical devices present.

In TestComplete, Opening the Object Browser tab and heading to the Mobile section, you will be able to see that TestComplete recognized the emulator running in Genymotion and list a lot of valuable information about the device on the right side as you can see below.

Make sure to turn on the “show Mobile Screen” feature in the TestComplete Menubar to mirror the exact view of the emulator as well.


First, we need to install the Android Agent on the emulator, you can easily perform that step by clicking on the “Install Android Agent” tool button in the “Mobile Screen” menu.  That will take a few seconds and you will see a new application installed in your emulator confirming that the TestComplete android Agent is install and well.

From that point on, you can deploy your application to the emulator using Visual Studio 2017 and the app will be seen running in the “TestComplete Mobile Screen”

The only problem now is that the Object Browser will not show any objects below the device name


That is because the application has not been “instrumented” yet.  You can still test your app using Testcomplete but you will need to use the Image repository to test clicks and images on the screen, which is fine, but not as powerful of course as getting access to the objects of the application running on the device or emulator.

Let’s go ahead and instrument the app

We will need to reference in Visual Studio 2017 THREE assemblies, not just ONE like Native Xamarin apps in the past.

The first TWO will come from the bin/Extensions… folders where TestComplete 12.5 is installed


The first assembly is called PatchServices.dll and the second assembly is called SmartBear.XFAgent.Android.dll

Add these 2 references and then reference the Mono.Android.Export.dll in the Assemblies section in the reference dialog


At the end your project in Visual Studio will need to have the following 3 references:


We are almost done!

We now just need to invoke the initializer in the startup code of the Xamarin Forms Application

Open the MainActivity.cs file for the Android project and add ONE line of code to the OnCreate event code:



We are ready to build and deploy one more time!

Now look at how much more information will be available for us in the Object Browser:


Isn’t that Awesome!  I can now develop Keyword tests and Script tests against that object model of the instrumented Xamarin forms app.  I could use the powerful TestComplete recorder to allow me to easily test my application with confidence.

I just recorded a session in script (JavaScript) where I clicked on the first item in the list “Testcomplete 12.5” which navigated to another page and then clicked on the Back button at the top to navigate to the starting point.  Here is the code recorded for me:


Hope the code is self-explanatory, but I want to point to 2 things in here, first line # 6 contain X and Y coordinate. Don’t let that worry you, the only reason TestComplete recorded the X and Y coordinate  is because we clicked on the first item in the list (index 0) at a specific location in that cell.  I could easily change it to TouchItemXY(0,0,0) and it will work just the same, it is the first 0 that is important, that is the index for the first item in the list.  This call will work as is in iOS as well with no changes.

Also line # 7 is performing a click on the TouchBackButton() it is great because that call is not Android specific.  What does that mean?  That means when we run the same application from Visual Studio on our iPhone simulator or device, the Back Button will be in a different place on the screen altogether but that script will not need to be changed, TouchBackButton() will still cause the iOS device to go back in navigation.

Now our scripts recorded or implemented in TestComplete 12.5 for Xamarin Forms application will not need to be changed and the same code can be executed on multiple devices from iOS and Android

Go ahead, give it a try! Download the trial of TestComplete 12.5 and start instrumenting your application today for Xamarin Forms Apps and test your heart out!

Load more reviews
You've already submitted a review for this item

Copyright © 2020 Alain "Lino" Tadros
Using Sitefinity 13.0.7300