Configure your Android app to be testable
The application configured following the steps below, should be used for testing purposes only and will not be accepted in Google Play Store.
Android apps must be configured in order to be testable by Test Studio Mobile. This can be achieved through the built-in configuration or manually:
Built-In Configuration
The built-in configuration requires that you have Java SDK v.1.8 or later, Android SDK v.14 or later Android Build Tools v.20 or later installed (Android Build Tools are a component of the Android Studio installation).
It doesn't change already instrumented app and you have to ensure that the
libs
folder of your project doesn't containMobileTestingExtension.jar
orMobileTestingExtension.aar
files. In addition built-in configuration is not supported for the below cases:
- Apps downloaded from Google play or built in production mode.
- The app to be instrumented has more than 65536 methods and is installed on device running API level 20 and below. See that article for more information.
The automatic configuration is incorporated into Test Studio Mobile project and can be launched by clicking the Android gear box icon at the right corner of the toolbar:
The Android application configuration dialog shows up. The first-time setup requires that paths to Android SDK and Java JDK foolders are set:
For more informational about Android application configuration settings, please see this article.
After valid paths are set, the Next button is enabled and the Input location step can be selected. It allows configuring an app either already installed on a device, or taken from the local machine file system. Configuring an app installed on a device, requires that the device is USB connected to the local machine running Test Studio Mobile:
Selecting a connected device automatically loads a subset of all apps installed on it. Apps that have identifiers starting with com.android
and com.google
are not shown initially. In order to show all available apps on the device, check the Show All checkbox. In addition instead of scrolling through the list, a search box allows you to look for a specific app identifier:
Configuring system apps is not supported. If system app is selected the configuration will either fail or the app may become unstable. Test Studio is not responsible for any damage that a configured system app may cause.
After app to be configured is selected, the Output location step is enabled and can be navigated by clicking the Next button:
Output location can be either the local machine file system or any of the USB connected devices:
Clicking the Run button will start the configuration process. After the app is successfully configured it will be deployed to the selected device or saved at the specified file location.
Testing the configured app can start immediatelly by opening an Android test and selecting a device for recording. The app identifier is automatically added and can be chosen from the list of app identifiers that is shown when recording starts. This article describes test recording in detail.
Manual Configuration
The manual configuration requires the source code (Android Studio/Eclipse project).
Configure your Android app to be testable.
Android Studio and AAR extension.
Copy Extension
- Download the Test Studio Mobile extension for Android and unpack it.
- Open
/MobileTestingExtension_Android/
. - Copy
MobileTestingExtension.aar
. - In your project open
/projectFolder/mymodulename/libs
. - Paste
MobileTestingExtension.aar
.
Configure Module gradle settings
- Open
/projectFolder/mymodulename/build.gradle
. -
Add the following
productFlavors
in theandroid
object:productFlavors { myFlavor { targetSdkVersion 0 } }
-
Add the following line to the
dependencies
section:myFlavorCompile (name: 'MobileTestingExtension', ext: 'aar')
Configure Project gradle settings
- Open
/projectFolder/build.gradle
. -
Add the following
flatDir
element in therepositories
object:flatDir { dirs 'libs' }
Sync the project and select View > Tool Windows > Build Variants.
-
Select the myFlavorDebug build variant and deploy it.
Android Studio and JAR extension.
Copy Extension
- Download the Test Studio Mobile extension for Android and unpack it.
- Open
/MobileTestingExtension_Android/
. - Copy
MobileTestingExtension.jar
. - In your project open
/projectFolder/mymodulename/libs
. - Paste
MobileTestingExtension.jar
.
Add Flavors
- Open your project in Android Studio.
- Right Click on the project and select Open Module Settings.
- Click app under Project Settings.
- Click the Flavors tab.
-
Click + to add two new entries:
production
andmobileTesting
. Click OK.
Configure Testing Flavor
- Open
/projectFolder/mymodulename/build.gradle
. -
Add the following after
productFlavors
in theandroid
object:android.applicationVariants.all { variant -> if (variant.flavorName == 'mobileTesting') { variant.outputs[0].processResources.manifestFile = file("src/${variant.flavorName}/AndroidManifest.xml") variant.outputs[0].processManifest.enabled=false } }
Include Extension
- Open
/projectFolder/mymodulename/build.gradle
. -
Add the following lines to the
dependencies
section:mobileTestingCompile files('libs/MobileTestingExtension.jar')
Create Subfolders
Create the following subfolders in the project:
/projectFolder/mymodulename/src/mobileTesting
Copy Android Manifest
- Open
/projectFolder/mymodulename/src/main
. - Copy
AndroidManifest.xml
. - Open
/projectFolder/mymodulename/src/mobileTesting
. - Paste
AndroidManifest.xml
.
Edit Android Manifest
- Open
/projectFolder/mymodulename/src/mobileTesting/AndroidManifest.xml
. - Verify that the permisiion element android.permission.SYSTEM_ALERT_WINDOW is added to the manifest file.
-
Add the following top-level
instrumentation
element which will be used as App-Identifier in Test Studio Mobile (don't forget to changeyour.app.package
with your actuall app package name):<instrumentation android:targetPackage="your.app.package" android:name="com.telerik.testingextension.MobileTestingInstrumentation" />
-
Add the following
activity
element as a child of theapplication
element:<activity android:name="com.telerik.testingextension.EntryPoint" android:theme="@android:style/Theme.NoDisplay"> <intent-filter> <action android:name="com.telerik.testing.ACTION_AUTOMATE"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>
Select View > Tool Windows > Build Variants.
-
Select the mobileTestingDebug build variant and deploy it.
Eclipse
Copy Extension
- Open
/Telerik Mobile Testing/extensions/Android
. - Copy
MobileTestingExtension.jar
. - Open
/projectFolder/libs
. - Paste
MobileTestingExtension.jar
.
Edit Android Manifest
- Open
/projectFolder/AndroidManifest.xml
. - Verify that the permisiion element android.permission.SYSTEM_ALERT_WINDOW is added to the manifest file.
-
Add the following top-level
instrumentation
element which will be used as App-Identifier in Test Studio Mobile:<instrumentation android:targetPackage="your.app.package" android:name="com.telerik.testingextension.MobileTestingInstrumentation" />
-
Add the following
activity
element as a child of theapplication
element:<activity android:name="com.telerik.testingextension.EntryPoint" android:theme="@android:style/Theme.NoDisplay"> <intent-filter> <action android:name="com.telerik.testing.ACTION_AUTOMATE"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>
Build the project and deploy it.