> For the complete documentation index, see [llms.txt](https://docs.testfirst.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.testfirst.com/testfirst-editor/android-mobile-automation.md).

# Android Mobile Automation

Android Mobile Automation allows you to automate Android applications using the TestFirst Editor. Tests can be written using the same Gherkin syntax used for web automation, making it easy to create, maintain, and execute mobile test scenarios alongside your existing automated tests.

Mobile automation supports running applications on **Android emulators** or existing **Android devices** and interacting with mobile UI elements using actions such as tapping, scrolling, waiting, and validations.

{% hint style="success" icon="asterisk" %}
Mobile automation uses application endpoints and mobile device endpoints stored in the Data Repository to launch and interact with Android applications.
{% endhint %}

## Prerequisites

Before running Android mobile tests, configure the Android tools on the machine where tests will execute.

{% stepper %}
{% step %}

### Install Java

Install **Amazon Corretto 25**.
{% endstep %}

{% step %}

### Install Android Command-Line Tools

1. Download the Android Command-Line Tools from:

   <https://developer.android.com/studio#command-tools>
2. Extract the files so the following directory exists:

```
C:\Tools\Android\cmdline-tools\latest
```

3. Create the following environment variable:

```
ANDROID_SDK_ROOT=C:\Tools\Android
```

{% endstep %}

{% step %}

### Install Android Emulator Image

Run:

```bash
sdkmanager "system-images;android-36.1;google_apis;x86_64"
```

{% hint style="info" %}
⚠️ This must be installed using the Android Command-Line Tools. Installing the image through Android Studio is not sufficient.
{% endhint %}
{% endstep %}

{% step %}

### Install Android Platform Tools

1. Download Platform Tools from:

   <https://developer.android.com/tools/releases/platform-tools>
2. Extract the package so the following directory exists:

```
C:\Tools\Android\platform-tools
```

{% endstep %}

{% step %}

### Install Android Build Tools

Navigate to:

```
C:\Tools\Android\cmdline-tools\latest\bin
```

Run:

```bash
sdkmanager "build-tools;36.1.0"
```

{% endstep %}
{% endstepper %}

***

### Configure the Application&#x20;

Before writing a mobile test, add the Android application to the Data Repository.

1. Open **Data Repository**
2. Select **Endpoints**
3. Create a new endpoint
4. Set the endpoint type to **App**
5. Upload the APK file
6. Save the endpoint

The application can then be referenced from your test case.

```gherkin
Given application "{Android apps.TestFirst Sample 1}"
```

<figure><img src="/files/EIR4gSmGTMlnN4RUyEvA" alt="" width="202"><figcaption></figcaption></figure>

### Configure a Mobile Device

Mobile tests require a mobile device endpoint.

1. Open **Data Repository**
2. Select **Endpoints**
3. Create a new endpoint&#x20;
4. Set the endpoint type to **Mobile Device**
5. Enter the device configuration and save the endpoint

#### Start an Emulator

Use the following configuration when TestFirst should start an emulator automatically.

<figure><img src="/files/7qLl4HL22iCOla1XdS82" alt="" width="203"><figcaption></figcaption></figure>

```json
{
  "start": {
    "emulator": {
      "apiLevel": "36.1",
      "imageType": "google_apis",
      "profile": {
        "deviceDefinitionName": "Pixel 5"
      }
    }
  },
  "type": "Android"
}
```

#### Use an Existing Device or Emulator

Use the following configuration when an Android emulator or device is already running.

<figure><img src="/files/1xcHgnFwgbWjyPXg1MzG" alt="" width="205"><figcaption></figcaption></figure>

```json
{
  "use": {},
  "type": "Android"
}
```

### Next Steps

After configuring your Android environment:

1. Use Appium Inspector if you need to inspect application elements while creating selectors.
2. Write your first mobile test.
3. Run the test from the Editor.
