To identify element locators and execute automation scripts, a mobile device is required. This device can be:
1. A real physical device
2. An emulator
3. A simulator
In this section, we'll walk you through the process of connecting a real Android device to a Windows machine for Appium testing.
Prerequisite
To connect a real device, we need to install
Java JDK: Required by Appium and Android tools to run properly, especially for command-line tools like ADB and Gradle.
Android Studio: Android Studio: Provides the Android SDK, platform-tools (like ADB), and device drivers necessary for real-device interaction
Appium: The automation engine that sends commands to the mobile device.
Appium Inspector: A GUI tool used to inspect app elements and generate locators (like XPath, accessibility ID, etc.).
We have seen how to install all these tools and software in the Appium Environment Setup on Windows section.
Step 1: Enable USB Debugging on the Android Device
1. Go to Settings > About Phone
2. Tap Build Number multiple times until Developer Options is enabled.
3. Now go to Settings > System > Developer Options
4. Scroll down and enable USB Debugging
Note: The exact location of these options may vary slightly depending on the device brand, but the general process remains same.
Step 2: Connect Your Android Device to the Windows Machine
Use a USB cable to connect your Android device. Ensure the phone is unlocked and you accept the “Allow USB Debugging” prompt on the device.
Now, your Android device is ready to accept commands from your computer via ADB (Android Debug Bridge), enabling Appium to control it.
Step 3: Verify ADB Connection
What is ADB?
ADB (Android Debug Bridge) is a command-line tool that allows your computer to communicate with Android devices for debugging, installing apps, accessing logs, etc.
To check the connection:
1. Open Command Prompt (CMD) or terminal on the windows machine.
2. Run command: adb devices
3. You should see your device listed with a “device” status
If your device is not listed, ensure USB Debugging is enabled and the proper drivers are installed (via Android Studio).
Step 4: Launch Appium GUI
1. Open Appium GUI.
2. Go to Advanced Options.
3. Check Allow CORS (needed for Inspector)
4. Click start Server
This will start the Appium Server locally (default host: 0.0.0.0, port: 4723).
Step 5: Connect Your Android Device in Appium Inspector
1. Download the Appium inspector, it is clearly mentioned in previous section
2. Open Appium Inspector
3. In the Remote Host/Port, add the server Host and Port
4. Click save
Step 6: Configure Desired Capabilities
Open a terminal or CMD and run:
Now open the Appium Inspector
In Json Representation: add the collected data
Click start session
If everything is configured correctly, your device's screen will be mirrored in Appium Inspector, and you'll be able to inspect UI elements and start building your automation scripts.
Connect Real Device Wirelessly
You can connect your Android device to ADB without a USB cable using Wireless Debugging.
Enable Wireless Debugging on your Android device
1. Ensure both your Windows PC and Android device are on the same Wi-Fi network.
2. Go to Developer Options → enable Wireless Debugging.
Connect Device with PC
1. Connect your device via USB (first-time pairing is required).
2. Open a command prompt in the Android Studio platform-tools folder.
3. Run cmd: adb shell ip route
4. Note the IP address (e.g., 192.168.1.xxx)
5. Enable TCP/IP mode by running command: adb tcpip 5555
6. Connect your device by running the command: adb connect 192.168.1.xxx:5555
7. Verify connection by running command adb devices