Skip to main content

Prerequisites

Before you can run tests on Android devices, you’ll need to set up Appium:
  1. Install Appium Server and dependencies:
    # 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:
    appium-doctor
    
    This command will check your system and highlight any issues that need to be fixed.
  3. Start the Appium server:
    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

Testpilot discovers Android devices through the Android Debug Bridge (adb). You have several options for creating test devices:
  1. Download and install Android 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

  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

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 account and API token.
  2. Set your API token to the following env var: EW_API_TOKEN
  3. Follow the documentation to install the emulator.wtf CLI
  4. Run the following command to create an 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

Create a test file (e.g., android-test.pilot.yaml) with the platform_config specifying your Android app package:
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

To run a test on an Android device, use the following command:
testpilot test android-test.pilot.yaml --driver appium --os android --runtime native
For testing web content in Chrome on an Android device:
testpilot test web-test.pilot.yaml --driver appium --os android --runtime chrome

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
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
I