Running Appium Tests on a Real Device
Running Appium Tests on a Real Device
This guide explains, step by step to set up and run Appium automation tests on a real Android device connected to a laptop.
What is Appium?
Appium is an open-source automation tool used to test mobile applications (Android and iOS).
It allows you to write test scripts using programming languages like Java, Python, JavaScript, etc., and run them on
real devices or emulators.
Prerequisites
Hardware Requirements
- A laptop (Windows / macOS / Linux)
- An Android real device (phone or tablet)
- A good-quality USB cable
Software Requirements
- Java JDK (Java 8 or above)
- Android Studio
- Android SDK & Platform Tools
- Node.js
- Appium Server
- IDE (Eclipse / IntelliJ IDEA / VS Code)
Install and Configure Required Tools
Install Java JDK
- Install Java JDK
- Set
JAVA_HOMEenvironment variable - Verify installation:
java -version
Install Android Studio
- Install Android Studio
- Open SDK Manager
- Install:
- Android SDK Platform
- Android SDK Build-Tools
- Android SDK Platform-Tools
Add the following to system environment variables:
ANDROID_HOME PATH = %ANDROID_HOME%\platform-tools
Install Node.js
Appium runs on Node.js. After installation, verify:
node -v npm -v
Install Appium
Install Appium globally using npm:
npm install -g appium
Verify Appium installation:
appium -v
Optionally, install Appium Desktop for GUI:
- Provides Appium Server UI
- Inspector for element inspection
Prepare the Real Android Device
Enable Developer Options
- Open Settings → About Phone
- Tap Build Number 7 times
Enable USB Debugging
- Go to Settings → Developer Options
- Enable USB Debugging
Connect Device to Laptop
- Connect device using USB cable
- Allow USB debugging permission on the device
Verify device connection:
adb devices
You should see your device listed as device.
Get Application Details
App Under Test
- Use APK file OR
- Use already installed application
Find App Package and Activity
adb shell dumpsys window | findstr mCurrentFocus
Example output:
com.example.app/com.example.app.MainActivity
Start Appium Server
Start via Command Line
/> appium
Start via Appium Desktop
- Open Appium Desktop
- Click Start Server
Default server URL:
http://127.0.0.1:4723
Create Appium Test Project
Create Java Project
- Open IDE (Eclipse / IntelliJ)
- Create a Maven or Java project
Add Required Dependencies
Add Appium and Selenium dependencies (example for Maven):
<dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>latest</version> </dependency>
Write First Appium Test Script
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "Android");
caps.setCapability("deviceName", "AndroidDevice");
caps.setCapability("automationName", "UiAutomator2");
caps.setCapability("appPackage", "com.example.app");
caps.setCapability("appActivity", "com.example.app.MainActivity");
AndroidDriver driver = new AndroidDriver(
new URL("http://127.0.0.1:4723"), caps
);
This code:
- Defines device and app details
- Connects Appium server
- Launches the app on the real device
Run the Test
- Ensure Appium Server is running
- Ensure device is connected and unlocked
- Run the test from IDE
If everything is correct:
- App launches on real device
- Test actions execute automatically
Common Beginner Issues
- Device not detected: Check USB debugging and drivers
- Session not created: Verify capabilities
- App not launching: Check appPackage and appActivity
- Port issues: Ensure port 4723 is free
Next Steps
- Learn Appium Inspector
- Understand locators (id, xpath, accessibilityId)
- Integrate TestNG or JUnit
- Run tests on multiple devices
Conclusion
Running Appium automation on a real device involves setting up the environment, connecting the device,
starting the Appium server, and executing test scripts. Once the setup is complete, writing and running tests
becomes straightforward and powerful for real-world mobile testing.“`