Following the instructions below you can easily create automated tests on compatible Android Wear apps directly on real or emulated devices.
Prerequisites
-
Install adb:
The Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android device.
You can find it at BinRxEnvAndroidtools. -
Connect with the phone:
Download the Android Wear app on your phone and pair the watch with your phone. You can find detailed information on how to do so here: https://support.google.com/androidwear#topic=6056405 -
Enable the debug mode:
On the smartphone go to “Developer Options” and enable “USB Debugging”.
On the watch got to “Developer Options” and enable “ADB Debugging” as well as “Debug over Bluetooth”. - Finally, open the Android Wear app on your smartphone, press the Settings button on the top right and check the “Debugging over Bluetooth”. The target should be shown as connected.
Getting Started
Connect the device via USB to your computer and call adb via the command line by typing “adb devices”.
It should print something like this:
List of devices attached 08937p69d0518aac device
This means you have successfully connected your phone to your computer. Now we need to connect the watch too. Type the following commands:
adb forward tcp:6666 localabstract:/adb-hub adb connect localhost:6666
Type once again “adb devices”. You should now see a new device called localhost:6666:
08937p69d0518aac device localhost:6666 device
In your Android Wear App, Host and Target should now show up as connected.
Now you can connect your devices, instrument your apps, and create your test.
Automate on an Emulated Device
The following instructions explain how to connect a Genymotion-emulated smartphone with a Google-emulated watch.
First, download Genymotion setup and start any Genymotion emulator with Android 4.3 or later. For Google’s emulated watch you need the AVD Manager.
Start the Android Studio, go to Tools -> Android -> AVD Manager. Create a new Virtual Wear device and start it.
Next, install Google Apps or Gapps on the Genymotion smartphone. With Gapps, also the Play Store will be installed, which is needed for downloading the Wear App.
Go to https://opengapps.org/#downloadsection and download the correct Gapps for your emulator. To install Gapps on Genymotion, please follow these instructions.
Follow the steps explained in Prerequisites and list your devices via adb as described in Getting started.
It should print something like this:
List of devices attached 192.168.154.102:5555 device
This means you have successfully connected your emulated phone to your computer. Now you need to connect the watch too. Type the following command into the command line:
adb -s {genimotion_ip}:{genimotion_port} -d forward tcp:5601 tcp:5601
Type once again the “adb devices” command. You should see a new device called emulator-5600.
Now you can connect your devices, instrument your apps, and create your test.