原创  python +appium 获取电脑连接的所有手机多线程并发控制

分类:android 2019-04-27T20:14:03    18人阅读   
def get_phone_list():
    t_list = []
    devices = list(os.popen('adb devices').readlines())
    for index in range(1, len(devices) - 1):
        desire_caps = dict()
        desire_caps['platformName'] = 'Android'
        desire_caps['noReset'] = True
        desire_caps["simpleIsVisibleCheck"] = True
        item = devices[index]
        deviceId = str(item).split("\t")[0]
        deviceAndroidVersion = list(
            os.popen('adb -s ' + deviceId + ' shell  getprop ro.build.version.release').readlines())
        brand = list(
            os.popen('adb -s ' + deviceId + ' shell  getprop ro.product.brand').readlines())
        model = list(
            os.popen('adb -s ' + deviceId + ' shell  getprop ro.product.model').readlines())

        deviceVersion = str(deviceAndroidVersion[0]).replace("\n", "")
        brand = str(brand[0]).replace("\n", "")
        model = str(model[0]).replace("\n", "")
        desire_caps['platformVersion'] = deviceVersion
        desire_caps['deviceName'] = deviceId
        desire_caps['id'] = brand + '-' + model
        print(brand + '-' + model)
        print(deviceVersion)
        print(deviceId)
        thread = threading.Thread(target=run_one, name=desire_caps['id'], args=(desire_caps,))
        t_list.append(thread)
    return t_list


if __name__ == "__main__":
    t_list = get_phone_list()
    for item in t_list:
        item.start()
    for item in t_list:
        item.join()