Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Managing Concurrent Mobile Automation on Multiple Devices with Appium and Python

Tech 1

When scaling mobile automation to run across multiple terminals simultaneously, utilizing Python's multi-threading capabilities is the standard approach. However, identifying devices correctly within the Appium server session is a common point of failure for many engineers.

Ensuring Device Uniqueness with UDID

In a multi-device setup, the deviceName capability in the Appium configuration is often descriptive rather than functional. Many developers assume this field uniquely identifies the phone, but Appium frequently ignores it or picks the first available device if only deviceName is provided. The udid (Unique Device Identifier) is the essential parameter for routing commands to specific hardware.

You can retrieve the udid by running the following command in your terminal:

adb devices

The output will list the serial numbers:

List of devices attached
SN12345678      device
SN87654321      device

In your automation script, you must include the udid in your desired capabilities to ensure the driver binds to the correct device. Below is an example of how to structure the session initialization:

from appium import webdriver

def create_driver_session(device_id, package_id, activity_name, platform_ver):
    # udid is the critical parameter for parallel execution
    capabilities = {
        "platformName": "Android",
        "platformVersion": platform_ver,
        "automationName": "UiAutomator2",
        "udid": device_id, 
        "deviceName": device_id,
        "appPackage": package_id,
        "appActivity": activity_name,
        "noReset": True,
        "autoAcceptAlerts": "true",
        "newCommandTimeout": 180
    }

    # Connect to the Appium server
    executor_url = "http://127.0.0.1:4723/wd/hub"
    driver = webdriver.Remote(executor_url, capabilities)
    return driver

Consistency in Application Package Names

Another hurdle when deploying tests to multiple devices is the inconsistency of package names across various distribution channels. The same application might have different suffixes depending on whether it was downloaded from an OEM-specific store (like Vivo or Xiaomi) or a third-party browser.

For example, a application package might vary as follows:

  • Standard Version: com.example.app.main
  • OEM Distributed Version: com.example.app.oem_suffix

When automating parallel tests, ensure that the APKs installed across all target devices are from the same source to avoid ActivityNotFound errors. Standardizing the installation processs—such as using a single shared APK file via adb install—is the most reliable way to maintain consistent package names and activities across the entire test fleet.

Tags: AppiumPython

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.