Appium UiAutomator2 Server

9.11.2 · active · verified Sun Apr 19

The `appium-uiautomator2-server` is a critical internal component of the Appium automation framework, specifically designed to enable automated testing on Android devices utilizing Google's UiAutomator2 framework. It functions as a lightweight Netty server that is deployed directly onto the Android device under test. This server component listens for automation commands transmitted from an Appium client (typically via the `appium-uiautomator2-driver`) and subsequently executes these commands by interacting with the native UiAutomator2 APIs on the device. Currently at version 9.11.2, the package is actively maintained by the Appium team, with a consistent cadence of minor releases and bug fixes, as evidenced by its recent changelog, ensuring ongoing compatibility and performance. While distributed as an npm package, it is not intended for direct programmatic JavaScript/TypeScript consumption by end-users, but rather serves as a deployable binary for the Appium ecosystem, bridging the gap between test scripts and Android UI interactions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a typical Appium client-side setup using WebdriverIO to interact with an Android device, which implicitly leverages the appium-uiautomator2-server component deployed on the device. This code does not directly import or use 'appium-uiautomator2-server'.

import { remote } from 'webdriverio';

const capabilities = {
  platformName: 'Android',
  'appium:automationName': 'UiAutomator2',
  'appium:deviceName': 'Android Emulator',
  'appium:platformVersion': '11',
  'appium:app': '/path/to/your/app.apk', // Replace with your app's path or package/activity
  'appium:noReset': true,
  // Other capabilities as needed, e.g., 'appium:appPackage', 'appium:appActivity'
};

async function runAppiumTest() {
  let driver;
  try {
    driver = await remote({
      hostname: process.env.APPIUM_HOST ?? 'localhost',
      port: parseInt(process.env.APPIUM_PORT ?? '4723', 10),
      path: '/wd/hub',
      capabilities,
    });

    console.log('Appium session started successfully.');

    // Example: Interact with a native element using UiAutomator2 locator
    const el = await driver.$('android=new UiSelector().text("Hello World!")');
    if (await el.isDisplayed()) {
      console.log('Found element with text "Hello World!"');
      await el.click();
    }

    // Example: Perform a scroll action
    await driver.execute('mobile: scroll', { strategy: 'accessibility id', selector: 'SomeScrollableList', direction: 'down' });

    // More interactions here...

  } catch (error) {
    console.error('Appium test failed:', error);
  } finally {
    if (driver) {
      await driver.deleteSession();
      console.log('Appium session ended.');
    }
  }
}

runAppiumTest().catch(console.error);

view raw JSON →