Appium Python Client

repository·master·Indexed 23 days ago

https://github.com/appium/python-client

A Python client library for automating mobile applications, fully compliant with the WebDriver Protocol. It provides mobile-specific helpers and options for Android, iOS, and other platforms, including specialized extensions for Android device control and Flutter integration. Version 5.3.1.

Tokens
4.2K
Snippets
10
Records
21
Agent score
83%

What's inside Appium-Python-Client

  1. Explore the webdriver.extensions package

    master

    The webdriver.extensions package provides specialized modules that extend the core WebDriver functionality with mobile-specific capabilities and Appium commands. These extensions allow you to interact with device hardware, manage application states, handle clipboard operations, and perform advanced actions like screen recording or image comparison.

    Key functional areas available via extensions include:

    • Mobile Commands: execute_mobile_command for sending raw mobile commands.
    • Device Interaction: clipboard, device_time, hw_actions, keyboard, and location.
    • Application Management: applications, context, and session.
    • Media & Logs: images_comparison, logs, log_event, and screen_record.
    • System/Filesystem: remote_fs and settings.
  2. Use the Flutter integration extension

    master

    The webdriver.extensions.flutter_integration package provides specialized tools for automating Flutter applications. It is composed of three main submodules:

    1. flutter_commands: Contains commands specifically designed to interact with Flutter application internals.
    2. flutter_finder: Provides specialized finder mechanisms to locate Flutter widgets within the application tree.
    3. scroll_directions: Defines the available directions for performing scroll actions within Flutter widgets.
  3. Explore the webdriver package structure

    master

    The webdriver package is the core of the Appium Python Client. It is organized into several subpackages and submodules that handle connection management, mobile-specific commands, and element interactions.

    Core Subpackages:

    • webdriver.common: Contains shared utilities and base classes.
    • webdriver.extensions: Contains extensions to the standard WebDriver functionality.

    Key Submodules:

    • webdriver.appium_connection: Manages the connection to the Appium server.
    • webdriver.appium_service: Handles the lifecycle of the Appium service.
    • webdriver.webdriver: The primary entry point for creating WebDriver instances.
    • webdriver.webelement: Defines the interface for interacting with web/mobile elements.
    • webdriver.mobilecommand: Provides support for mobile-specific commands.
    • webdriver.switch_to: Provides methods to switch context (e.g., between NATIVE_APP and WEBVIEW).
  4. Explore Android-specific extensions in webdriver.extensions.android

    master

    The webdriver.extensions.android package provides specialized extensions for interacting with Android devices. It is organized into several submodules, each targeting a specific area of Android device control or state monitoring:

    • activities: Manage and interact with Android Activities.
    • common: Shared utilities and common Android-specific logic.
    • display: Control and query display settings and states.
    • gsm: Interact with GSM/cellular network features.
    • nativekey: Simulate hardware key presses (e.g., Back, Home, Recent Apps).
    • network: Manage and monitor network connectivity and states.
    • performance: Retrieve device performance metrics.
    • power: Control power states (e.g., screen on/off, battery status).
    • sms: Send, receive, and manage SMS messages.
    • system_bars: Control and interact with Android system bars (Status bar, Navigation bar).
  5. Extend HTTP request read timeout

    master

    The client has a default read timeout of 120 seconds. To extend this, use one of the following methods:

    1. Recommended: Configure the timeout via appium.webdriver.client_config.AppiumClientConfig or selenium.webdriver.remote.client_config.ClientConfig using the timeout argument, or provide init_args_for_pool_manager for the underlying urllib3.PoolManager.
    2. Fallback: Set the GLOBAL_DEFAULT_TIMEOUT environment variable (Note: this method is being deprecated in favor of Selenium's binding changes).
  6. Configure driver options using automation-specific classes

    master

    Since client version 2.3.0, you should use specific Options classes instead of desired_capabilities. These classes provide type-safe ways to set capabilities for different automation engines.

    Common automation options and their package paths:

    • uiautomator2: appium.options.android.UiAutomator2Options
    • espresso: appium.options.android.EspressoOptions
    • xcuitest: appium.options.ios.XCUITestOptions
    • safari: appium.options.ios.SafariOptions
    • mac2: appium.options.mac.Mac2Options
    • windows: appium.options.WindowsOptions
    • gecko: appium.options.GeckoOptions
    • flutterintegration: appium.options.flutter_integration.FlutterOptions
    • any: appium.options.common.base.AppiumOptions
  7. Install the Appium Python Client

    master

    You can install the Appium Python client using one of the following three methods:

    Install the package directly using pip:

    pip install Appium-Python-Client

    2. From Source via PyPI Tarball

    Download and unarchive the source tarball (e.g., Appium-Python-Client-X.X.tar.gz) from PyPI, then install it:

    tar -xvf Appium-Python-Client-X.X.tar.gz
    cd Appium-Python-Client-X.X
    pip install .

    3. From Source via GitHub

    Clone the repository and install from the local directory:

    git clone git@github.com:appium/python-client.git
    cd python-client
    pip install .
  8. Relax SSL validation for self-signed certificates

    master

    To connect to a host with an invalid or self-signed certificate, you can relax SSL validation.

    For Appium Python client v4.3.0 and later (Recommended): Use selenium.webdriver.remote.client_config.ClientConfig with ignore_certificates=True.

    For older versions: Pass strict_ssl=False as an argument to webdriver.Remote.

    from appium import webdriver
    from selenium.webdriver.remote.client_config import ClientConfig
    
    # Recommended for v4.3.0+
    client_config = ClientConfig(
        remote_server_addr='http://127.0.0.1:4723',
        ignore_certificates=True
    )
    driver = webdriver.Remote(client_config.remote_server_addr, options=options, client_config=client_config)
  9. Set up the development environment

    master

    The project uses uv for dependency management. To set up a local development environment:

    1. Install uv and sync dependencies:
      make install-uv
      exec $SHELL
      make sync-dev
    2. If you need a specific Python version, run uv venv --python <V> (e.g., 3.12) before make sync-dev.
    3. Activate the environment:
      source .venv/bin/activate
    make install-uv
    exec $SHELL
    make sync-dev
  10. Migrate from Appium Python Client v3 to v4

    master

    Upgrading from v3 to v4 involves the following changes:

    Removed Classes

    • MultiAction and TouchAction have been removed. Use W3C WebDriver actions or mobile: extensions instead.

    Deprecated Constants

    • AppiumBy.WINDOWS_UI_AUTOMATION is deprecated and has no current usage.
  11. Migrate from Appium Python Client v4 to v5

    master

    If you are upgrading from v4 to v5, note the following changes:

    Use AppiumClientConfig

    If you previously used keep_alive, direct_connection, or strict_ssl arguments directly in webdriver.Remote, you must now use the AppiumClientConfig object passed via the client_config argument.

    Update Server URL

    Use http://127.0.0.1:4723 as the default server URL instead of the legacy http://127.0.0.1:4444/wd/hub path.

    from appium.webdriver.client_config import AppiumClientConfig
    
    SERVER_URL_BASE = 'http://127.0.0.1:4723'
    client_config = AppiumClientConfig(
        remote_server_addr=SERVER_URL_BASE,
        direct_connection=True,
        keep_alive=False,
        ignore_certificates=True,
    )
    
    driver = webdriver.Remote(
        options=UiAutomator2Options().load_capabilities(desired_caps),
        client_config=client_config
    )