def third_app_operation(self, operation, app_path): if operation.upper() != 'NONE': #self.device.install_app_from_desktop('INSTALL',app_path) # Identify whether install vlife or other apps if operation.upper().find('VLIFE') == -1: pkg_name = device_config.getValue(self.dname,'custom_third_app').split('/')[0] else: pkg_name = device_config.getValue(self.dname,'slave_service') out = self.device.find_package(pkg_name) if out.find(pkg_name) != -1: find_flag = True else: find_flag = False if operation.upper().startswith('FIRST_INSTALL'): logger.debug('Install the third party of APP') if find_flag: self.device.app_operation('CLEAR', pkg=pkg_name) self.device.install_app_from_desktop('INSTALL', app_path) if operation.upper().startswith('COVER_INSTALL'): logger.debug('Cover install the third party of APP') if not find_flag: self.device.install_app_from_desktop('INSTALL') self.device.install_app_from_desktop('COVER_INSTALL', app_path) if operation.upper().startswith('UNINSTALL'): logger.debug('Uninstall the third party of APP') if find_flag: self.device.app_operation('UNINSTALL', pkg=pkg_name)
def access_other_app(self, value): """ open some app according to package and activity name from configuration file, :param value: :return: """ if value.upper() != 'NONE': logger.debug('Step:open other app') # open app, then return back home screen if value.lower() == 'android_system_app': pkg_name = device_config.getValue(self.dname, 'android_system_app') self.device.app_operation('LAUNCH', pkg=pkg_name) logger.debug('Step: launch app ' + pkg_name) elif value.lower() == 'custom_third_app': pkg_name = device_config.getValue(self.dname, 'custom_third_app') self.device.app_operation('LAUNCH', pkg=pkg_name) logger.debug('Step: launch app ' + pkg_name) else: logger.debug('Step: skip accessing the third app') sleep(3) # return back home self.device.send_keyevent(3) sleep(1)
def __init__(self,dname): self.device = device.Device(dname) self.dname = dname self.pname = device_config.getValue(dname, 'product_type') self.pkg = device_config.getValue(dname, 'slave_service') self.func_dict = {'network': self.network_change, 'clear_app': self.clear_app, 'access_other_app': self.access_other_app, 'click_screen': self.click_screen, 'close_app': self.close_app, 'close_backend_tasks': self.close_backend_tasks, 'connect_network_trigger': self.connect_network_trigger, 'install_app': self.install_app, 'module_effective': self.module_effective, 'reboot': self.reboot_device, 'screen_on': self.screen_on, 'start_app': self.start_app, 'task_init_source': self.task_init_resource, 'unlock_screen': self.unlock_screen, 'update_para': self.update_para, 'update_date': self.update_time, 'sdcard_action': self.sdcard_action, 'third_app_operation': self.install_third_app, 'kill_process': self.kill_process, 'SrvConfig_Switch': self.set_srvcon_switch, 'SrvConfig_Push_Interval': self.set_srvcon_Interval, 'oper_startup_main': self.oper_startup_main, 'oper_module_config': self.oper_module_config}
def update_para(self, value): """ :param value: :return: """ logger.debug('Step:update parameter file ' + value) pkg_name = device_config.getValue(self.dname,'slave_service') file_path = ''.join(['/data/data/', pkg_name, '/shared_prefs/']) if value.upper() == 'PUSH_MESS_FREQ': full_name = os.path.join(file_path,'push_message.xml') out = self.device.read_file_from_device(full_name) out = out.replace('\r\n','') keyword = r'.*value="(.*)".*' content = re.compile(keyword) m = content.match(out) if m: actu_freq = m.group(1) else: actu_freq = '' expe_freq = device_config.getValue(self.dname,'push_message_frequent') if expe_freq != actu_freq: reg_str = ''.join(["'",'s/','"',actu_freq,'"/','"',expe_freq,'"/g ',"'"]) self.device.update_file_from_device(reg_str,full_name)
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 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 emulate_swipe_action(self): # get resolution of screen width,height = self.get_screen_size() unlock_style = device_config.getValue(self.uid,'unlock_style') unlock_location = device_config.getValue(self.uid,'unlock_location') if unlock_style.upper() == 'LANDSCAPE': cmd = "adb -s {0} shell input swipe {1} {2} {3} {4}".format(self.uid,int(width/5),int(height/2),int(width/5*4),int(height/2)) else: if unlock_location.upper() == 'CENTER': cmd = "adb -s {0} shell input swipe {1} {2} {3} {4}".format(self.uid,int(width/2),int(height/2),int(width/2),int(height/4)) if unlock_location.upper() == 'BOTTOM': cmd = "adb -s {0} shell input swipe {1} {2} {3} {4} {5}".format(self.uid,int(width/2),int(height/4*3),int(width/2),int(0),int(200)) self.shellPIPE(cmd) sleep(2)
def update_android_time(self, delta, interval_unit='hour'): # delta is interval time, like 1, -1 interval_num = int(delta) # get android time, then get expected time stamp cmd = "".join(["adb -s ", self.uid, " shell date +%Y%m%d.%H%M%S "]) out = self.shellPIPE(cmd) for char in ['\r', '\n']: out = out.replace(char, '') cur_time = datetime.datetime.strptime(out,'%Y%m%d.%H%M%S') if interval_unit.lower() == 'hour': expe_time = cur_time + datetime.timedelta(hours=interval_num) elif interval_unit.lower() == 'minutes': expe_time = cur_time + datetime.timedelta(minutes=interval_num) else: expe_time = cur_time + datetime.timedelta(days=interval_num) #time_stamp = time.mktime(expe_time.timetuple()) version = self.get_os_version() if version < 6: expe_time = datetime.datetime.strftime(expe_time, '%Y%m%d.%H%M%S') cmd = 'adb -s {0} shell su 0 date -s {1} '.format(self.uid,expe_time) name = device_config.getValue(self.uid,'name') if name.upper().find('VIVO') != -1: cmd = 'adb -s {0} shell date -s {1} '.format(self.uid, expe_time) else: expe_time = datetime.datetime.strftime(expe_time,'%m%d%H%M%Y.00') cmd = 'adb -s {0} shell date {1} ; am broadcast -a android.intent.action.TIME_SET'.format(self.uid,expe_time) self.shellPIPE(cmd)
def verify_module_data_pkg(uid, text): logger.debug("Step: start to compare content of data pkg") mid = device_config.getValue(uid, 'background_module_id1') exp_value = tc.get_module_info(mid) content = re.compile( r'.*<property name="file">(.*)</property><property name="u".*') match = content.match(text) act_value = {} if match: match_value = match.group(1) xmlobject = pXml.parseXml(match_value) names = xmlobject.get_elements_attribute_value('property', 'name') values = xmlobject.get_elements_attribute_value('property', 'value') act_value = dict(zip(names, values)) logger.debug("Expected values as follow") for key, value in exp_value.items(): print(key + ':' + str(value)) logger.debug(key + ':' + str(value)) logger.debug("Actual values as follow") for key, value in act_value.items(): print(key + ':' + str(value)) logger.debug(key + ':' + str(value)) # sysmmetric difference 对等差分 diff = set(act_value.items()) ^ set(exp_value.items()) if len(diff) == 0: return True else: return False
def get_test_data(): dname = sys.argv[1] prod_name = device_config.getValue(dname, 'product_type') pid = ','.join(tc.get_product_ID_byName(prod_name)) suite_list = sys.argv[2] return tc.filter_cases(suite_list, TASK_COMPONENT, pid)
def verify_wallpaper_lockscreen_id(dname, lsid, wpid): result = True build_type = device_config.getValue(dname, 'build_type') print 'Actual lockscreen_id:' + lsid print 'Actual wallpaper_id:' + wpid lsid = int(lsid) wpid = int(wpid) if build_type.upper() == 'MAGAZINE': if lsid != 0 or wpid != 0: print 'id value is not right, expected value is 0' result = False if build_type.upper() == 'THEMELOCK': if lsid == 0 or wpid != 0: print 'Excepted lockscreen_id is not 0' print 'Excepted wallpaper_id is 0' result = False if build_type.upper() == 'WALLPAPER': if lsid != 0 or wpid == 0: print 'Excepted lockscreen_id is 0' print 'Excepted wallpaper_id is not 0' result = False if build_type.upper() == 'WALLPAPER_THEMELOCK': if lsid == 0 or wpid == 0: print 'Excepted lockscreen_id is not 0' print 'Excepted wallpaper_id is not 0' result = False return result
def oper_module_config(self, value): if value.upper != 'NONE': logger.debug('Step: set operation module ' + str(value)) config_para = device_config.getValue(self.dname, 'operation_module_upgrade_current') config_dict = json.loads(config_para) exp_dict = eval(value) flag = False module_take_effect = False for key, value in exp_dict.items(): key = key.encode('utf8') value = value.encode('utf8') if key in ['b', 'c', 'so']: enabled, network, selfkill = value.split(':') flag = tc.update_operation_module(int(config_dict[key]), int(network), int(selfkill), int(enabled)) if key == 'c_rule': flag = tc.start_c_process(int(config_dict[key]),int(value)) if key == 'module': network, selfkill = value.split(':') flag = tc.update_stage_module_network(int(config_dict[key]), int(network), int(selfkill)) if flag: module_take_effect = True if module_take_effect: config_srv.enableModule('STAGECONFIG')
def run(dname, loop, rtype): global DEVICENAME, DEVICE, LogPath global LOOP_NUM, RESULT_DICT, FAIL_CASE, RUN_ID DEVICENAME = dname DEVICE = device.Device(DEVICENAME) # run test case logname = desktop.get_log_name(dname, 'TestMemory') LogPath = os.path.dirname(os.path.abspath(logname)) utest_log = os.path.join(LogPath, 'unittest.html') # ##RESULT_DICT format {casename:{Result:['PASS','PASS'],Log:['','']}}##### RESULT_DICT = {} FAIL_CASE = [] # insert run info to database dname = sys.argv[1] slist = sys.argv[2] vname = device_config.getValue(dname, 'version') RUN_ID = tc.insert_runinfo(slist, dname, vname, loop, rtype) try: for LOOP_NUM in range(loop): fileobj = file(utest_log, 'a+') if LOOP_NUM == 0 or rtype.upper() == 'ALL': suite = unittest.TestLoader().loadTestsFromTestCase( TestMemoryCPU) else: suite = unittest.TestSuite() for name in FAIL_CASE: suite.addTest(TestMemoryCPU(name)) FAIL_CASE = [] if suite.countTestCases() > 0: runner = HTMLTestRunner.HTMLTestRunner( stream=fileobj, verbosity=2, loop=LOOP_NUM, title='Test Memory&CPU Report', description='Test Result', ) runner.run(suite) fileobj.close() sleep(5) # write log to summary report if LOOP_NUM == loop - 1: desktop.summary_result(utest_log, True, RESULT_DICT) TestLinkObj.write_result_to_testlink(DEVICENAME, RESULT_DICT) else: desktop.summary_result(utest_log, False, RESULT_DICT) except Exception, ex: print ex
def filter_log_result(logname, pid_list, match_type, device_name, findstr=''): logger.debug('Step: Start to filter test log') result_dict = {} find_lines = [] if findstr.find('SLAVE_PKG_NAME') != -1: slave_service = device_config.getValue(device_name, 'slave_service') + ':main' findstr = findstr.replace('SLAVE_PKG_NAME', slave_service) expe_list = findstr.split("||") if match_type.upper() in ['MATCH']: regular_flag = True # according to pid to query log file, so will query same file multiple times for pi in pid_list: logger.debug('Filter log according to PID:' + str(pi)) result_dict[pi] = False qindex = 0 re_flag = False try: with open(logname) as reader: for line in reader: # remove redundance space line = ' '.join(filter(lambda x: x, line.split(' '))) values = line.split(' ') # values[6:] is text column text = ' '.join(values[6:]) if values[2] == str(pi): if not regular_flag: if text.find(expe_list[qindex]) != -1: print 'Find log:' + line logger.debug('Find log:' + line) find_lines.append(line) qindex += 1 else: if not re_flag: content = re.compile(expe_list[qindex]) re_flag = True match = content.match(text) if match: value = match.group(1) print 'Find log:' + line logger.debug('Find log:' + line) find_lines.append(line) qindex += 1 re_flag = False # exit loop when find all matched logs if qindex == len(expe_list): result_dict[pi] = True break except Exception, ex: logger.error(ex) continue
def set_srvcon_Interval(self,value): if int(value) != 0: logger.debug('Step: set push interval in server side:' + str(value)) rule_id = device_config.getValue(self.dname, 'background_rule_id') # update database tc.update_push_interval(rule_id, value) config_srv.enableModule('STAGECONFIG')
def module_effective(self, value): if value.upper() != 'NONE': logger.debug('Step: update database and make module effective') mid = device_config.getValue(self.dname,'background_module_id1') network, killself = value.split(':') flag = tc.update_stage_module_network(int(mid), int(network), int(killself)) if flag: config_srv.enableModule('STAGECONFIG') else: logger.debug('Data of DB is fit for test requirement')
def test_third_party_theme(self): logger.debug(u'TestCase:解锁到三方应用') self.case_id = '133' theme.set_device_theme(DEVICENAME, 'VLIFE') # access to the third party of app custom_app = device_config.getValue(DEVICENAME, 'custom_third_app') DEVICE.start_application(custom_app) sleep(2) result = self.unlock_screen() self.assertEqual(False, result) DEVICE.screenshot(self._testMethodName, self.log_path)
def set_srvcon_switch(self, value): if value.upper() != 'NONE': logger.debug('Step: set switch' + str(value)) stype, action = value.split(':') rule_id = device_config.getValue(self.dname, 'background_rule_id') # update database tc.update_switch(rule_id,stype,action) config_srv.enableModule('STAGECONFIG')
def unlock_screen(self, value): """ :param value: :return: """ unlock_type = device_config.getValue(self.dname, 'unlock_style').split('|') unlock_location = device_config.getValue(self.dname,'unlock_location').split('|') if value.upper() == 'NONE': print 'do nothing' elif len(unlock_type) != len(unlock_location): logger.warning("Unlock parameters are not right, testing stop") # just for an exception , and stop testing res = 1/0 elif value.upper() == 'DEFAULT': logger.debug('Step:unlock screen') # sometimes device start up is very slowly, so will try multiple times for i in range(5): names = self.device.get_connected_devices() if self.dname in names: self.device.screen_on_off("OFF") sleep(2) self.device.screen_on_off("ON") sleep(2) self.__unlock_by_setting(unlock_type, unlock_location) break else: sleep(5) else: # redo unlock action multiple times logger.debug('Step:unlock screen') for i in range(int(value)): self.device.screen_on_off("OFF") sleep(2) self.device.screen_on_off("ON") sleep(2) self.__unlock_by_setting(unlock_type, unlock_location) sleep(5)
def find_file_from_appfolder(self,fname): pkg = device_config.getValue(self.uid, 'slave_service') path = os.path.dirname(fname) basename = os.path.basename(fname) # find path '/data/data/pkg_name/' cmd = "".join(["adb -s ", self.uid, " shell run-as ", pkg, " ls ", path]) out = self.shellPIPE(cmd) if out.find(basename) != -1: return True else: return False
def common_init_env(dname): DEVICE = device.Device(dname) file_list = device_config.getValue(dname,'pushfile').split(';') try: for fname in file_list: orgi,dest = fname.split(':') orgi = PATH('../external/' + dname + '/' + orgi) if os.path.isfile(orgi): DEVICE.device_file_operation('push',orgi,dest) except Exception, ex: print ex print "initial environment is failed" sys.exit(0)
def oper_startup_main(self,value): if value.upper() != 'NONE': logger.debug('Step: startup main process ' + str(value)) action = device_config.getValue(self.dname, 'operation_startup_main') root_flag = device_config.getValue(self.dname, 'root_flag') if action.upper() == 'INITSOURCE_NCHANGE_REBOOT': self.task_init_resource('vlife') self._network_change_root(root_flag) # verify if module is downing config_para = device_config.getValue(self.dname, 'operation_module_upgrade_current') config_dict = json.loads(config_para) result = tc.get_all_module_info(config_dict) res = self.device.find_file_from_appfolder(result['module']['path']) if res: logger.debug('Step: module download success, file is found ' + result['module']['path']) # start to verify c, so file self.reboot_device('default') self.unlock_screen('default') logger.debug('Step: wait for 30s b downloading') sleep(30) # check if b has downloaded res = self.device.find_file_from_appfolder('databases/server.db') if res: logger.debug('Step: b download success, file is found ' + 'server.db') self.kill_process('MAIN') sleep(20) self._network_change_root(root_flag) timeout = device_config.getValue(self.dname, 'operation_timeout') logger.debug('Step: waiting for c, so files downloading about ' + timeout) sleep(int(timeout)) for key, value in config_dict.items(): if key.lower() == 'c' or key.lower() == 'so': res = self.device.find_file_from_appfolder(result[key]['cpath']) if res: logger.debug('Step: ' + key + ' download success, file is found ' + result[key]['cpath'])
def get_pid_by_vpname(dname, value): pid_list = [] master_service = device_config.getValue(dname, 'master_service') slave_service = device_config.getValue(dname, 'slave_service') + ':main' try: if value.upper().find('DOUBLE') != -1: plist = [slave_service, master_service] elif value.upper().find('SYSTEMUI') != -1: plist = [master_service] elif value.upper().find('SYSTEM') != -1: plist = ['system_server'] else: plist = [slave_service] for name in plist: pid = dumplog.DumpLogcatFileReader.get_PID(dname, name) if str(pid) > 0: pid[0] = pid[0].strip() pid_list.append(pid[0]) except Exception, ex: #print 'canot get correlative PID' return []
def install_third_app(self, operation): logger.debug('Step: install APP:' + operation) find_text = [u"好",u"安装", u"允许"] if operation.upper().find('VLIFE') == -1: app_path = PATH(PATH('../external/' + 'advhelp.apk')) else: app_name = device_config.getValue(self.dname, 'vlife_app') app_path = PATH(PATH('../external/' + app_name)) try: threads = [] install_app = threading.Thread(target=self.third_app_operation, args=(operation,app_path)) proc_process = threading.Thread(target=myuiautomator.do_popup_windows, args=(10, find_text, self.dname)) threads.append(proc_process) threads.append(install_app) for t in threads: t.setDaemon(True) t.start() sleep(2) t.join() except Exception, ex: pass
def get_log_name(device_name, basename, path_index, loop_number, shell_index, suffix='.log'): cur_date = datetime.datetime.now().strftime("%Y%m%d") now = datetime.datetime.now().strftime("%H%M") name = device_config.getValue(device_name, 'name') temp = now + basename + 'PATH' + str(path_index) + '_' + 'LOOP' + str( loop_number) + '_' + 'SHELL' + str(shell_index) parent_path = os.path.join('log', cur_date, device_name + '_' + name, temp) # create multi layer directory if not os.path.isdir(parent_path): os.makedirs(parent_path) dname = 'result' + suffix filename = os.path.join(parent_path, dname) return filename
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)
DEVICE.app_operation('LAUNCH', pkg='com.android.settings/.Settings') sleep(5) # click WLAN element = myuiautomator.Element(dname) event = myuiautomator.Event(dname) try: ele = element.findElementByName("WLAN") if ele is not None: event.touch(ele[0], ele[1]) sleep(2) except Exception,ex: print ex # click setting button setting_path = device_config.getValue(dname, 'wifi_setting').split('::') location = setting_path[0] index = int(setting_path[1]) # Whether checked nor non_checked, attribute value are both 'false' on VIVO name = device_config.getValue(dname,'name') if name.upper().find('VIVO') != -1: element = myuiautomator.Element(dname) try: ele = element.findElementByName(u"选取网络") if ele is None: state = 'false' else: state = 'true' except Exception, ex: print ex
def __init__(self, uid): self.uid = uid self.name = device_config.getValue(uid,'name')
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
def setUpClass(self): self.pkg = device_config.getValue(DEVICENAME, 'set_theme_pkg')