Search code examples
xamarin.androidgoogle-maps-android-api-2xamarin.uitestvisual-studio-app-center

Blank screen google maps on UI test xamarin android


I write Ui test for Xamarin Forms project, with use google map on iOS they work normal, but on android show only blank screen. If build on debug / release or install apk maps work, but if i use UI test nothing. I use Nunit 2.6.4 and testing on local device and emulator and AppCenter.


Solution

  • Why this issue exists

    When you're compiling your .apk with Google Maps included, Maps use your Keystore settings to verify that the maps is legit (I can't remember the exact details off hand but basically - if the keystore information used to sign the .apk changes - it breaks the maps).

    By default, when you use UITest without sending keystore information - UITest does various magical things with its own keystore. This causes maps to stop working.

    How to resolve this locally

    To fix the test run locally, you need to tell UITest to use the keystore which you used to build the .apk file originally:

    public AndroidAppConfigurator KeyStore (String path, String storePassword, String keyPassword, String keyAlias)
    

    Is the method you want to use when setting up your App Configuration:

    ConfigureApp
       .Android
       .ApkFile("path/to/my.apk")
       .Keystore(path, password, alias)
       .StartApp(mode);
    

    How to resolve this in App Center

    If you want to send your tests up to App Center then you'll need to do one more thing - and that is to include the keystore information when calling the appcenter-cli using the following parameters (which you can get from appcenter test run uitest --help:

       --key-password <arg>                 Password to the matching private  
                                            key in the keystore. Corresponds  
                                            to the "-keypass" argument in     
                                            jarsigner                         
       --key-alias <arg>                    Alias to the key in the keystore. 
                                            Corresponds to the "-alias"       
                                            argument in jarsigner             
       --store-password <arg>               Password to the keystore.         
                                            Corresponds to the "-storepass"   
                                            argument in jarsigner             
       --store-path <arg>                   Path to the keystore file
    

    P.S. If you have issues with App Center - I'd recommend opening a conversation using the Intercom widget in the bottom corner of the website - this will get you routed through to the Test support team who should be able to help you (you might even get to speak to me! :))