30 / 66 · 09 Mobile & Cross-Platform Testing · Appium Fundamentals← prev⊞ allnext →☰ Read as one page
5.6Common Appium Patterns
Page Object Model for Mobile
# pages/login_page.py
class LoginPage:
def __init__(self, driver):
self.driver = driver
@property
def email_field(self):
return self.driver.find_element(AppiumBy.ACCESSIBILITY_ID, "email-input")
@property
def password_field(self):
return self.driver.find_element(AppiumBy.ACCESSIBILITY_ID, "password-input")
@property
def login_button(self):
return self.driver.find_element(AppiumBy.ACCESSIBILITY_ID, "login-button")
@property
def error_message(self):
return self.driver.find_element(AppiumBy.ACCESSIBILITY_ID, "login-error")
def login(self, email, password):
self.email_field.send_keys(email)
self.password_field.send_keys(password)
self.login_button.click()
def is_error_displayed(self):
try:
return self.error_message.is_displayed()
except:
return False
Handling App State
# Reset app state between tests
def reset_app(driver):
"""Reset the app to initial state without reinstalling."""
driver.reset()
# Handle permission dialogs
def handle_permission_dialog(driver, allow=True):
"""Handle system permission dialogs (camera, location, etc.)."""
try:
if allow:
driver.find_element(
AppiumBy.ID, "com.android.permissioncontroller:id/permission_allow_button"
).click()
else:
driver.find_element(
AppiumBy.ID, "com.android.permissioncontroller:id/permission_deny_button"
).click()
except:
pass # No dialog present
# Wait for network operations
def wait_for_loading(driver, timeout=30):
"""Wait for loading spinner to disappear."""
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
try:
WebDriverWait(driver, timeout).until(
EC.invisibility_of_element_located(
(AppiumBy.ACCESSIBILITY_ID, "loading-spinner")
)
)
except:
pass
Appium remains the industry standard for cross-platform mobile testing because of its language flexibility, real-device support, and evolution toward AI-native patterns. Master it, and you can automate testing on any mobile platform.