Python client library for Appium mobile automation framework extending Selenium WebDriver with iOS and Android testing capabilities
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Core WebDriver functionality providing the foundation for all mobile automation operations. The WebDriver class extends Selenium's Remote WebDriver with Appium-specific capabilities and mobile element handling.
Main WebDriver class that extends Selenium's Remote WebDriver with Appium-specific functionality and extension support.
class WebDriver:
def __init__(self, command_executor: str, extensions: list = None,
options = None, client_config = None):
"""
Initialize WebDriver with Appium capabilities.
Args:
command_executor (str): URL of Appium server endpoint
extensions (list, optional): List of extension classes to add
options: Platform-specific options object (UiAutomator2Options, XCUITestOptions, etc.)
client_config: Client configuration for connection settings
"""
def start_session(self, capabilities: dict, browser_profile = None):
"""
Start a new WebDriver session with specified capabilities.
Args:
capabilities (dict): Session capabilities dictionary
browser_profile: Browser profile configuration (optional)
"""
def get_status(self) -> dict:
"""
Get the status of the Appium server.
Returns:
dict: Server status information including build info and supported platforms
"""
def create_web_element(self, element_id: str):
"""
Create a MobileWebElement from element ID.
Args:
element_id (str): Element identifier returned by find operations
Returns:
WebElement: Mobile-enabled WebElement instance
"""
def delete_extensions(self):
"""Remove all added extensions from the WebDriver instance."""
def assert_extension_exists(self, ext_name: str):
"""
Verify that a named extension is available.
Args:
ext_name (str): Name of extension to verify
Raises:
Exception: If extension is not available
"""
def mark_extension_absence(self, ext_name: str):
"""
Mark an extension as absent to avoid repeated checks.
Args:
ext_name (str): Name of extension to mark as absent
"""
@property
def orientation(self) -> str:
"""
Get or set device orientation.
Returns:
str: Current orientation ('LANDSCAPE' or 'PORTRAIT')
"""
@orientation.setter
def orientation(self, value: str):
"""
Set device orientation.
Args:
value (str): Orientation to set ('LANDSCAPE' or 'PORTRAIT')
"""
@property
def switch_to(self):
"""
Access mobile-specific switching functionality.
Returns:
MobileSwitchTo: Switch context manager for mobile contexts
"""Mobile WebElement extending Selenium's WebElement with mobile-specific methods and enhanced functionality.
class WebElement:
def get_attribute(self, name: str):
"""
Get element attribute value.
Args:
name (str): Attribute name
Returns:
str or dict: Attribute value, returns dict for complex attributes
"""
def is_displayed(self) -> bool:
"""
Check if element is visible on screen.
Returns:
bool: True if element is displayed, False otherwise
"""
def clear(self):
"""
Clear element text content.
Returns:
WebElement: Self for method chaining
"""
def send_keys(self, *value):
"""
Send text input to element.
Args:
*value: Text values to send
Returns:
WebElement: Self for method chaining
"""
@property
def location_in_view(self) -> dict:
"""
Get element location relative to the current view.
Returns:
dict: Location coordinates {'x': int, 'y': int}
"""Base class for creating custom WebDriver extensions with command registration and execution.
class ExtensionBase:
def method_name(self) -> str:
"""
Abstract method to return the extension's method name.
Returns:
str: Method name that will be added to WebDriver
"""
def add_command(self) -> dict:
"""
Abstract method to define HTTP method and URL for the extension.
Returns:
dict: Command definition with 'method' and 'url' keys
"""
def execute(self, parameters: dict = None):
"""
Execute the extension command with given parameters.
Args:
parameters (dict, optional): Command parameters
Returns:
Any: Command execution result
"""Common exceptions that may be raised during WebDriver operations.
class NoSuchContextException(Exception):
"""Raised when attempting to switch to a context that doesn't exist."""
pass
# Standard Selenium exceptions also apply
from selenium.common.exceptions import (
NoSuchElementException,
TimeoutException,
WebDriverException,
InvalidArgumentException,
ElementNotInteractableException
)from appium import webdriver
from appium.options.android import UiAutomator2Options
# Configure options
options = UiAutomator2Options()
options.platform_name = "Android"
options.device_name = "Android Emulator"
options.app = "/path/to/app.apk"
# Start session
driver = webdriver.Remote("http://localhost:4723", options=options)
# Verify server status
status = driver.get_status()
print(f"Appium version: {status['build']['version']}")
# Find and interact with elements
element = driver.find_element("id", "button1")
element.click()
# Clean up
driver.quit()from appium.webdriver.webdriver import ExtensionBase
class CustomExtension(ExtensionBase):
def method_name(self):
return "custom_action"
def add_command(self):
return {
'method': 'POST',
'url': '/session/$sessionId/custom/action'
}
def execute(self, parameters=None):
return self.driver.execute('custom_action', parameters)
# Add extension to WebDriver
driver = webdriver.Remote("http://localhost:4723", options=options,
extensions=[CustomExtension])
# Use custom extension
result = driver.custom_action({'param': 'value'})from typing import Union, List, Dict
# Connection and configuration types
ClientConfig = Union[dict, object]
Capabilities = dict
CommandExecutor = str
ExtensionList = List[ExtensionBase]
# Element and location types
ElementId = str
Coordinates = Dict[str, int]
AttributeValue = Union[str, dict, None]
# Orientation constants
DeviceOrientation = str # 'LANDSCAPE' or 'PORTRAIT'
# Client configuration
AppiumClientConfig = object # Configuration for connection settings
# Switch context types
MobileSwitchTo = object # Mobile context switching managerInstall with Tessl CLI
npx tessl i tessl/pypi-appium-python-client