If you want to run an android app automation test using Appium on a physical Android device such as a phone or pad, you need to first enable USB debugging mode in your physical Android device and then connect it with your PC using a data line. Below are steps about how to do that.
1. Step-1: Enable Developer Options.
Below steps are the prerequisites before you can enable USB debugging mode on an android device. If you have already done this step before, then you can go to step 2 directly.
- Click the Settings icon on the android OS main screen.
- Scroll down in the Settings menu list, check whether there is a menu named ” Developer options ” at the bottom above the About phone menu item, if you can see that option you can type it to disable or enable it. If you can see that option, it also means you have done step-1 before, you can skip step-1 and go to step-2 directly. In my example, I can see that option because I had enabled it before.
- If you can not see the ” Developer options ” menu, you should go to the ” About phone ” menu and tap it. The About phone menu is located at the bottom of the Settings menu list.
- Scroll down to the ” Build number ” menu item in the ” About phone ” menu list.
- You need totally tap seven times on the ” Build number ” menu item, after the first three-tap, it will popup message show you something like ” If you continue tap twice or more you will be a developer “, keep typing until you see another message like ” You are now a developer! “.
- Then go back to the Settings menu list, you can see the ” Developer options ” menu item in it.
2. Step-2: Enable USB Debugging Mode.
- After enabling the ” Developer options ” menu in step-1, you can enable USB debugging mode now. But what I want to remind you of is that do not make your android phone or pad in USB debugging mode always, just enable it when you needed. There are security risks in that mode because it permits high-level operation on your android device. So to make your android device ( phone or pad ) safe, you should disable this option immediately after you use it.
- Type on the ” Developer options ” menu item in the Settings menu list.
- Check the ” USB debugging (Debug mode when USN is connected)” checkbox to enable it.
- It will prompt you to ask whether ” Allow USB debugging ” or not, click the OK button.
- The detailed message of the Allow USB debugging? popup dialog is as below.
USB debugging is intended for development purposes only. Use it to copy data between your computer and your device, install apps on your device without notiﬁcation, and read log data.
- Now the USB debugging mode has been enabled completed successfully.
3. Step 3: Check Whether Device Is Connected With PC Properly.
- Use a USB line to connect your android device with the PC, then you can run the below dos command to verify that the android device in USB debugging mode is connected with the PC properly.
- Open dos window.
- Execute command ” adb devices ” in the dos window. Then you can see the connected android devices list.
- If you can not see any device, maybe it is because of a connection issue or you do not enable USB debugging mode correctly. The most possible reason is that you do not install your android device’s USB driver correctly on your PC. Below are some general android device’s USB driver provider links.
- Click here to download the Samsung device USB driver, Click here to download the Lenovo device USB driver, Click here to download the HTC device USB driver. Otherwise, you can go to your phone’s manufacturer’s website to download related USB drivers.
4. Install Google USB Driver In Android SDK Manager.
- If you really can not find the correct USB driver for your android device, you can install google’s default USB driver, it can be used to install some android devices.
- Launch Android Studio, click the ” Tools —> Android —> SDK Manager ” menu item.
- In the pop-up dialog, click Appearance & Behavior —> System Settings —> Android SDK on the left side, then click the SDK Tools tab on the right side, then check the ” Google USB Driver ” checkbox, click Apply button. Then click the Finish button in the next dialog to complete the install.
- Click the Windows Start menu, input “device manager” in the windows command input box. Press Enter key.
- In the Device Manager window, right-click your portable devices in the path Laptop —> Portable Devices —> Nexus 7 (your portable device).
- Click the Properties menu item in the above popup menu list. It will open the detail properties dialog with the title Nexus 7 Properties. Click the Driver tab, then click the ” Update Driver… ” button.
- Browse to the Google USB driver saved directory. Commonly you can find the driver in your android SDK installation directory like
- After installing google provided USB driver, you can see the connected android device uses adb devices command in the command line.
Now you can run a native android app automation test in your physical android device using Appium and selenium webdriver, we will introduce that in later articles.