class TestTask(unittest.TestCase): @classmethod def setUpClass(self): self.master_service = CONFIG.getValue(DEVICENAME, 'master_service') self.slave_service = CONFIG.getValue(DEVICENAME, 'slave_service') self.slave_main_process = self.slave_service + ':main' self.omit_cases = CONFIG.getValue(DEVICENAME, 'omit_cases') self.set_theme = bool(CONFIG.getValue(DEVICENAME, 'set_theme')) self.set_theme_pkg = CONFIG.getValue(DEVICENAME, 'set_theme_pkg') def setUp(self): self.log_name = None self.log_path = None self.log_reader = None self.result = False self.log_count = 1 self.double_process = False self.proc_name = 'lockscreen' for title in self.omit_cases.split(':'): if self._testMethodName.find(title) != -1: self.skipTest('this case is not supported by this version') if LOOP_NUM != 0 and not self.set_theme: self.set_magazine_init_env() # only connect wifi DEVICE.gprs_operation('OFF') sleep(5) DEVICE.wifi_operation('ON') sleep(5) def tearDown(self): #self._outcomeForDoCleanups = result # Python 3.2, 3.3 try: if hasattr(self, '_outcome'): # Python 3.4+ result = self.defaultTestResult( ) # these 2 methods have no side effects self._feedErrorsToResult(result, self._outcome.errors) else: # Python 3.2 - 3.3 or 2.7 result = getattr(self, '_outcomeForDoCleanups', self._resultForDoCleanups) error = self.list2reason(result.errors) failure = self.list2reason(result.failures) ok = not error and not failure #Save all test result #init result dict at the first time if LOOP_NUM == 0: RESULT_DICT.setdefault(self._testMethodName, {})['Result'] = [] RESULT_DICT.setdefault(self._testMethodName, {})['Log'] = [] if ok: RESULT_DICT[self._testMethodName]['Result'].append('PASS') RESULT_DICT[self._testMethodName]['Log'].append('') else: RESULT_DICT[self._testMethodName]['Result'].append('FAILED') RESULT_DICT[self._testMethodName]['Log'].append( os.path.basename(self.log_name)) # insert into fail case list FAIL_CASE.append(self._testMethodName) except Exception, ex: print ex # # only connect wifi # DEVICE.gprs_operation('OFF') # sleep(5) # DEVICE.wifi_operation('ON') # sleep(5) if self.set_theme: #self.set_device_theme(self.set_theme_pkg, 'system') pass # close all adb to avoid 5037 port occupation desktop.close_all_program('adb') # restart adb server sleep(1) DEVICE.restart_adb_server() sleep(5)
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])
class TestStartupRegister(unittest.TestCase): @classmethod def setUpClass(self): self.master_service = CONFIG.getValue(DEVICENAME, 'master_service') self.slave_service = CONFIG.getValue(DEVICENAME, 'slave_service') self.slave_main_process = self.slave_service + ':main' self.omit_cases = CONFIG.getValue(DEVICENAME, 'omit_cases') self.set_theme = bool(CONFIG.getValue(DEVICENAME, 'set_theme')) self.set_theme_pkg = CONFIG.getValue(DEVICENAME, 'set_theme_pkg') def setUp(self): self.log_name = None self.log_path = None self.log_reader = None self.result = False self.reg_uid = '' self.filter_result = {} self.log_count = 1 self.double_process = False self.pid_uid = {} for title in self.omit_cases.split(':'): if self._testMethodName.find(title) != -1: self.skipTest('this case is not supported by this version') def tearDown(self): #self._outcomeForDoCleanups = result # Python 3.2, 3.3 try: # newname = self._testMethodName +'fail'+ '.txt' # newname = os.path.join(os.path.dirname(self.log_name),newname) # os.rename(self.log_name,newname) if hasattr(self, '_outcome'): # Python 3.4+ result = self.defaultTestResult( ) # these 2 methods have no side effects self._feedErrorsToResult(result, self._outcome.errors) else: # Python 3.2 - 3.3 or 2.7 result = getattr(self, '_outcomeForDoCleanups', self._resultForDoCleanups) error = self.list2reason(result.errors) failure = self.list2reason(result.failures) ok = not error and not failure if LOOP_NUM == 0: RESULT_DICT.setdefault(self._testMethodName, {})['Result'] = [] RESULT_DICT.setdefault(self._testMethodName, {})['Log'] = [] if ok: RESULT_DICT[self._testMethodName]['Result'].append('PASS') RESULT_DICT[self._testMethodName]['Log'].append('') else: RESULT_DICT[self._testMethodName]['Result'].append('FAILED') RESULT_DICT[self._testMethodName]['Log'].append( os.path.basename(self.log_name)) # insert into fail case list FAIL_CASE.append(self._testMethodName) except Exception, ex: print ex # make mobile theme to system theme if self.set_theme: self.set_device_theme(self.set_theme_pkg, 'system') # close all adb to avoid 5037 port occupation desktop.close_all_program('adb') # restart adb server sleep(1) DEVICE.restart_adb_server() sleep(10)
class TestModule(unittest.TestCase): @classmethod def setUpClass(self): self.slave_service = CONFIG.getValue(DEVICENAME, 'slave_service') self.slave_main_process = self.slave_service + ':main' self.omit_cases = CONFIG.getValue(DEVICENAME, 'omit_cases') def setUp(self): self.log_name = None self.log_path = None self.log_reader = None self.result = False self.log_count = 1 for title in self.omit_cases.split(':'): if self._testMethodName.find(title) != -1: LOGGER.debug(self._testMethodName + 'SKIP') self.skipTest('this case is not supported by this version') else: LOGGER.debug(self._testMethodName + 'START') # only connect wifi DEVICE.gprs_operation('OFF') sleep(5) DEVICE.wifi_operation('ON') sleep(5) def list2reason(self, exc_list): if exc_list and exc_list[-1][0] is self: return exc_list[-1][1] def tearDown(self): #self._outcomeForDoCleanups = result # Python 3.2, 3.3 try: if hasattr(self, '_outcome'): # Python 3.4+ result = self.defaultTestResult( ) # these 2 methods have no side effects self._feedErrorsToResult(result, self._outcome.errors) else: # Python 3.2 - 3.3 or 2.7 result = getattr(self, '_outcomeForDoCleanups', self._resultForDoCleanups) error = self.list2reason(result.errors) failure = self.list2reason(result.failures) ok = not error and not failure if LOOP_NUM == 0: RESULT_DICT.setdefault(self._testMethodName, {})['Result'] = [] RESULT_DICT.setdefault(self._testMethodName, {})['Log'] = [] if ok: RESULT_DICT[self._testMethodName]['Result'].append('PASS') RESULT_DICT[self._testMethodName]['Log'].append('') LOGGER.debug(self._testMethodName + ':PASS') else: RESULT_DICT[self._testMethodName]['Result'].append('FAILED') RESULT_DICT[self._testMethodName]['Log'].append( os.path.basename(self.log_name)) # insert into fail case list FAIL_CASE.append(self._testMethodName) LOGGER.debug(self._testMethodName + ':FAIL') except Exception, ex: LOGGER.error(ex) # clear self.clear_app() # close all adb to avoid 5037 port occupation desktop.close_all_program('adb') # restart adb server sleep(1) DEVICE.restart_adb_server() sleep(5)
class TestVivoBasicUI(unittest.TestCase): @classmethod def setUpClass(self): self.pkg = device_config.getValue(DEVICENAME, 'set_theme_pkg') def setUp(self): self.log_name = None self.log_path = LogPath self.log_reader = None self.result = True self.log_count = 1 self.pid = [] self.run_loop = 1 self.filter_log = {} self.case_id = None # recovery to initial state self.unlock_screen() def tearDown(self): try: if hasattr(self, '_outcome'): # Python 3.4+ result = self.defaultTestResult( ) # these 2 methods have no side effects self._feedErrorsToResult(result, self._outcome.errors) else: # Python 3.2 - 3.3 or 2.7 result = getattr(self, '_outcomeForDoCleanups', self._resultForDoCleanups) error = self.list2reason(result.errors) failure = self.list2reason(result.failures) ok = not error and not failure #Save all test result #init result dict at the first time if LOOP_NUM == 0: RESULT_DICT.setdefault(self._testMethodName, {})['Result'] = [] RESULT_DICT.setdefault(self._testMethodName, {})['Log'] = [] if ok: RESULT_DICT[self._testMethodName]['Result'].append('PASS') RESULT_DICT[self._testMethodName]['Log'].append('') tc.insert_test_result(RUN_ID, self.case_id, LOOP_NUM, 'PASS', os.path.abspath(self.log_name)) else: RESULT_DICT[self._testMethodName]['Result'].append('FAILED') RESULT_DICT[self._testMethodName]['Log'].append( os.path.basename(self.log_name)) # insert into fail case list FAIL_CASE.append(self._testMethodName) tc.insert_test_result(RUN_ID, self.case_id, LOOP_NUM, 'FAILED', os.path.abspath(self.log_name)) except Exception, ex: print ex desktop.close_all_program('adb') # restart adb server sleep(1) DEVICE.kill_server() sleep(2) DEVICE.start_server() sleep(5)
class TestTimerTask(unittest.TestCase): @classmethod 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 setUp(self): self.log_name = None self.log_path = None self.log_reader = None self.result = True self.log_count = 1 self.pid = [] self.run_loop = 1 self.filter_log = {} self.case_id = None self.testlink_id = None def tearDown(self): try: if hasattr(self, '_outcome'): # Python 3.4+ result = self.defaultTestResult() # these 2 methods have no side effects self._feedErrorsToResult(result, self._outcome.errors) else: # Python 3.2 - 3.3 or 2.7 result = getattr(self, '_outcomeForDoCleanups', self._resultForDoCleanups) error = self.list2reason(result.errors) failure = self.list2reason(result.failures) ok = not error and not failure #Save all test result #init result dict at the first time if LOOP_NUM == 0: RESULT_DICT.setdefault(self._testMethodName, {})['Result'] = [] RESULT_DICT.setdefault(self._testMethodName, {})['Log'] = [] RESULT_DICT.setdefault(self._testMethodName, {})['TLID'] = self.testlink_id if ok: RESULT_DICT[self._testMethodName]['Result'].append('PASS') RESULT_DICT[self._testMethodName]['Log'].append('') tc.insert_test_result(RUN_ID, self.case_id, LOOP_NUM, 'PASS', os.path.abspath(self.log_name)) else: RESULT_DICT[self._testMethodName]['Result'].append('FAILED') RESULT_DICT[self._testMethodName]['Log'].append(os.path.basename(self.log_name)) # insert into fail case list FAIL_CASE.append(self._testMethodName) tc.insert_test_result(RUN_ID, self.case_id, LOOP_NUM, 'FAILED', os.path.abspath(self.log_name)) except Exception,ex: print ex desktop.close_all_program('adb') # restart adb server sleep(1) DEVICE.restart_adb_server() sleep(5)