def clear_background_activities(self): info = os.popen(self.adb + " -s " + self.device_connect_url + " shell dumpsys activity activities | grep affinity") activitie_List = [i.strip().replace("affinity=", "") for i in info] skill_activitie_List = [ i for i in getvaule(configPath, "main_frame_act", self.model).split(",") ] for i in activitie_List: if i not in skill_activitie_List: print(self.adb + " -s " + self.device_connect_url + " shell pm clear " + i) os.system(self.adb + " -s " + self.device_connect_url + " shell pm clear " + i) elif i in skill_activitie_List: continue os.system(self.adb + " -s " + self.device_connect_url + " shell input keyevent HOME") os.system(self.adb + " -s " + self.device_connect_url + " shell input keyevent APP_SWITCH") tap_pos = [ i for i in getvaule(configPath, "main_frame_clear_button_pos", self.model).split(",") ] os.system(self.adb + " -s " + self.device_connect_url + " shell input tap " + tap_pos[0] + " " + tap_pos[1]) os.system(self.adb + " -s " + self.device_connect_url + " shell input keyevent HOME")
def download_apk_to_phone(self): """ 下载客户端apk至当前机型默认下载目录下 :return: """ url = getvaule(configPath, "config", "apk_url") file_size = 0 UUID = url.split("/")[-1] file_path = getvaule(configPath, "Down_load_path", self.model) shell("am start -a android.intent.action.VIEW -d " + url) tap_info = getvaule(configPath, "input_tap", self.model).split(",") time.sleep(int(tap_info[2])) shell("input tap " + tap_info[0] + " " + tap_info[1]) now_size = 0 while True: time.sleep(8) info = os.popen(self.adb + " -s " + self.device_connect_url + " shell du -k " + file_path + UUID) for i in info: now_size = i.split('\t')[0] if now_size == file_size: print(now_size) print(file_size) print("Download apk file success") break else: file_size = now_size
def __init__(self, device): self.device = device self.install_act = Install_api(self.device) self.model = self.install_act.model self.phone_install = True if getvaule(config_path, "phone_install", self.model) == "1" else False self.command_install = True if getvaule(config_path, "command_install", self.model) == "1" else False self.is_need_to_mv_apk = True if getvaule(config_path, "is_need_to_mv_apk", self.model) == "1" else False
def clear_phone_apk(self): """ 清理当前机型的默认下载目录下的所有apk文件 :return:null """ file_path = getvaule(configPath, "Down_load_path", self.model) os.system(self.adb + " -s " + self.device_connect_url + " shell rm " + os.path.join(file_path, "*.apk"))
def __init__(self, device): self.air_adb = ADB() self.adb = self.air_adb.adb_path self.device = device self.device_connect_url = get_device_source_info( self.device)["device"]["source"]["remoteConnectAddress"] connect_device("Android://127.0.0.1:5037/" + self.device_connect_url) self.model = str(shell("getprop ro.product.model")).replace( " ", "_").strip("\n").strip("\r") self.serialno = str(shell("getprop ro.serialno")).strip("\n") self.main_configPath = os.path.join(getpropath()[0], "cfg", "config.ini") self.build_type = getvaule(self.main_configPath, "config", "build_type") self.package = getvaule(self.main_configPath, "active_config", self.build_type)
def install_apk_local_cmd(self): url = getvaule(configPath, "config", "apk_url") UUID = url.split("/")[-1] download_path = os.path.join(getpropath()[0], "res", "apk") file_path = os.path.join(download_path, UUID) print(self.adb + " -s " + self.device_connect_url + " install -r -g " + file_path) os.system(self.adb + " -s " + self.device_connect_url + " install -r -g " + file_path)
def install_apk_phone_cmd(self): """ 安装下载至设备中的apk文件 :return: """ url = getvaule(configPath, "config", "apk_url") UUID = url.split("/")[-1] file_path = getvaule(configPath, "Down_load_path", self.model) print(self.adb + " -s " + self.device_connect_url + " shell pm install -r -g " + file_path + UUID) try: os.system(self.adb + " -s " + self.device_connect_url + " shell pm clear " + self.package) os.system(self.adb + " -s " + self.device_connect_url + " shell pm uninstall " + self.package) except: pass os.system(self.adb + " -s " + self.device_connect_url + " shell pm install -r -g " + file_path + UUID)
def creat_ui_xml(self): """ 获取手机当前界面的控件信息并生成xml文件 :return:xml文件的路径地址 """ file_path = getvaule(configPath, "Down_load_path", self.model) os.system(self.adb + " -s " + self.device_connect_url + " shell uiautomator dump " + file_path + "ui.xml") if not os.path.exists(os.path.join(res_ui_path, self.serialno)): os.makedirs(os.path.join(res_ui_path, self.serialno)) os.system(self.adb + " -s " + self.device_connect_url + " pull " + file_path + "ui.xml " + os.path.join(res_ui_path, self.serialno)) return os.path.join(res_ui_path, self.serialno, "ui.xml")
def download_apk_to_local(self): url = getvaule(configPath, "config", "apk_url") UUID = url.split("/")[-1] download_path = os.path.join(getpropath()[0], "res", "apk") file_path = os.path.join(download_path, UUID) r1 = requests.get(url, stream=True, verify=False) total_size = int(r1.headers['Content-Length']) # 删除所有本地apk缓存 os.system("rm -f " + os.path.join(download_path, "*.apk")) # 若本地本地文件已下载过,检测大小,未下载则0 if os.path.exists(file_path): temp_size = os.path.getsize(file_path) # 本地已经下载的文件大小 else: temp_size = 0 print("已存在文件大小(未存在为0)" + str(temp_size)) print("下载文件预计大小" + str(total_size)) # 核心部分,这个是请求下载时,从本地文件已经下载过的后面下载 headers = {'Range': 'bytes=%d-' % temp_size} # 重新请求网址,加入新的请求头的 r = requests.get(url, stream=True, verify=False, headers=headers) # "ab"表示追加形式写入文件 with open(file_path, "ab") as f: for chunk in r.iter_content(chunk_size=1024): if chunk: temp_size += len(chunk) f.write(chunk) f.flush() ###这是下载实现进度显示#### # done = int(50 * temp_size / total_size) # sys.stdout.write("\r[%s%s] %d%%" % ('█' * done, ' ' * (50 - done), 100 * temp_size / total_size)) # sys.stdout.flush() print() # 避免上面\r 回车符 print("下载完毕!!!")
from MyConfigParser import MyConfigParser, getvaule, setvaule system = platform.system() if system == "Windows": PerfDogService_exe_path = os.path.join(getpropath()[0], "PerfDogService", "PerfDogService.exe") else: PerfDogService_exe_path = os.path.join(getpropath()[0], "PerfDogService_Linux", "PerfDogService") q = Queue(1) adb = ADB().adb_path configPath = os.path.join(getpropath()[0], "cfg", "config.ini") build_type = getvaule(configPath, "config", "build_type") package = getvaule(configPath, "active_config", build_type) report_output_path = os.path.join(getpropath()[1], "perfdog_service_output", "AutoPerformance_Report_" + str(time.time())) personal_token = "866cdeec9743460abd3f1d7e2075300eddfeb964d481e387682361754f582b7c" def get_performance_data(pack_name, q): """ 启动PerfDogService 测试数据采集 """ try: # 在代码里启动PerfDogService或手动启动PerfDogService print("0.启动PerfDogService")
def install_apk_phone_tap(self): tap_info = getvaule(configPath, "more_input_tap", self.model).split(",") time.sleep(int(tap_info[2])) shell("input tap " + tap_info[0] + " " + tap_info[1])
def main(): values = sys.argv apk_url = values[1] url_head = "http://soft.f.xmfunny.com:8888/sausage/apk" apk_build_type = apk_url.split("_")[0] url = "" if apk_build_type == "dev": url = url_head + "/开发/" + apk_url elif apk_build_type == "first-test": url = url_head + "/先行/" + apk_url setvaule(install_config_path, "config", "apk_url", url) setvaule(cfg_config_path, "config", "build_type", apk_build_type) atx_devices = atx.get_devices_info()["devices"] devices_in_config = getvaule(cfg_config_path, "config", "devices").split(",") devices_info = [] for i in atx_devices: if i["udid"] in devices_in_config and i["owner"] == None: atx.add_device(i["udid"]) devices_info.append(i) real_devices = "" for j in devices_info: real_devices = real_devices + j["udid"] + "," real_devices = real_devices.strip(",") setvaule(cfg_config_path, "config", "real_devices", real_devices) real_devices_list = getvaule(cfg_config_path, "config", "real_devices").split(",") if system == "Windows": pass elif system == "Linux": docker_start = DockerOperation() install_container_list = {} for device in real_devices_list: container_id = docker_start.Runinstall(device) install_container_list[device] = container_id p_list = [] manager = Manager() perf_container_list = manager.dict() lock = manager.Lock() for k in install_container_list: container = docker_start.get_container( DockerID=install_container_list[k]) p = Process(target=check_is_start_per_docker, args=(k, container, docker_start, perf_container_list, lock)) p_list.append(p) for i in p_list: i.start() for i in p_list: i.join() p2_list = [] for c in perf_container_list: per_container = docker_start.get_container( DockerID=perf_container_list[c]) p = Process(target=get_per_container_end_code, args=(c, per_container)) p2_list.append(p) for i in p2_list: i.start() for i in p2_list: i.join()