Q10 of 26 · Mobile QA
How do UIAutomator2 and XCUITest drivers differ, and how does that affect your test code?
Short answer
Short answer: UIAutomator2 drives Android via Google's UIAutomator framework and uses Android-specific capabilities and locators (resource-id, UiSelector). XCUITest drives iOS via Apple's XCUITest framework and uses iOS-specific locators (predicate strings, class chains). Both speak the same W3C WebDriver protocol, so your high-level test logic is portable — only the locators and platform-specific commands differ.
Detail
The two drivers share the same interface — your test creates an AppiumDriver and calls findElement, click, sendKeys — but diverge in three areas:
Locator strategies: UIAutomator2 uniquely supports -android uiautomator (UiSelector queries) and id (resource IDs like com.example:id/button). XCUITest uniquely supports -ios predicate string and -ios class chain. The cross-platform strategy is accessibility id, which both support.
Driver-specific capabilities: some capabilities only apply to one driver — appium:avd (Android Virtual Device to launch) is Android-only; appium:xcodeOrgId (code signing) is iOS-only. Manage these in platform-specific configuration files rather than a single shared config.
Mobile-specific execute commands: both drivers expose platform capabilities via driver.execute('mobile: <command>', args). The command names differ: Android has mobile: pressKey, mobile: swipeGesture; iOS has mobile: tap, mobile: scroll. Abstract these behind a helper layer to keep test code portable.
A well-designed cross-platform test suite puts all platform divergence — locators and execute commands — inside screen object classes. Test logic calls loginScreen.tapLoginButton(); the screen object implementation selects the right locator based on driver.capabilities.platformName.