> ## Documentation Index
> Fetch the complete documentation index at: https://jetify-dependabot-npm-and-yarn-npm-and-yarn-387f502f5a.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Testing Android Apps with Testpilot

> Run automated tests on Android devices and emulators. Set up Appium, configure your device, and execute your first Android test.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

Before you can run tests on Android devices, you'll need to set up Appium:

1. Install Appium Server and dependencies:

   ```bash theme={null}
   # Install Appium globally
   npm install -g appium

   # Install Appium Doctor for diagnostics
   npm install -g appium-doctor

   # Install the Android driver
   appium driver install uiautomator2
   ```

2. Verify your Appium installation:

   ```bash theme={null}
   appium-doctor
   ```

   This command will check your system and highlight any issues that need to be fixed.

3. Start the Appium server:

   ```bash theme={null}
   appium --allow-cors
   ```

   You'll need to keep this server running in a separate terminal window while executing your tests.

## Setting Up an Android Device[​](#setting-up-an-android-device "Direct link to Setting Up an Android Device")

Testpilot discovers Android devices through the Android Debug Bridge (adb). You have several options
for creating test devices:

### Option 1: Android Studio Emulator (Recommended)[​](#option-1-android-studio-emulator-recommended "Direct link to Option 1: Android Studio Emulator (Recommended)")

1. Download and install [Android Studio](https://developer.android.com/studio)
2. Launch Android Studio and open the Device Manager
3. Click on "Create Device" and select "Pixel 7" (recommended for optimal compatibility)
4. Choose a system image (Android 12 or newer is recommended)
5. Complete the setup and start the emulator

### Option 2: Physical Device[​](#option-2-physical-device "Direct link to Option 2: Physical Device")

1. Enable Developer Options on your Android device:
   * Go to Settings > About Phone
   * Tap "Build Number" 7 times to enable Developer Options

2. Enable USB Debugging in Developer Options

3. Connect your device to your computer with a USB cable

4. Accept any authorization prompts on your device

### Option 3: Connecting with Emulator.wtf[​](#option-3-connecting-with-emulatorwtf "Direct link to Option 3: Connecting with Emulator.wtf")

[emulator.wtf](https://emulator.wtf) lets you quickly spin up remote Android emulators, connect over
ADB, and run your Android Unit and Testpilot tests on the remote device. You can connect Testpilot
to your `emulator.wtf` devices using the following steps:

1. Create an [`emulator.wtf`](http://emulator.wtf) account and API token.
2. Set your API token to the following env var: `EW_API_TOKEN`
3. Follow the [documentation](https://docs.emulator.wtf/integrations/cli/) to install the
   `emulator.wtf` CLI
4. Run the following command to create an [`emulator.wtf`](http://emulator.wtf) device and connect
   it to your local `adb`: `ew-cli start-session --device model=Pixel7,version=34,gpu=auto`
5. You’re device is now ready to run Appium tests!

## Creating an Android Test[​](#creating-an-android-test "Direct link to Creating an Android Test")

Create a test file (e.g., `android-test.pilot.yaml`) with the platform\_config specifying your
Android app package:

```yaml theme={null}
name: "Android App Test"
context:
  - text: "Testing a native Android application"
cases:
  - id: "android-basic-001"
    name: "Basic Android Navigation"
    description: "Test basic navigation in the Android app"
    platform_config:
      android_pkg: "com.example.myapp" # Replace with your app's package name
    steps:
      - "Verify the app launches successfully"
      - "Tap on the 'Login' button"
      - "Enter username and password"
      - "Tap the Submit button"
      - "Verify successful login"
```

## Running Android Tests[​](#running-android-tests "Direct link to Running Android Tests")

To run a test on an Android device, use the following command:

```bash theme={null}
testpilot test android-test.pilot.yaml --driver appium --os android --runtime native
```

For testing web content in Chrome on an Android device:

```bash theme={null}
testpilot test web-test.pilot.yaml --driver appium --os android --runtime chrome
```

## Test Platform Configuration[​](#test-platform-configuration "Direct link to Test Platform Configuration")

The `platform_config` section lets you define the android app that you want to run your tests on.
You can specify an app and URL for both browser based and native application tests

```yaml theme={null}
platform_config:
  url: "https://example.com" # For browser-based tests
  android_pkg: "com.example.myapp" # For native app tests
```

* Use `url` for browser-based tests on Android Chrome
* Use `android_pkg` for native Android app tests
