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 enableModule(config_file, sname): config_file = r'E:\AutoTestDemo\config\htmlconfig.ini' sname = 'STAGECONFIG' htmlObj = html.MyHttp(config_file, sname) url = '/clearapi.do?' # combine all parameters project = 'vlife' version = 'major' t = str(int(time.time()) * 1000) t1 = '1500878198000' component = ['interactive','adcenter'] username = '******' for comp in component: temp = '-'.join([project,comp,'paper',project,t]) md = stropt.get_md5(temp) paras = '&'.join(['component='+comp,'project='+project,'t='+t,'check='+ md, 'from='+username,'user='******'version='+version]) logger.debug('Read for enable module') res = htmlObj.get(url,paras) if json.loads(res[0]).get('result', '') == 'success': logger.info('Enable module is passed for ' + comp) else: logger.error('Enable module is not failed ' + comp)
def enableModule(sname): htmlObj = html.MyHttp(html_config, sname) url = '/clearapi.do?' # combine all parameters project = 'vlife' version = 'major' t = str(int(time.time()) * 1000) t1 = '1500878198000' # first two items for module download.'adcenter, cloud-upgrade for operation module upgrade' component = ['cm', 'adcenter', 'cloud-upgrade'] username = '******' for comp in component: temp = '-'.join([project,comp,'paper',project,t]) md = stropt.get_md5(temp) paras = '&'.join(['component='+comp,'project='+project,'t='+t,'check='+ md, 'from='+username,'user='******'version='+version]) logger.debug('Read for enable module') res = htmlObj.get(url,paras) if json.loads(res[0]).get('result', '') == 'success': logger.info('Enable module is passed for ' + comp) else: logger.error('Enable module is not failed ' + comp) # need wait for 5 minutes and enable validate on side logger.debug('Have to wait for 3 minutes server take effect') time.sleep(180)
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 update_file_from_device(self, reg_str, fname): logger.debug('Step:update parameter file' + fname) cmd = "".join( ["adb -s ", self.uid, " shell sed -i ", reg_str, " ", fname]) print cmd self.shellPIPE(cmd)
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 kill_process(self, value): logger.debug('Step: kill process:' + value) if value.upper() != 'NONE': if value.upper() == 'MAIN': pid = td.get_pid_by_vpname(self.dname,'MAIN') self.device.device_kill_pid(pid)
def install_app(self, value): """ :return: """ if value.upper() != 'NONE': logger.debug('Step:install new app ' + self.pkg) pass
def test_vlife_theme(self): logger.debug(u'TestCase: 下载并应用主题') self.case_id = '130' theme.set_device_theme(DEVICENAME, 'VLIFE') result = self.unlock_screen() self.assertEqual(False, result)
def click_screen_by_coordinate(self, x, y): logger.debug('Step:click scrren by coordinate x, y:' + str(x) + "," + str(y)) cmd = "".join( ["adb -s ", self.uid, " shell input tap ", str(x), " ", str(y)]) self.shellPIPE(cmd)
def test_vlife_system_switch(self): logger.debug(u'TestCase:不同引擎间多次切换') self.case_id = '132' theme.set_device_theme(DEVICENAME, 'VLIFE') result = self.unlock_screen() self.assertEqual(False, result) theme.set_device_theme(DEVICENAME, 'SYSTEM') result = self.unlock_screen() self.assertEqual(False, result)
def get_user_id(self,lines): res = [] for ln in lines: keyword =r'.*key:uid,value:(\d+).*' content = re.compile(keyword) m = content.match(ln) if m: logger.debug('UID is:' + str(m.group(1))) res.append(m.group(1)) return res
def clear_app(self, value): """ :return: """ if value.upper() != 'NONE': logger.debug('Step: clear app') self.device.app_operation('CLEAR', pkg=self.pkg) self.device.app_operation('CLEAR', pkg='com.android.systemui') sleep(5)
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 connect_network_trigger(self, value): logger.debug('Step: connect network by change of network status ' + value) if value.upper() != 'NONE': actions = value.split(':') self.network_change(actions[0]) self.update_time('hour-24') sleep(15) self.network_change(actions[1])
def delete_files_from_device(): # delete apk file logger.debug('step: delete old apk file') del_path = module_config.getValue('SHELL_MODULE', 'push_apk_path') del_path = os.path.join(del_path, '*.apk') device.remove(del_path) # delete so file logger.debug('step: delete old so file') del_path = module_config.getValue('SHELL_MODULE', 'push_so_path') del_path = os.path.join(del_path, 'libvlife_*.so') device.remove(del_path)
def verify_log(fname): logger.debug('Search key word in the log file') filter_text = "localVersionName != currentVersionName | random and test exception" with open(fname, 'rb') as rfile: for line in rfile: if line.find(filter_text) != -1: logger.debug('test log is found in the file ' + outfile) return True return False
def test_multiple_vlife_theme(self): logger.debug(u'TestCase: 切换不同vlife主题') self.case_id = '131' for i in range(1): # set theme1 theme.set_device_theme(DEVICENAME, 'VLIFE') result = self.unlock_screen() self.assertEqual(False, result) # set theme2 theme.set_device_theme(DEVICENAME, 'VLIFE', 1) result = self.unlock_screen() self.assertEqual(False, result)
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 test_screen_on_off_30(self): logger.debug(u'TestCase: 反复亮灭屏') theme.set_device_theme(DEVICENAME, 'VLIFE') self.case_id = '137' for i in range(30): DEVICE.send_keyevent(26) sleep(2) DEVICE.send_keyevent(26) DEVICE.screenshot(self._testMethodName, target_path=self.log_path) result = self.get_device_state() self.assertEqual(True, result) # recovery to initial state self.unlock_screen()
def test_unlock_30(self): logger.debug(u'TestCase: 反复亮灭屏解锁') theme.set_device_theme(DEVICENAME, 'VLIFE') self.case_id = '138' for i in range(30): if DEVICE.get_lock_screen_state(): DEVICE.send_keyevent(26) sleep(1) DEVICE.send_keyevent(26) else: DEVICE.send_keyevent(26) result = self.unlock_screen() self.assertEqual(False, result)
def reboot_device(self, value): """ :return: """ if value.upper() != 'NONE': logger.debug('Step:reboot device') self.device.device_reboot() sleep(30) findstr = [u'开启', u'安装', u'允许', u'确定'] myuiautomator.do_popup_windows(6, findstr, self.dname) else: logger.debug('Step: do nothing for reboot')
def start_app(self, value): """ :return: """ if value.upper() != 'NONE': logger.debug('Step:start_app') if self.pname.upper() == 'MAGAZINE': self.device.app_operation('START', pkg=self.pkg) sleep(5) elif self.pname.upper() == 'THEME': theme.set_device_theme(self.dname, 'vlife') elif self.pname.upper() == 'WALLPAPER': pass else: pass
def test_dropdown_notification_recovery(self): logger.debug(u'TestCase:下拉通知栏可复原') self.case_id = '134' theme.set_device_theme(DEVICENAME, 'VLIFE') result = self.unlock_screen() self.assertEqual(False, result) width, height = DEVICE.get_screen_normal_size() DEVICE.shell('input swipe {0} {1} {2} {3} 200'.format( int(width) / 2, 50, int(width) / 2, int(height) / 2)) sleep(2) DEVICE.send_keyevent(26) sleep(2) result = self.unlock_screen() self.assertEqual(False, result)
def verify_excepted_number(value_list, vp_type_name, expected, dtype): result = True # verify memory if dtype.upper() == 'MEMORY': # get average value and compare result avg_value = int(sum(value_list) / len(value_list)) logger.debug('Expected Memory Value:' + str(expected)) print 'Excepted Memory Value:' + str(expected) logger.debug('Actual Memory Value:' + str(avg_value)) print 'Actual Memory Value:' + str(avg_value) if vp_type_name.upper() == 'LESSTHAN': if avg_value > int(expected): result = False elif vp_type_name.upper() == 'GREATERTHAN': if avg_value < int(expected): result = False else: result = False # verify cpu # There is five group data,,[[avg,max,last],[avg1,max1,last1]......] if dtype.upper() == 'CPU': val2 = [] last_value = 0 for val in value_list: temp = val[0] # avg value change range 5% if abs(val[0] - temp) > 0.05: result = False val2.append(val[1]) last_value = last_value + val[2] if result: max_value = max(val2) if last_value != 0 or max_value > float(expected): result = False logger.debug('Expected CPU Value:' + str(expected)) print 'Excepted CPU Value:' + str(expected) logger.debug('Actual Max CPU Value:' + str(max_value)) print 'Actual Max CPU Value:' + str(max_value) logger.debug('Actual last CPU Value:' + str(last_value)) print 'Actual last CPU Value:' + str(last_value) return result
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 screen_on(self, value): """ make screen lighten or off :return: """ value = value.encode('gbk') if value.upper != 'NONE': logger.debug('Step:screen ' + value) temp = value.split(':') if len(temp) > 1: loop = int(temp[1]) else: loop = 1 for i in range(loop): for vl in temp[0].split('-'): self.device.screen_on_off(vl) sleep(3)