Android & iOS Test Automation
Writing cross-platform Appium tests requires understanding both Android and iOS automation patterns, their differences in locator strategies, and how to share test logic while handling platform differences. This topic gives you production patterns for both platforms with a shared test architecture.
Cross-Platform Test Architecture
# ══════════════════════════════════════════════════════════════
# SHARED TEST ARCHITECTURE (Android + iOS)
# ══════════════════════════════════════════════════════════════
# mobile_tests/
# conftest.py ← Driver fixtures for Android and iOS
# pages/
# base_page.py ← Shared mobile actions
# login_page.py ← Login page with platform-aware locators
# home_page.py
# tests/
# test_login.py ← Same test logic, runs on both platforms
# test_data/
# android_caps.json ← Android device capabilities
# ios_caps.json ← iOS device capabilities
# ── pages/login_page.py (cross-platform page object) ──────────
import platform
from appium.webdriver.common.appiumby import AppiumBy
class LoginPage:
# Platform-aware locators: same element, different ID format
LOCATORS = {
"android": {
"email_input": (AppiumBy.ID, "com.myapp:id/email_input"),
"password_input": (AppiumBy.ID, "com.myapp:id/password_input"),
"login_button": (AppiumBy.ID, "com.myapp:id/login_btn"),
"error_message": (AppiumBy.ID, "com.myapp:id/error_text"),
},
"ios": {
"email_input": (AppiumBy.ACCESSIBILITY_ID, "email-input"),
"password_input": (AppiumBy.ACCESSIBILITY_ID, "password-input"),
"login_button": (AppiumBy.ACCESSIBILITY_ID, "login-button"),
"error_message": (AppiumBy.ACCESSIBILITY_ID, "error-message"),
}
}
def __init__(self, driver, platform="android"):
self.driver = driver
self.locators = self.LOCATORS[platform]
def enter_email(self, email):
self.driver.find_element(*self.locators["email_input"]).send_keys(email)
def enter_password(self, password):
self.driver.find_element(*self.locators["password_input"]).send_keys(password)
def tap_login(self):
self.driver.find_element(*self.locators["login_button"]).click()
def login(self, email, password):
self.enter_email(email)
self.enter_password(password)
self.tap_login()
def get_error_text(self):
return self.driver.find_element(*self.locators["error_message"]).text
# ── tests/test_login.py (runs on both platforms) ─────────────
@pytest.mark.parametrize("platform", ["android"]) # add "ios" when available
def test_login_valid_credentials(platform, request):
driver = request.getfixturevalue(f"{platform}_driver")
login_page = LoginPage(driver, platform=platform)
login_page.login("alice@test.com", "Test@1234")
wait = WebDriverWait(driver, 15)
home_element = wait.until(EC.presence_of_element_located(
(AppiumBy.ACCESSIBILITY_ID, "home-screen")
))
assert home_element.is_displayed()Common Mistakes
- Separate test files for Android and iOS — use shared test logic with platform-specific page objects; avoid code duplication
- Using resource-id (Android) on iOS tests — Android uses resource-id/ID; iOS uses accessibility identifier; always check platform in locator strategy
- Not waiting for app animations — mobile apps have native transitions; wait for animation to complete before asserting element visibility
- Typing text without clearing first — mobile text fields often retain value; always clear() before send_keys() on input fields
Tip
Tip
Practice Android iOS Test Automation in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Playwright rising fast — modern API, auto-waits, all browsers
Practice Task
Note
Practice Task — (1) Write a working example of Android iOS Test Automation from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Android iOS Test Automation is skipping edge case testing — empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready software testing code.
Key Takeaways
- Writing cross-platform Appium tests requires understanding both Android and iOS automation patterns, their differences in locator strategies, and how to share test logic while handling platform differences.
- Separate test files for Android and iOS — use shared test logic with platform-specific page objects; avoid code duplication
- Using resource-id (Android) on iOS tests — Android uses resource-id/ID; iOS uses accessibility identifier; always check platform in locator strategy
- Not waiting for app animations — mobile apps have native transitions; wait for animation to complete before asserting element visibility