English 中文(简体)
• 如何有效地控制与平线平行的多种和海底装置?
原标题:How to efficiently control multiple android devices in parallel with python?

我是比利时的一个计算机科学学生,从事一个项目,涉及simultaneously 控制来自Avry script的多安装置。 在测试期间,我在执行有效的多管齐下演播室宣传器方面遇到挑战,我早就利用这些宣传器,然后再与实际装置连接。 我曾探讨过像 App和 Sel服务器等解决办法,但找到与我的需求相匹配的明确信息和直截了当的工作流程证明是困难的。

I attempted using ADB and Appium, but could only control one phone at a time. My experiments with Appium and Selenium server have been challenging, and I’m struggling to find clear information or simple workflows for this task.

这种情况阻止了我的进展,我欢迎任何建议或建议,这些建议或建议可以简化同时通过沙尔控制安乐团的进程。 每一执行者不应履行同样的任务;他们应当遵循由斯图尔特概述的程序途径。 我愿意彻底改变我努力执行的工作流程。

Below is my attempt to retrieve connected devices using ADB and an initial try to launch Appium servers for each device:

# Function to get connected devices
def get_connected_devices():

    devices_configs = []
    try:
        output = subprocess.check_output([adb_path,  devices ]).decode( utf-8 )
        devices = output.strip().split( 
 )[1:]


        for device in devices:
            ud_id = device.split( 	 )[0]
            os_version = (
                subprocess.check_output(
                    [
                        adb_path,
                         -s ,
                        ud_id,
                         shell ,
                         getprop ,
                         ro.build.version.release ,
                    ]
                )
                .decode( utf-8 )
                .strip()
            )
            platform = "Android"
            system_port = str(8200 + len(devices_configs))
            chrome_driver_port = str(8100 + len(devices_configs))
            device_details = {
                "device": ud_id,
                "os_version": os_version,
                "ud_id": ud_id,
                "platform": platform,
                "systemPort": system_port,
            }
            devices_configs.append(device_details)
        return devices_configs
    except subprocess.CalledProcessError as e:
        print(f"Error executing ADB command: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

# Retrieve connected devices
connected_devices = get_connected_devices()

# Start Appium servers for each device
processes = []
for i in range(len(connected_devices)):
    port = 4724 + i
    cmd = ["start", "appium", "-p", str(port)]
    process = subprocess.Popen(cmd, shell=True)
    processes.append(process)

尽管如此,我还是遇到了强迫使用特定装置港口的问题,因为它把同一港口用于所有装置:

# Pair each connected device with a server
device_server_pairs = list(zip(connected_devices, servers))

# Start Appium sessions using threads
with concurrent.futures.ThreadPoolExecutor() as executor:
    executor.map(start_appium_session, device_server_pairs)

# Function to start Appium session for each device
def start_appium_session(device_config_server_tuple):
    device_config, server = device_config_server_tuple
    capabilities = {
         platformName : device_config[ platform ],
         platformVersion : device_config[ os_version ],
         deviceName : device_config[ ud_id ],
         systemPort : device_config[ systemPort ],
         app : APP_PATH,
    }

    driver = webdriver.Remote(server, options=UiAutomator2Options().load_capabilities(capabilities))

I appreciate any insights or improvements you could provide.

问题回答

您可尝试AndroidViewClient/culebra,在一定时间可以与多种装置连接。

You can find some videos at https://github.com/dtmilano/AndroidViewClient/wiki/Resources#screencasts-and-videos, particularly Culebra GUI: Multi-device tests. While it shows the same test script being run on all the devices there s nothing that prevents you from running completely different things.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签