Posted by Tobias Walter on Thursday, February 14th, 2013 at 8:51 am to Improve Object Recognition

This blog post illustrates how to automate testing of cross-platform apps implemented with Xamarin.iOS (MonoTouch) and Xamarin.Android (Mono for Android) with Ranorex.

Automate Xamarin.iOS and Xamarin.Android Cross-Platform  App Testing


Infrastructure

Xamarin.iOS and Xamarin.Android, both developed by Xamarin, are commercial implementations of Mono – a cross-platform implementation of C# – for iPhone and Android-based smartphones.

Using these two implementations it’s easy to reuse most of your existing code when porting from Android to iOS or vice versa. Next to that it’s possible to import existing .NET libraries and to use them in your Android/iOS apps.

Ranorex supports test automation for both, Xamarin.iOS and Xamarin.Android. Simply follow the steps below to make your cross-platform app testable.


Make Your Xamarin.iOS App Testable with Ranorex

To instrument your MonoTouch app you simply have to add the Ranorex automation library for iOS to your MonoTouch project as native library.

Add Library as Native Lib

 

Open the projects options and set the following additional arguments (not necessary when working with simulator only):

-cxx -gcc_flags "-framework QuartzCore -framework CoreGraphics"

Additional Arguments


Make Your Xamarin.Android App Testable with Ranorex

Note: With Ranorex 5.0.0 and higher, Xamarin.Android apps can be instrumented using the Ranorex Instrumentation Wizard.

To manually instrument your Xamarin.Android app simply follow the step by step instructions below.

  • Add the Ranorex automation library for Android (<RanorexInstallDir>\bin\RxEnv\Android\Ranorex.jar) to your Xamarin.Android project.
    Add Ranorex Automation Library 1
    Add Ranorex Automation Library 2
    Copy Ranorex Automation Library
  • Open the properties of the added file and set the build action to “AndroidJavaLibrary”.
    Set Build Action 1
    Set Build Action 2
  • Download the file RanorexAndroidMonoInstrumentation.cs and add it to your project (the same way as described in the first step).
  • Add the following lines of code to each activity in your project:
    public override bool DispatchKeyEvent (KeyEvent e)
    {
      Ranorex.RanorexAndroidMonoInstrumentation.dispatchKeyEvent(e);
      return base.DispatchKeyEvent (e);
    }
    
    protected override void OnResume ()
    {
      base.OnResume ();
      Ranorex.RanorexAndroidMonoInstrumentation.onResume(this);
    }
    
    protected override void OnPause ()
    {
      base.OnPause ();
      Ranorex.RanorexAndroidMonoInstrumentation.onPause(this);
    }
  • Open the properties of your project and add a new “Android Manifest” in the “Mono for Android Application” area.
    Add a Manifest
  • Add “(RxInstrumented$4.x.x)” to the version name (whereas 4.x.x is the Ranorex version you are using) and activate the check boxes “INJECT_EVENTS” and “INTERNET” in the “Required permission” area.
    Update Manifest


Conclusion

Following these simple step by step instructions will make your Xamarin.iOS and Xamarin.Android apps accessible for Ranorex and nothing should be standing between you and your robust cross-platform test automation.

To get started with mobile test automation, have a look at the chapters “Android Testing” and “iOS Testing” in our user guide.

The following two tabs change content below.

Tobias Walter

Online Marketing and Content Specialist at Ranorex
Tobias Walter is Online Marketing and Content Specialist at Ranorex GmbH. Next to his marketing activities he also writes articles published in severals blogs and journals.

Latest posts by Tobias Walter (see all)

Tags: , , , ,

4 comments

  1. Anoop

    We have an issue with integrating the tool with our iPhone and iPad applications developed using Xamarin. Can you please help us in fixing this issue? and following are the steps performed by us:

    1. We created a sample app (eg: Adding a value to the list) using the Xamarin for iPad and iPhone.
    2. Added the Ranorex Automation Library ‘libRxAutomationUni_405.a’ as Native library.
    3. Added the additional arguments in the project options “-cxx -gcc_flags “-framework QuartzCore -framework CoreGraphics”
    4. Built the app. App launches in Simulator/iPhone and the device gets listed in the ‘Manage Devices’ of Ranorex app.
    5. Next, we tried the same steps 1-4 for our client’s iPhone and iPad applications.
    6. Application fails to launch and we are getting null errors on UIApplication.SharedApplication.Delegate but UIApplication.SharedApplication returns the app.
    7. Now, we removed the Ranorex Automation Library ‘libRxAutomationUni_405.a’ from the Native library. App launches in Simulator/iPhone but device does NOT get listed in the ‘Devices List’ of Ranorex app.

  2. twalter

    @Anoop: Can you please provide the exact error thrown?
    You can of course directly contact our support team at support@ranorex.com if you don’t want a public conversation.
    Regards
    Tobias

  3. paul

    Is it possible to test ios device on using windows platform,
    as most of the instructions seen point to use of mac pc for ios testing

  4. Tobias Walter

    @paul
    Of course it is possible to test your iOS device using Windows.
    For further details have a look at the chapter “iOS Testing” in our user guide.

    Regards,
    Tobias

Leave a Reply