Appium 2.0 redesigned mobile test automation by decoupling drivers into independent plugins. Learn how to configure Android emulators, iOS simulators, and write clean Java mobile test scripts.
1. Installing Appium 2.0 and UiAutomator2 Driver
2. Configuring Android Desired Capabilities for UiAutomator2
3. Writing Your First Appium Test: Login Flow
4. Using UIAutomator2 Inspector (uiautomatorviewer)
The Appium Inspector (previously UIAutomatorViewer) allows QA testers to inspect the Android accessibility tree and identify element locators (ID, AccessibilityId, XPath, ClassName) before writing test scripts. Launch it from appium inspector NPM package.
5. Handling Gestures: Swipe, Scroll, and Pinch-to-Zoom
6. iOS Automation with XCUITest Driver
7. Page Object Model (POM) for Mobile Tests
Structure Appium tests using the Page Object Model to separate UI element locators from test logic. Use the @AndroidFindBy and @iOSXCUITFindBy annotations from Appium Java Client for cross-platform compatibility.
Frequently Asked Questions (FAQ)
Q1: What is the difference between Appium 1.x and Appium 2.0?
A: Appium 2.0 decouples drivers into independently installable plugins. You only install the drivers you need (UiAutomator2, XCUITest, Espresso) using appium driver install, making the core server lighter and more modular.
Q2: Can Appium test React Native and Flutter apps?
A: Yes. For React Native apps, use standard UiAutomator2/XCUITest drivers. For Flutter apps, use the flutter_driver package or the specialized appium-flutter-driver plugin.
Q3: What is the recommended locator strategy in Appium?
A: Use AccessibilityId (cross-platform) as the first choice since it works on both Android and iOS. Avoid XPath for performance reasons as it performs a full traversal of the accessibility tree.
8. Cross-Platform Testing Strategy: One Codebase, Two Platforms
Appium enables a single Java test class to run on both Android and iOS by using conditional driver initialization and the @AndroidFindBy / @iOSXCUITFindBy annotation pair from Appium Java Client.
9. Running Appium Tests on Real Devices (Cloud Testing Platforms)
For production-grade mobile QA, run Appium tests against real device clouds like BrowserStack, LambdaTest, or Sauce Labs. These platforms provide 3000+ real Android and iOS devices accessible via remote WebDriver URLs.
10. Appium Test Reporting with Allure & Extent Reports
Integrate Allure Report with TestNG to generate step-by-step test evidence including screenshots, device logs, and video recordings. Add the allure-testng Maven dependency and annotate critical steps with @Step("User taps Login button").
11. Appium Inspector: Inspecting Element Locators Visually
Before writing locators in your test scripts, use the Appium Inspector tool to visually identify element attributes (resource-id, content-desc, text, className) on the live device or emulator screen. This prevents wasted time writing locators that don't work.
Launch Appium Inspector by running npm install -g appium-inspector, connecting to your Appium server at http://localhost:4723, and entering the desired capabilities. The visual tree viewer shows every accessible element and its attributes in a hierarchical format.
12. Handling Toasts, Alerts & Dialogs in Appium
13. Running Appium Tests in Parallel on Multiple Devices
Use TestNG parallel execution with separate Appium server ports per device to run tests concurrently across multiple Android emulators or real devices. This dramatically reduces overall test suite execution time.
14. Deep Link Testing with Appium
Deep links allow users to navigate directly to specific screens within a mobile app from external sources (push notifications, email links, websites). Testing deep links is critical for marketing campaigns and notification-driven user flows. In Android, test deep links using the adb command or Appium's driver.executeScript("mobile: deepLink").
15. Network Condition Simulation β Offline and Slow 3G Testing
Mobile apps must behave gracefully under poor network conditions β 3G connectivity, airplane mode, or intermittent WiFi. Appium enables programmatic network condition simulation on Android using the setNetworkConnection API and on iOS through the Network Link Conditioner tool.
Network testing is essential for verifying offline caching, error message display (βNo internet connectionβ screens), retry mechanisms, and data sync behavior when connectivity is restored. These scenarios are frequently missed in desktop browser automation but are critical for mobile QA coverage.
16. Mobile App Performance Testing with Appium
Performance testing for mobile apps focuses on three key metrics: app launch time (cold start vs warm start), screen transition latency, and memory consumption over extended usage. Appium's getPerformanceData API for Android and Instruments profiling for iOS provide programmatic access to these metrics during automated test runs.
17. CI/CD Integration for Appium β Running Mobile Tests in GitHub Actions
Running Appium tests in CI/CD requires a different approach than web automation because you need either a cloud device farm (BrowserStack, Sauce Labs) or Android emulators running on the CI server. GitHub Actions supports Android emulator execution using the reactivecircus/android-emulator-runner action.
18. Common Appium Pitfalls and Production-Proven Fixes
Experienced mobile QA engineers accumulate battle-tested knowledge of Appiumβs failure modes. Here are the most frequently encountered pitfalls and their proven solutions:
- NoSuchSessionException after app crash: App crashes mid-test leave an orphan driver session. Implement
@AfterMethoddriver null-check withtry/catcharounddriver.quit(). - StaleElementReferenceException on screen transitions: Mobile transitions take longer than web. Increase explicit wait timeouts to 15β20 seconds for post-navigation element verification.
- XPath performance on Android: XPath performs full tree traversal on large Android layouts (100+ elements). Always prefer
AppiumBy.id()orAppiumBy.accessibilityId()as primary locators. - iOS Simulator keyboard not appearing: Disable hardware keyboard in iOS Simulator: Simulator menu β I/O β Keyboard β Toggle Software Keyboard. Or use
driver.executeScript("mobile: hideKeyboard")to dismiss. - Appium server port conflict (4723 already in use): Kill stale Appium processes:
pkill -f appiumor run on alternate ports using--port 4725.
Appium Interview Questions β Mobile Automation SDET Level
Q: How do you decide between testing on emulators vs real devices?
A: Emulators are sufficient for 80% of functional testing β fast, free, and reproducible. Reserve real devices for final regression runs, performance validation, network condition testing, and hardware-specific scenarios (camera, fingerprint, NFC). Cloud platforms like BrowserStack provide real device access without hardware maintenance overhead.
Q: How would you structure an Appium framework for a team of 10 QA engineers?
A: Use a Base Test class with thread-safe ThreadLocal<AppiumDriver> for parallel device execution, a ScreenFactory pattern (similar to PageFactory), a CapabilityManager that loads device configs from JSON files (not hardcoded), a DataFactory for test data generation, and Allure reporting with device screenshots attached on failure. Store all capabilities in a devices.json config file that can be modified without code changes.
Q: What is the difference between driver.closeApp() and driver.terminateApp()?
A: closeApp() sends the app to the background (mimicking the home button press) but keeps the session alive and app state preserved. terminateApp(bundleId) force-kills the app process completely, resetting all app state. Use terminateApp in @BeforeMethod to guarantee a clean app start for each test.
References & Official Documentation
- Appium 2.0 Official Documentation β Driver installation, capabilities reference, and migration from 1.x.
- Android Debug Bridge (ADB) Reference β Essential commands for Android device control.
- Apple XCTest Framework Documentation β iOS UI testing automation foundation.
- BrowserStack Appium Integration Guide β Real device cloud setup and configuration.
✍️ About the Author
Rammehar Dhiman is a Senior Mobile QA Engineer specializing in Appium 2.0, React Native, and Flutter app testing across Android and iOS platforms. He has built mobile automation frameworks for fintech and e-commerce apps serving 10+ million active users.
Summary Checklist for Appium 2.0 Mobile Automation Setup
- Step 1: Install Node.js, Appium 2.0 CLI, and driver plugins (
appium driver install uiautomator2/xcuitest). - Step 2: Set environment variables:
ANDROID_HOME,JAVA_HOME, and update systemPATH. - Step 3: Verify environment setup using
appium-doctorCLI tool. - Step 4: Use Appium Inspector to visually inspect element locators on connected Android/iOS devices.
- Step 5: Write test scripts using Page Object Model and run parallel tests on Cloud Device Farms.