Instrumenting Android Applications in Android Studio

Applies to TestComplete 14.40, last modified on April 22, 2021

To create object-based Android tests, you need to instrument your tested Android application. This topic explains how you can do this with Android Studio.

Do not submit instrumented applications to the Google Play. Instrumented applications use private APIs and will be rejected. Create a separate build configuration for test builds.

Requirements

The instructions below assume that Android Studio is installed on your computer. It is part of the Android Developer Tools package that can be downloaded from this web site:

http://developer.android.com/sdk

Preparation Steps

1. Include the PatchServices.jar Library in Your Project

  1. Open your Android project in Android Studio.

  2. Expand the app\libs folder.

  3. Copy the PatchServices.jar library to the libs project folder and click OK in the Copy dialog. The library file is located in the <TestComplete>\Bin\Extensions\Android folder on your computer.

  4. Add PatchServices.jar to the dependencies list in the app\build.gradle file of your project:

    Java

    dependencies {
      compile files ('libs/PatchServices.jar')
    }
    Note: You need to add a library reference to an individual module's build.gradle file, not to the top-level build file.

2. Initialize the PatchServices Library When Application Starts

The main goal of this step is to initialize TestComplete tools when the application starts. There are two ways to do that. If your application has more than one activity, you need to place the initializing line in the constructor of your application.

Java

public class MyApplication extends Application
{
    public MyApplication()
    {
        // The method that initializes TestComplete tools
        com.smartbear.uibinder.Binder.Initialize(this);
 
        …
    }
}

If there is only one activity in the tested application, you can add the initializing line to the onCreate method of the activity.

Java

public class MainActivity extends Activity
{
    protected void onCreate(Bundle savedInstanceState)
    {
        // The method that initializes TestComplete tools
        com.smartbear.uibinder.Binder.Initialize(getApplication());
 
        …
    }
}

3. Install TestComplete Android Agent

To interact with your instrumented Android application from TestComplete, you need to install TestComplete Android Agent on your device. For complete information about the Agent and installation steps, see the Agent description.

See Also

Preparing for Testing Android Applications
Instrumenting Android Applications - Overview
About Testing Android Applications

Highlight search results