def tear_down(self, loop_num, data_type): self.launch.stop() if self.robot.get_lock_screen_state(): # unlock screen myaction = action.DeviceAction(self.uid) myaction.unlock_screen('DEFAULT') value = common_tear_down(self.launch.result_path, loop_num, data_type) self.result.append(value)
def setUpClass(self): self.master_service = device_config.getValue(DEVICENAME,'master_service') self.slave_service = device_config.getValue(DEVICENAME,'slave_service') self.slave_main_process = self.slave_service + ':main' self.set_env_flag = False # get network business order self.device_action = action.DeviceAction(DEVICENAME)
def setUpClass(self): self.master_service = device_config.getValue(DEVICENAME, 'master_service') self.version = device_config.getValue(DEVICENAME, 'version') self.device_action = action.DeviceAction(DEVICENAME) self.action_loop = int( device_config.getValue(DEVICENAME, 'performance_monitor_loop'))
def unlock_screen(self): # screen off/on if not DEVICE.get_display_state(): DEVICE.send_keyevent(26) DEVICE.screenshot(self._testMethodName, target_path=self.log_path) # unlock device_action = action.DeviceAction(DEVICENAME) device_action.unlock_screen('default') result = DEVICE.get_lock_screen_state() return result
def test(self): try: for i in range(10): self.robot.send_keyevent(26) sleep(1) myaction = action.DeviceAction(self.uid) myaction.unlock_screen('DEFAULT') self.robot.send_keyevent(26) state = self.robot.get_display_state() if not state: self.robot.send_keyevent(26) except Exception, ex: print ex
def set_up(self): # set vlife theme theme.set_device_theme(self.uid, 'VLIFE') state = self.robot.get_display_state() if state: self.robot.send_keyevent(26) sleep(30) # screen on and unlock screen myaction = action.DeviceAction(self.uid) myaction.unlock_screen('DEFAULT') sleep(1) self.launch.start()
def test(self): try: super(TestMemoryLeak, self).test() # screen on/off for i in range(2): state = self.robot.get_display_state() if not state: self.robot.send_keyevent(26) # unlock screen myaction = action.DeviceAction(self.uid) myaction.unlock_screen('DEFAULT') # screen off self.robot.send_keyevent(26) sleep(1) except Exception, ex: print ex
def set_up(self): # set vlife theme theme.set_device_theme(self.uid, self.name) self.robot.reboot() sleep(20) # screen on/off state = self.robot.get_display_state() if not state: self.robot.send_keyevent(26) # unlock screen myaction = action.DeviceAction(self.uid) myaction.unlock_screen('DEFAULT') sleep(10) # clear background app self.launch.start()
def collect_log(uid, path_index, loop_number, shell_index=0): da = action.DeviceAction(uid) logger.debug('Reboot device and unlock screen') da.reboot_device('default') da.unlock_screen('default') # get root device.adb('root') device.adb('remount') # start collect log name = get_log_name(uid, 'ShellModuleUpdate', path_index, loop_number, shell_index) log_reader = dumplog.DumpLogcatFileReader(name, uid) log_reader.clear_logcat() log_reader.start() logger.debug('step: connect network and download module') for i in range(2): da.connect_network_trigger('CLOSE_ALL:ONLY_WIFI') sleep(10) log_reader.stop() return name
def init_module_version(uid, orig_path, path_index, loop_number): shell_paths = module_config.getValue('SHELL_MODULE', 'upgrade_shell_path').split(';') result_list = [] count = 0 for new_shell in shell_paths: logger.debug('***key step****: upgrade to ' + new_shell) test_result = True new_shell_index = shell_paths.index(new_shell) + 1 # get root device.adb('root') device.adb('remount') # delete files delete_files_from_device() # clear app pkg_name = module_config.getValue('SHELL_MODULE', 'pkg_name') logger.debug('step: clear pkg content ' + pkg_name) device.clear_app_data(pkg_name) logger.debug('step: clear system ui') device.clear_app_data('com.android.systemui') device.uninstall(pkg_name) # push new api file apk_path = module_config.getValue('SHELL_MODULE', 'push_apk_path') so_path = module_config.getValue('SHELL_MODULE', 'push_so_path') logger.debug('step: push apk file to device') files = get_full_name(orig_path, '.apk') device.push(files[0], apk_path) desktop_path = os.path.join(orig_path, 'so') files = get_full_name(desktop_path, '.so') logger.debug('step: push so files to device') for fl in files: device.push(fl, so_path) ######################################################################### # # reboot and unlock screen da = action.DeviceAction(uid) logger.debug('step: reboot device and unlock screen') da.reboot_device('default') da.unlock_screen('default') # set root permission before reboot device.adb('root') device.adb('remount') # push .xml file to /data/data/com.vlife.vivo.wallpaper/shared_prefs# device.push('/home/lang/testfile/function.xml', '/data/data/com.vlife.vivo.wallpaper/shared_prefs') # self-activation pkg_name = module_config.getValue('SHELL_MODULE', 'pkg_name') acti_flag = module_config.getValue('SHELL_MODULE', 'self_activation') product_type = device_config.getValue(uid, 'product_type') if acti_flag.upper() == 'FALSE': logger.debug('step: access to vlife theme, start-up main process') if product_type.upper() == 'THEME': theme.set_device_theme(uid, 'vlife') # configure server option mid = module_config.getValue('SHELL_MODULE', 'module_id') try: logger.debug('step: config server and enable module ') tc.update_stage_module_status(int(mid), True) flag1 = tc.update_stage_module_network(int(mid), 1, 0) flag2 = tc.check_amount_limit(int(mid)) if flag1 or flag2: config_srv.enableModule('STAGECONFIG') logger.debug('step: set date to after two months') da.update_time('DAYS-61') da.unlock_screen('default') #connect network and waiting for module download logger.debug('step: connect network and download module') for i in range(2): da.connect_network_trigger('CLOSE_ALL:ONLY_WIFI') #check module has download config_dict = {"module": mid} result = tc.get_all_module_info(config_dict) search_path = result['module']['path'] soft_version = result['module']['version'] full_path = os.path.join(r'/data/data/', pkg_name, os.path.dirname(search_path)).replace( '\\', '/') base_name = os.path.basename(search_path) res = device.find_file_from_appfolder(pkg_name, full_path) if res.find(base_name) != -1: logger.debug( '***key step***: module is download successfully, ' + search_path + ' has found') # reboot and unlock screen for applying module name = collect_log(uid, path_index, loop_number) # get pid of app pkg_process = pkg_name + ':main' pkg_pid = device.get_pid(pkg_process) #check log for login package and verify if module update loginfo = filter_log_result(name, 'jabber:iq:auth', pkg_pid) init_result = verify_pkg_content(loginfo, soft_version) if init_result: logger.debug('***key step***: module is made effect for ' + str(mid)) # test basic func sid = module_config.getValue('COMMON', 'basic_fun_suite_id') cmd = ' '.join(['run', uid, str(sid)]) if count == 0: logger.debug( '***key step***: start to run basic test cases') subprocess.call(cmd, shell=True, stdout=None) # test new shell for upgrade result = install_new_shell(new_shell, pkg_name, soft_version, uid, path_index, loop_number, new_shell_index) if result: logger.debug( '***key step***:Install new shell is success for SHELL' + str(new_shell_index)) else: logger.error( '***key step***:Install new shell is failed. login package is not right for SHELL' + str(new_shell_index)) test_result = False else: logger.error( '***key step***:Login package content is not right, made effect is failed' ) test_result = False else: logger.error( '***key step***: module is not downloaded successfully') test_result = False except Exception, ex: print ex test_result = False count += 1 result_list.append(test_result)
def run(uid, device, loop_number, loop_unit): log_path = desktop.get_log_path(uid, 'advertise_test') valid_count = 1 output = device.shell( 'ls -l /data/data/com.vlife.vivo.wallpaper/files/ua/log/f7235a61fd.dat' ).readlines()[0].split(' ') logger.debug('*****file size:******' + output[12]) for i in range(loop_number): value = False logger.debug('loop number:' + str(i)) # restart adb every 3 times desktop.close_all_program('adb') # restart adb server sleep(1) device.adb('kill-server') sleep(5) device.adb('start-server') sleep(5) display_state = device.get_display_state() if not display_state: da = action.DeviceAction(uid) da.unlock_screen('default') sleep(1) # change wifi every 5 times if i % 5 == 0: logger.debug('close_open wifi') #da.connect_network_trigger('CLOSE_ALL:ONLY_WIFI') device.shell('svc wifi disable') sleep(2) device.shell('svc wifi enable') sleep(3) logger.debug('clear UC app') device.clear_app_data('com.UCMobile') logger.debug('waiting time for 20s') sleep(20) logger.debug('log in application') # access to app and screenshot device.start_application('com.UCMobile/com.uc.browser.InnerUCMobile') sleep(4) fname = device.screenshot('loop_' + str(i) + '_', os.path.abspath(log_path)) screenshot_full_path = os.path.join(os.path.abspath(log_path), fname + '.png') logger.debug('verify if pop-up advertisement') crop_name = os.path.join(os.path.abspath(log_path), 'crop' + str(i) + '.png') imagemagick.crop_image(screenshot_full_path, 100, 100, 1224, 320, crop_name) value = imagemagick.compare_image(crop_name, r'E:/crop_expected.png') if value: valid_count += 1 if valid_count > 160: break logger.debug('Advertisement is pop-up successful') # x1, y1 = get_circle_location(valid_count) # device.shell('input tap {0} {1}'.format(x1, y1)) # sleep(1) index = 0 if int(valid_count / loop_number) == 0: index = 0 if int(valid_count / loop_unit) + 1 > ( valid_count / loop_unit) >= int(valid_count / loop_unit): index = int(valid_count / loop_unit) triangle = [[[0, 95], [180, 95], [0, 2560]], [[180, 2560], [180, 95], [0, 2560]], [[180, 95], [220, 550], [1230, 550]], [[180, 95], [1230, 95], [1230, 550]], [[1230, 95], [1230, 2560], [1440, 2560]], [[1230, 95], [1440, 95], [1440, 2560]], [[210, 2050], [210, 2560], [1220, 2560]], [[210, 2050], [210, 2560], [1220, 2560]]] x1, y1 = get_point(triangle[index]) x = x1[valid_count] y = y1[valid_count] logger.debug('click x1,y1' + str(x) + ',' + str(y)) device.shell('input tap {0} {1}'.format(x, y)) sleep(1) else: logger.debug('Advertisement is not pop-up') if valid_count % loop_unit == 0: logger.debug('*****valid_count=*******' + str(valid_count)) output = device.shell( 'ls -l /data/data/com.vlife.vivo.wallpaper/files/ua/log/f7235a61fd.dat' ).readlines()[0].split(' ') logger.debug('*****file size:*****' + output[12])
def init_module_version(uid, test_path): init_result = False # # delete old apk file # logger.debug('step: delete old apk file') # del_path = module_config.getValue(test_path, 'device_delete_apk_path') # logger.debug('step: delete old apk file from ' + del_path) # del_path = os.path.join(del_path, '*.apk') # device.remove(del_path) # # # clear app # pkg_name = module_config.getValue(test_path, 'pkg_name') # logger.debug('step: clear pkg content ' + pkg_name) # device.clear_app_data(pkg_name) # logger.debug('step: clear system ui') # device.clear_app_data('com.android.systemui') # # # push new api file # source = module_config.getValue(test_path, 'push_orig_path') # target = module_config.getValue(test_path, 'push_dest_path') # logger.debug('step: push apk file to device') # device.push(source, target) ######################################################################### # # reboot and unlock screen da = action.DeviceAction(uid) logger.debug('step: reboot device and unlock screen') da.reboot_device('default') da.unlock_screen('default') # self-activation pkg_name = module_config.getValue(test_path, 'pkg_name') acti_flag = module_config.getValue(test_path, 'self_activation') product_type = device_config.getValue(uid, 'product_type') if acti_flag.upper() == 'FALSE': logger.debug('step: access to vlife theme, start-up main process') if product_type.upper() == 'THEME': theme.set_device_theme(uid, 'vlife') # configure server option mid_list = module_config.getValue(test_path, 'module_upgrade_path').split(';') count = 0 try: for mid in mid_list: logger.debug('step: config server and enable module ') tc.update_stage_module_status(int(mid), True) flag1 = tc.update_stage_module_network(int(mid), 1, 0) flag2 = tc.check_amount_limit(int(mid)) if flag1 or flag2: config_srv.enableModule('STAGECONFIG') #connect network and waiting for module download logger.debug('step: connect network and download module') for i in range(2): da.connect_network_trigger('CLOSE_ALL:ONLY_WIFI') #check module has download config_dict = {"module": mid} result = tc.get_all_module_info(config_dict) search_path = result['module']['path'] soft_version = result['module']['version'] full_path = os.path.join(r'/data/data/', pkg_name, os.path.dirname(search_path)).replace( '\\', '/') base_name = os.path.basename(search_path) res = device.find_file_from_appfolder(pkg_name, full_path) if res.find(base_name) != -1: logger.debug('step: module is download successfully, ' + search_path + ' has found') # reboot and unlock screen for applying module logger.debug('step: reboot device') da.reboot_device('default') da.unlock_screen('default') # start collect log name = desktop.get_log_name(uid, 'SmokeModule') #LogPath = os.path.dirname(os.path.abspath(name)) log_reader = dumplog.DumpLogcatFileReader(name, uid) log_reader.clear_logcat() log_reader.start() #connect network and waiting for module download logger.debug('step: connect network and download module') for i in range(2): da.connect_network_trigger('CLOSE_ALL:ONLY_WIFI') sleep(10) log_reader.stop() # get pid of app pkg_pid = device.get_pid(pkg_name) #check log for login package and verify if module update loginfo = filter_log_result(name, 'jabber:iq:auth', pkg_pid) init_result = verify_pkg_content(loginfo, soft_version) if init_result: logger.debug('step: module is made effect for ' + str(mid)) if count == len(mid_list) - 2: sid = module_config.getValue('COMMON', 'basic_fun_suite_id') cmd = ' '.join(['run', uid, str(sid)]) subprocess.Popen(cmd, shell=True, stdout=None) # test new module for upgrade device_config.setValue(uid, 'background_module_id1', mid_list[count + 1]) sid = module_config.getValue('COMMON', 'upgrade_fun_suite_id') cmd = ' '.join(['run', uid, str(sid)]) subprocess.call(cmd, shell=True, stdout=None) break count += 1 else: logger.error('step: module is not made effect for ' + str(mid)) break else: logger.error('step: module is not downloaded successfully') break except Exception, ex: print ex
newParser = argparse.ArgumentParser() newParser.add_argument("uid", help="Your device uid") newParser.add_argument("-p", dest="pkg", type=str, help="package name") newParser.add_argument("-o", dest="out", type=str, help="output file name") args = newParser.parse_args() uid = args.uid pkg = args.pkg out = args.out if uid is None or out is None or pkg is None: sys.exit(0) Found = False my_device = adbtools.AdbTools(uid) my_action = action.DeviceAction(uid) #pid = my_device.get_pid(pkg) cmd = 'adb logcat -b main -b system -v threadtime' for i in range(3): temp = os.path.splitext(out) outfile = ''.join([temp[0], '_', str(i), temp[1]]) logger.debug('Loop Number:' + str(i)) logger.debug('Start to grasp the log') log_reader = DumpLogcat(outfile, uid, cmd) log_reader.start() ######verify main process # my_action.network_change('CLOSE_ALL') # sleep(1)