Search code examples
androidandroid-emulatorandroid-uiautomator

How to run UIAutomator on emulator?


I am able to run my UIAutomator test on a real device. Here are the steps I've taken:

  1. <sdk_dir>/sdk/tools/android create uitest-project -n <test_name> -t 1 -p <workspace_dir>/<test_name>
  2. cd <workspace_dir>/<test_name>
  3. ant build
  4. <platform-tools/adb push
  5. <workspace_dir>/<test_name>/bin/<test_name.jar> /data/local/tmp
  6. <platform-tools/adb shell uiautomator runtest <test_name.jar> -c <package_name.classname>

Does anyone know how to execute the test on an emulator? (I am using Mac - emulator64-arm)


Solution

  • You can always run UIAutomator tests on Android device emulator

    All that you need is to find out what devices are connected to your pc:

    <platform-tools/adb devices
    List of devices attached
    emulator-5555 device
    HTCDesireX device
    

    once you have the device id of emulator, use adb -s <emulator_id> instead of adb , you new steps would be:

    <platform-tools/adb -s emulator-5555 push <workspace_dir>/<test_name>/bin/<test_name.jar> /data/local/tmp
    <platform-tools/adb -s emulator-5555 shell uiautomator runtest <test_name.jar> -c <package_name.classname>