def run(self, cases): start_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) devices = check_devives() if not devices: print('There is no device found,test over.') return # generate test data data.json 准备测试数据 generate_test_data(devices) print('Starting Run test >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') runs = [] for i in range(len(devices)): runs.append(RunCases(devices[i])) # run on every device 开始执行测试 pool = Pool(processes=len(runs)) for run in runs: pool.apply_async(self._run_cases, args=( run, cases, )) print('Waiting for all runs done........ ') pool.close() pool.join() print('All runs done........ ') ChromeDriver.kill() # Generate statistics report 生成统计测试报告 将所有设备的报告在一个HTML中展示 create_statistics_report(runs) backup_report('./TestReport', './TestReport_History', start_time)
def run(self, cases): # 根据method 获取android设备 method = ReadConfig().get_method().strip() if method == 'SERVER': # get ATX-Server Online devices # devices = ATX_Server(ReadConfig().get_server_url()).online_devices() print('Checking available online devices from ATX-Server...') devices = get_online_devices() print('\nThere has %s alive devices in ATX-Server' % len(devices)) elif method == 'IP': # get devices from config devices list print('Checking available IP devices from config... ') devices = get_devices() print('\nThere has %s devices alive in config IP list' % len(devices)) elif method == 'USB': # get devices connected PC with USB print('Checking available USB devices connected on PC... ') devices = connect_devices() print('\nThere has %s USB devices alive ' % len(devices)) else: raise Exception('Config.ini method illegal:method =%s' % method) if not devices: print('There is no device found,test over.') return # # 测试前准备 # generate_test_data(devices) # 创建测试数据 data.js # download_apk() # 下载小影最新的apk print('Starting Run test >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') runs = [] for i in range(len(devices)): runs.append(RunCases(devices[i])) # run on every device 开始执行测试 pool = Pool(processes=len(runs)) for run in runs: pool.apply_async(self._run_cases, args=(run, cases,)) time.sleep(2) print('Waiting for all runs done........ ') pool.close() pool.join() print('All runs done........ ') ChromeDriver.kill() # Generate statistics report 生成统计测试报告 将所有设备的报告在一个HTML中展示 # apk = get_apk() # apk_info = get_apk_info(apk['apk_path']) # 获取apk信息 # title = "ApkUrl: %s<br />PackageName: %s<br /> Version: V%s<br />VersionCode: %s" % ( # apk['html'], apk_info["package"], apk_info["versionName"], apk_info["versionCode"]) # create_statistics_report(runs, title=title) create_statistics_report(runs)
def run(self, cases): # 根据method 获取android设备 method = ReadConfig().get_method().strip() if method == 'SERVER': # get ATX-Server Online devices # devices = ATX_Server(ReadConfig().get_server_url()).online_devices() print('Checking available online devices from ATX-Server...') devices = get_online_devices() print('\nThere has %s online devices in ATX-Server' % len(devices)) elif method == 'IP': # get devices from config devices list print('Checking available IP devices from config... ') devices = get_devices() print('\nThere has %s devices alive in config IP list' % len(devices)) elif method == 'USB': # get devices connected PC with USB print('Checking available USB devices connected on PC... ') devices = connect_devices() print('\nThere has %s USB devices alive ' % len(devices)) else: raise Exception('Config.ini method illegal:method =%s' % method) if not devices: print('There is no device found,test over.') return # generate test data data.json 准备测试数据 generate_test_data(devices) print('Starting Run test >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') runs = [] for i in range(len(devices)): runs.append(RunCases(devices[i])) # run on every device 开始执行测试 pool = Pool(processes=len(runs)) for run in runs: pool.apply_async(self._run_cases, args=( run, cases, )) print('Waiting for all runs done........ ') pool.close() pool.join() print('All runs done........ ') ChromeDriver.kill() # Generate statistics report 生成统计测试报告 将所有设备的报告在一个HTML中展示 create_statistics_report(runs)
def set_chromedriver(self, device_ip=None, package=None, activity=None, process=None): driver = ChromeDriver(self.d, Ports().get_ports(1)[0]). \ driver(device_ip=device_ip, package=package, attach=True, activity=activity, process=process) return driver
def run(self, cases, apk, upload=True): start_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) build_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) devices = check_devives() if not devices: print('There is no device found,test over.') return # # 测试前准备 # generate_test_data(devices) # 创建测试数据 data.js print('Starting Run test >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') runs = [] for i in range(len(devices)): runs.append(RunCases(devices[i])) # run on every device 开始执行测试 pool = Pool(processes=len(runs)) for run in runs: pool.apply_async(self._run_cases, args=( run, cases, )) time.sleep(2) print('Waiting for all runs done........ ') pool.close() time.sleep(1) pool.join() print('All runs done........ ') ChromeDriver.kill() end_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) # Generate statistics report 生成统计测试报告 将所有设备的报告在一个HTML中展示 apk_info = get_apk_info(apk['apk_path']) # 获取apk信息 title = "StartTime: %s<br />ApkUrl: %s<br />PackageName: %s<br /> Version: V%s<br />VersionCode: %s" % ( build_time, apk['html'], apk_info["package"], apk_info["versionName"], apk_info["versionCode"]) runs_info = create_statistics_report(runs, title=title) if upload: # 上传报告信息 for res in runs_info: result_tmp = {} result_tmp['device_name'] = res['name'] result_tmp['count'] = res['sum'] result_tmp['pass'] = res['pass'] result_tmp['fail'] = res['fail'] result_tmp['error'] = res['error'] result_tmp['tag'] = 'Android_' + start_time insert_ui_results(result_tmp) # 上传apk信息 task_app_info = {} task_app_info['app_name'] = '小影' task_app_info['package_name'] = apk_info["package"] task_app_info['ver_name'] = apk_info["versionName"] task_app_info['ver_code'] = apk_info["versionCode"] # # task_app_info['channel'] = apk_info['channel'] # task_app_info['appkey'] = apk_info["appkey"] task_app_info['file_name'] = apk['apk_name'] task_app_info['tag'] = 'Android_' + start_time insert_ui_apks_info(task_app_info) # 上传task信息 task_info = {} task_info['start_time'] = start_time task_info['end_time'] = end_time task_info['app_name'] = apk_info["package"] task_info['app_version'] = apk_info["versionName"] task_info['devices'] = len(runs) task_info['tag'] = 'Android_' + start_time insert_ui_tasks(task_info) # 压缩报告文件夹并上传 zipname = zip_report(start_time) upload_report_zip(zipname) else: pass
#!/usr/bin/env python # -*- coding: utf-8 -*- import time import uiautomator2 as u2 from Public.chromedriver import ChromeDriver #将chromedriver.py和该脚本放在同一目录下 from Public.BasePage import BasePage base_page = BasePage() base_page.set_driver('10.0.31.63') d = base_page.get_driver() # d.app_stop('com.github.android_app_bootstrap') # d.app_start('com.github.android_app_bootstrap') # d(text='Login').click() # d(text='Baidu').click() # time.sleep(3) driver = ChromeDriver(d).driver() driver.find_element_by_id('index-kw').click() driver.find_element_by_id('index-kw').send_keys('Python') time.sleep(3) driver.find_element_by_id('index-bn').click() driver.quit() ChromeDriver(d).windows_kill()