def runnerPool(getDevices): devices_Pool = [] for i in range(0, len(getDevices)): _pool = [] _initApp = {} print("=====runnerPool=========") print(getDevices) _initApp["deviceName"] = getDevices[i]["devices"] _initApp["udid"] = getDevices[i]["devices"] _initApp["platformVersion"] = getPhoneInfo(devices=_initApp["deviceName"])["release"] _initApp["platformName"] = "android" _initApp["port"] = getDevices[i]["port"] # _initApp["automationName"] = "uiautomator2" //关闭automation _initApp["systemPort"] = getDevices[i]["systemPort"] _initApp["app"] = getDevices[i]["app"] apkInfo = ApkInfo(_initApp["app"]) _initApp["appPackage"] = apkInfo.getApkBaseInfo()[0] _initApp["appActivity"] = apkInfo.getApkActivity() _pool.append(_initApp) devices_Pool.append(_initApp) pool = Pool(len(devices_Pool)) pool.map(runnerCaseApp, devices_Pool) pool.close() pool.join()
def runnerPool(getDevices): devices_Pool = [] for i in range(0, len(getDevices)): _pool = [] _initApp = {} _initApp["deviceName"] = getDevices[i]["devices"] _initApp["platformVersion"] = getPhoneInfo(devices=_initApp["deviceName"])["release"] _initApp["platformName"] = "android" _initApp["port"] = getDevices[i]["port"] _initApp["automationName"] = "uiautomator2" _initApp["systemPort"] = getDevices[i]["systemPort"] _initApp["app"] = getDevices[i]["app"] apkInfo = ApkInfo(_initApp["app"]) #_initApp["appPackage"] = apkInfo.getApkBaseInfo()[0] #_initApp["appPackage"] = " test.joko.com.myapplication" #_initApp["appActivity"] = apkInfo.getApkActivity() #_initApp["appActivity"] = ".welcome" _pool.append(_initApp) devices_Pool.append(_initApp) pool = Pool(len(devices_Pool)) pool.map(runnerCaseApp, devices_Pool) pool.close() pool.join()
def install_app(driver, device, app_pkg): # 手机是否已安装app,未安装则直接安装 apk = ApkInfo(app_pkg) pkg_name = apk.get_package_name() installed_pkg = adb_command(device, 'shell pm list package', False) if pkg_name not in installed_pkg: logger.info('app未安装,正在安装') Thread(target=loop_accept_alert, args=[driver]).start() # 启动多线程处理弹框 adb_command(device, 'install --no-streaming %s' % app_pkg) logger.info('app安装完成') return # 已安装与待安装的app版本号是否一致,不一致则卸载重装 new_version = apk.get_version_code() old_version = re.findall( r'versionCode=(\d+)', adb_command(device, 'shell dumpsys package %s' % pkg_name, False))[0] logger.info('新版本号:%s 旧版本号:%s' % (new_version, old_version)) if new_version != old_version: logger.info('app版本号不一致,卸载重装') adb_command(device, 'uninstall %s' % pkg_name) Thread(target=loop_accept_alert, args=[driver]).start() # 启动多线程处理弹框 adb_command(device, 'install --no-streaming %s' % app_pkg) logger.info('app安装完成') return logger.info('app已安装,无需安装')
def init(): getDevices = getYam(PATH("../yaml/devices.yaml")) apkPath = PATH("../yaml/" + getYam(PATH("../yaml/run.yaml"))["app"]) print(apkPath) apkInfo = ApkInfo(apkPath=apkPath) for item in getDevices: item["app"] = apkPath item["appPackage"] = apkInfo.getApkBaseInfo()[0] item["appActivity"] = apkInfo.getApkActivity() # 统计 of = OperateFile(PATH("../Log/info.pickle")) of.mkdir_file() of = OperateFile(PATH("../Log/sum.pickle")) of.mkdir_file() data = read(PATH("../Log/sum.pickle")) data["appName"] = apkInfo.getApkName() data["appSize"] = apkInfo.getApkSize() data["appVersion"] = apkInfo.getApkBaseInfo()[2] data["sum"] = 0 data["pass"] = 0 data["fail"] = 0 write(data=data, path=PATH("../Log/sum.pickle")) return getDevices
def runnerPool(getDevices): devices_Pool = [] for i in range(0, len(getDevices)): _pool = [] _initApp = {} _initApp["deviceName"] = getDevices[i]["devices"] _initApp["platformVersion"] = getPhoneInfo( devices=_initApp["deviceName"])["release"] _initApp["platformName"] = "android" _initApp["port"] = getDevices[i]["port"] _initApp["automationName"] = "uiautomator2" _initApp["systemPort"] = getDevices[i]["systemPort"] _initApp["app"] = getDevices[i]["app"] #调取Base.Apk.py文件中的ApkInfo类,传入测试app apkInfo = ApkInfo(_initApp["app"]) _initApp["appPackage"] = apkInfo.getApkBaseInfo()[0] _initApp["appActivity"] = apkInfo.getApkActivity() _initApp[ "waitappActivity"] = 'com.smartcity.maxnerva.vborad_phone.view.activity.*' _pool.append(_initApp) devices_Pool.append(_initApp) pool = Pool(len(devices_Pool)) #运行runnerCaseApp方法 pool.map(runnerCaseApp, devices_Pool) pool.close() pool.join()
def get_devices(_role): devices = {} if _role == 'teacher': apkInfo = ApkInfo(PATH(cfg.get('T_APK_PATH', 'path'))) devices['appPackage'] = apkInfo.get_appPackage()[0] devices['appActivity'] = apkInfo.get_appActivity() devices["app"] = PATH(cfg.get('T_APK_PATH', 'path')) devices['data_path'] = PATH(cfg.get('T_DATA_PATH', 'path')) else: apkInfo = ApkInfo(PATH(cfg.get('P_APK_PATH', 'path'))) devices['appPackage'] = apkInfo.get_appPackage()[0] devices['appActivity'] = apkInfo.get_appActivity() devices["app"] = PATH(cfg.get('P_APK_PATH', 'path')) devices['data_path'] = PATH(cfg.get('P_DATA_PATH', 'path')) devices['platformName'] = 'Android' devices['deviceName'] = AdbOperate().get_device_id()[0] devices['platformVersion'] = AdbOperate.get_android_ver( devices['deviceName']) devices['noReset'] = cfg.get('NORESET', 'noReset') devices['port'] = cfg.get('PORT', 'port') if int(devices['platformVersion'].split('.')[0]) >= 6: devices['automationName'] = 'uiautomator2' return devices
def get_desired_caps(self, device_alias, app): desired_caps = self.device_info.get(device_alias) if not desired_caps: raise Exception('找不到此设备:%s,请检查配置./config/devices.yaml' % device_alias) # app包 desired_caps['app'] = app # 闲置超时时间 desired_caps['newCommandTimeout'] = 3600 # 如果配置文件定义了appPackage、appActivity,则按配置文件来,否则根据apk包自动获取; if not desired_caps["appPackage"] or not desired_caps["appActivity"]: apk_info = ApkInfo(app) if not desired_caps["appPackage"]: desired_caps["appPackage"] = apk_info.get_package_name() if not desired_caps["appActivity"]: desired_caps["appActivity"] = apk_info.get_activity() # 先检查有线连接是否OK,若未连接,采用无线连接 device_name = desired_caps['deviceName'] if not self.adb.is_connected(device_name): device_list = desired_caps['device_address'] if not device_list: device_list = [] for i in device_list: try: device_name = self.adb.connect(i) # 兼容性模拟器调试 if not device_name: continue break except ConnectionError as e: print(e) desired_caps['deviceName'] = device_name phone_info = get_phone_info(device_name) # 自动设置platformVersion desired_caps["platformVersion"] = phone_info["release"] # 从记忆库中选择chromedriver,如果没有则自动选择,并记录到记忆库 webview_version = self._read_webview_version(phone_info["model"]) if not webview_version: webview_version = get_webview_version(device_name, desired_caps['appPackage'], desired_caps['appActivity']) self._save_webview_version(phone_info["model"], webview_version) desired_caps['chromedriverExecutable'] = auto_chromedriver(webview_version) return desired_caps