Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

## 请问是否支持多设备并行测试? #93

Closed
yumao123 opened this issue Apr 29, 2018 · 8 comments
Closed

## 请问是否支持多设备并行测试? #93

yumao123 opened this issue Apr 29, 2018 · 8 comments

Comments

@yumao123
Copy link

请问是否支持多设备并行测试?

是否支持脚本一次运行,多台机器分开跑?
推荐的方法是哪些?

@codeskyblue
Copy link
Member

开多线程,每台设备分别跑

@flyfire100
Copy link

import os,time
import uiautomator2 as u2
from multiprocessing import Process,Queue

def get_devices_serials():
    devices_list = []
    fd = os.popen("adb devices")
    devices_list_src = fd.readlines()
    fd.close()
    for device in devices_list_src:
        if "device\n" in device:
            device = device.replace("\tdevice\n","")
            devices_list.append(device)
    return devices_list
    
def worker( serial ):
    os.system("python -m uiautomator2 init  --serial %s"%serial)
    d = u2.connect(serial)
    print(d.info)
    #这里可以添加自己要执行的脚本
    
if __name__ == "__main__":
    process_list = []
    serial_list = get_devices_serials()
    for index in range( len(serial_list) ):
        p = Process( target=worker, args=( serial_list[index],  ) )
        p.start()
        process_list.append(p)
    for p in process_list:
        p.join()
    print("all task done!")

@flyfire100
Copy link

flyfire100 commented May 5, 2018

这个issue可以关闭了吧?目前我就是用上面的方式实现多进程并发执行测试用例的,楼主可以参考下,有问题的话可以继续探讨

@yumao123 yumao123 closed this as completed May 8, 2018
@yumao123
Copy link
Author

yumao123 commented May 8, 2018

谢谢

@oujibahei
Copy link

oujibahei commented Jan 23, 2019

@flyfire100 @codeskyblue 似乎并不能实现多设备连接 print的所有设备都是第一个connect上的
u2.connect()使用过一次之后再调用不能改变返回的值

@codeskyblue
Copy link
Member

@oujubahei 历史问题,已经修复了

@wangshuwen1107
Copy link

u2.connect()使用过一次之后再调用不能改变返回的值,也遇到了相同问题,有解决吗

@codeskyblue
Copy link
Member

@wangshuwen1107 说详细点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants