def testing(self, com): testcases = TestCasesRead.getTestCase(self) for case in testcases: com_port = COMTest._opencom(com) result = COMTest.send_AT_and_Result(self, com_port, case) COMTest.close_port(com_port) yield '{0} : {1}\n{2}'.format(case, TimeUtils.strTime(), result)
def case_set_time_format(self): self.case_if_base(True) time.sleep(0.5) self.test.find_byacc(filemanager_root_menu).click() time.sleep(0.5) self.test.find_byid(filemanager_settings).click() self.Case.assertTrue( self.test.wait_if_activity(filemanager_settings_acivity), '未打开设置界面') time.sleep(1) tmp_list = self.test.find_list_byid(ID_title, '常规设置').click() time.sleep(1) t = '' for x in range(3): tmp = self._get_setting_menu('日期格式') tmp.click() time.sleep(0.5) if x == 0: t = '系统指定' elif x == 1: t = '日/月/年' else: t = '年-月-日' self.test.find_byclass(CheckedTextView, t).click() time.sleep(0.5) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) test_time = TimeUtils.strDATEName() tmp = self.test.find_list_byid(filemanager_item_sub_summary, test_time) self.Case.assertIsNotNone(tmp, '时间非 [年-月-日] 格式') time.sleep(1)
def case_music_add_play_list(self): time_name = TimeUtils.str_HMS_Name() self.case_if_music_base(True) time.sleep(1) if self.test.find_byclass(TextView, '歌曲', isText=True) is None: self.test.find_byacc(music_video_music_menu).click() time.sleep(0.2) self.test.find_list_byid(music_video_music_menu_title, '歌曲').click() time.sleep(1) tmp_list = self.test.find_byid_list(music_video_music_indicator_list) tmp_int = random.randint(2, len(tmp_list) - 2) tmp_list[tmp_int].click() time.sleep(0.5) self.test.find_list_byid(ID_title, '添加到播放列表').click() time.sleep(0.5) self.test.find_list_byid(ID_title, '新建播放列表').click() time.sleep(0.5) tmp_el = self.test.find_byid(music_video_music_playlist_edit) tmp_el.clear() tmp_el.send_keys(f'list_{time_name}') self.test.find_byid(music_video_music_create_playlist).click() if self.test.if_toast_text('歌曲已添加到播放列表') is None: log('error', '添加到 收藏,未找到 toast') self.test.find_byacc(music_video_music_menu).click() time.sleep(1) self.test.find_list_byid(music_video_music_menu_title, '播放列表').click() time.sleep(1) self._checK_play_list(f'list_{time_name}').click() time.sleep(1) tmp = self.test.find_byclass(TextView, 'music_') if tmp is None: self.Case.fail('列表中没有音乐 {music_}')
def case_check_date_time(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('时钟').click() time.sleep(0.5) time_test = TimeUtils.str_A_P_M_time() tmp_time = self.test.find_byid(clock_show_time).text tmp_date = self.test.find_byid(clock_show_data).text if tmp_time not in time_test: self.Case.fail( f'失败,请检查是否与北京时间相差过大,若差1分钟则不是问题,手机时间 : {tmp_time},当前时间 : {time_test}' ) if tmp_date not in TimeUtils.str_date_week(): self.Case.fail( f'失败,请检查是否与北京时间相差过大,手机日期 : {tmp_date},当前日期 : {TimeUtils.str_date_week()}' )
def case_Camera_A_test_take_a_picture(self): time_start = int(TimeUtils.str_HMS_Name()) - 10 self.caseMethod.case_take_a_picture() self.driver.terminate_app(cam_Pkg) time.sleep(3) tmp_time = self.gallery_method.case_get_picture_date() if tmp_time < time_start: self.fail('照片时间小于当前时间,测试fail,请检查设备时间是否为北京时间') self.driver.terminate_app(gallery_Pkg)
def case_Camera_A_test_take_a_video(self): time_start = int(TimeUtils.str_HMS_Name()) - 10 self.caseMethod.case_take_a_video() self.driver.terminate_app(cam_Pkg) time.sleep(2) tmp_name = self.gallery_method.case_get_title() if "VID" not in tmp_name: self.fail('fail,图库最新资料非视频') tmp_time = int(tmp_name.split('_')[2]) if tmp_time < time_start: self.fail('视频时间小于当前时间,测试fail,请检查设备时间是否为北京时间') self.driver.terminate_app(gallery_Pkg)
def com_log(com, dev='Null', logname=None): """ 串口log """ com_port = COMTest._opencom(com) if logname is None: logname = '{0}/log/{1}-{2}'.format(Utils.get_sys_path(), dev, TimeUtils.strTimeName()) while True: result = COMTest._wait_Result(com_port) v = Python_version() if v > 3.0: print(result, end='') else: print(result), result = re.sub(r'\n', '', result) logname_new = '{0}-com_log.log'.format(logname) size = Utils.get_FileSize(logname_new) if size > 2.00: logname = '{0}/log/{1}-{2}'.format(Utils.get_sys_path(), dev, TimeUtils.strTimeName()) logname_new = '{0}-com_log.log'.format(logname) Utils.saveTxtFile(logname_new, data=result)
def dmesg(dev='Null', logname=None, logon=False): """ dmesg log """ result, out = Utils.adbshell(dev, "dmesg", logon) if logname is None: logname = '{0}/log/{1}-{2}-dmesg.log'.format( Utils.get_sys_path(), dev, TimeUtils.strTimeName()) if result == 0: v = Python_version() if v > 3.0: Utils.saveTxtFile(logname, data=out) else: Utils.saveTxtFile(logname, data=out) return result, out
def Find_newest_log(): if not os.path.exists(f'{Utils.get_sys_path()}\Log'): os.mkdir(f'{Utils.get_sys_path()}\Log') if not os.path.exists(f'{Utils.get_sys_path()}\Logcat'): os.mkdir(f'{Utils.get_sys_path()}\Logcat') dir = r'{0}\Log'.format(Utils.get_sys_path()) lists = os.listdir(dir) if len(lists) == 0: p = r'{0}\Log\RunTestLog-{1}.log'.format(Utils.get_sys_path(), TimeUtils.strTimeName()) with open(p, mode='w+') as f: f.write(p) return p lists.sort(key=lambda fn: os.path.getmtime(dir + "\\" + fn)) # 按时间排序 file_new = os.path.join(dir, lists[-1]) return file_new
def logcat_and_dmesg(dev='Null', logname=None, logon=False): """ logcat 和 dmesg log """ if logname is None: logname = '{0}/log/{1}-{2}'.format(Utils.get_sys_path(), dev, TimeUtils.strTimeName()) result_dmesg, out_dmesg = Utils.adbshell(dev, "dmesg", logon) result_logcat, out_logcat = Utils.adbshell(dev, "logcat -d -v time", logon) if result_dmesg == 0: Utils.saveTxtFile('{0}-dmesg.log'.format(logname), data=out_dmesg) if result_logcat == 0: Utils.saveTxtFile('{0}-logcat.log'.format(logname), data=out_logcat) return result_dmesg, out_dmesg, result_logcat, out_logcat
def TestResultSummary(devices='1234567', version='v01', sum=0, Pass=0, fail=0, skip=0): # TODO 测试报告总结界面 TestResultSummary global fileName try: wb = load_workbook(fileName) sh = wb.create_sheet("TestResultSummary",0) sh.merge_cells('B2:F2') sh.merge_cells('E3:F3') sh.merge_cells('C4:F4') sh.cell(2, 2).alignment = Alignment(horizontal='center', vertical='center') REPORT = Font(name=u'微软雅黑', bold=True, size=20) sh['B2'].font = REPORT sh['B2'] = 'TEST REPORT' sh['B3'] = 'DEVICE ID' sh['C3'] = devices sh['D3'] = 'TEST DATE' sh['E3'] = TimeUtils.strDATEName() sh['B4'] = 'VERSION' sh['C4'] = version sh['B5'] = 'SUM' sh['C5'] = 'PASS' sh['D5'] = 'FAIL' sh['E5'] = 'SKIP' sh['F5'] = 'OTHER' sh['B6'] = sum sh['C6'] = Pass sh['D6'] = fail sh['E6'] = skip sh['F6'] = (sum - Pass - fail - skip) border_set = Border(left=Side(style='dashed', color=colors.BLACK), right=Side(style='dashed', color=colors.BLACK), top=Side(style='dashed', color=colors.BLACK), bottom=Side(style='dashed', color=colors.BLACK)) for x in range(5): for y in range(5): sh.cell(x+2, y+2).border = border_set wb.save(fileName) wb.close() except IOError as err: log('ERROR',f'TestResultSummary : {err}')
async def seek(self, ctx, timestamp): '''Advance the stream to the specified second Example: `-seek 70` (70 seconds) or` -seek 1m:20s` (1 minute 20 seconds) o `-seek 1h:10m:10s` (1 hour 10 minutes 10 seconds) ''' playing_state = self.client.voice.get_playing_state(ctx) if isinstance(playing_state, Stream): try: second = int(timestamp) await self.client.voice.seek(ctx, second) await ctx.processing_command_reaction() except ValueError: # incase it has the readable format try: seconds = TimeUtils.parse_readable_format(timestamp) await self.client.voice.seek(ctx, seconds) await ctx.processing_command_reaction() except NotValidSongTimestamp: await ctx.send( "Invalid format, use something like `10m:50s o 1h:20m:20s o 20s`" ) except Exception as e: logging.warning(str(e), exc_info=True) await ctx.send("No pes")
def log(loglevel, logcontent): #创建一个logger logger = logging.getLogger() logger.setLevel(logging.DEBUG) # Log等级总开关 #logname = r'{0}\Log\RunTestLog-{1}.log'.format(get_sys_path(), TimeUtils.strTimeName()) logname = Find_newest_log() if Utils.get_FileSize(logname) > 4.0: logname = r'{0}\Log\RunTestLog-{1}.log'.format(Utils.get_sys_path(), TimeUtils.strTimeName()) fh = logging.FileHandler(logname) fh.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) formatter = logging.Formatter( "%(asctime)s-[MEIG]-%(levelname)s: %(message)s") fh.setFormatter(formatter) ch.setFormatter(formatter) #将logger添加到handler里面 logger.addHandler(fh) logger.addHandler(ch) loglevel = loglevel.lower() if loglevel == "info": logger.info(logcontent) logger.removeHandler(fh) logger.removeHandler(ch) elif loglevel == "error": logger.error(logcontent) logger.removeHandler(fh) logger.removeHandler(ch) elif loglevel == "warning": logger.warning(logcontent) logger.removeHandler(fh) logger.removeHandler(ch) else: logger.debug(logcontent) logger.removeHandler(fh) logger.removeHandler(ch)
def case_set_alarm(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) time.sleep(1) self.test.find_byacc('闹钟').click() time.sleep(0.5) self.test.find_byacc('展开闹钟').click() time.sleep(1) self.test.find_byid(clock_del_alarm).click() time.sleep(0.2) self.test.find_byacc('展开闹钟').click() time.sleep(0.2) for text_acc in ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']: tmp = self.test.find_byacc(text_acc) if tmp.get_attribute('checked') == 'false': tmp.click() time.sleep(0.2) time.sleep(0.2) self.test.find_byid_list(clock_show_time)[0].click() time.sleep(0.5) if self.test.find_byid(clock_set_time_simulation) is None: self.Case.fail(f'设定闹钟的 模拟时钟 刻度盘未显示') if TimeUtils.is_AM(): self.test.find_byid(clock_set_time_am).click() else: self.test.find_byid(clock_set_time_pm).click() self.test.find_byid(clock_set_time_mode).click() time.sleep(0.2) self.test.find_byid(clock_set_time_hour).send_keys( TimeUtils.get_hour()) self.test.find_byid(clock_set_time_minute).send_keys( TimeUtils.get_minute() + 2) self.test.find_byclass(Button, '确定').click() isFlga = False actions = TouchAction(self.driver) for x in range(122): actions.press(x=(self.test.get_windows_width() * 0.5), y=(self.test.get_windows_height() * 0.15)).release().perform() tmp = self.test.find_byid(clock_set_alarm_state) if tmp is not None: locat = tmp.location actions.long_press(x=locat['x'], y=locat['y']) actions.move_to(x=(self.test.get_windows_width() * 0.9), y=locat['y']) actions.release().perform() isFlga = True break time.sleep(1) self.driver.press_keycode(4, 0, 0) if not isFlga: self.Case.fail(f'闹钟在2分钟内未响,测试失败') self.Case.assertTrue(self.test.wait_if_activity(clock_activity), '闹钟 关闭 失败,超时5秒未检测到主界面') time.sleep(1)
def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey self.new_name = TimeUtils.str_HMS_Name()
sh['E6'] = skip sh['F6'] = (sum - Pass - fail - skip) border_set = Border(left=Side(style='dashed', color=colors.BLACK), right=Side(style='dashed', color=colors.BLACK), top=Side(style='dashed', color=colors.BLACK), bottom=Side(style='dashed', color=colors.BLACK)) for x in range(5): for y in range(5): sh.cell(x+2, y+2).border = border_set wb.save(fileName) wb.close() except IOError as err: log('ERROR',f'TestResultSummary : {err}') def bug_report(self, case='test001', log='*****', result='pass', id=2): if 'ID' not in self.TestCasesRead(): self.TestResultWrite(cells='A1',text='ID') self.TestResultWrite(cells='B1', text='CASE NAME') self.TestResultWrite(cells='C1', text='LOG REPORT') self.TestResultWrite(cells='D1', text='TEST RESULT') self.TestResultWrite(cells='E1', text='TEST TIME') self.TestResultWrite(cells=f'A{id+1}', text=str(id)) self.TestResultWrite(cells=f'B{id+1}', text=case) self.TestResultWrite(cells=f'C{id+1}', text=log) self.TestResultWrite(cells=f'D{id+1}', text=result) self.TestResultWrite(cells=f'E{id+1}', text=TimeUtils.strTime())
__author__ = "sun hai lang" __date__ = "2019-12-23" import requests import ssl import urllib3 from Utils.TimeUtils import TimeUtils # don't show warning information urllib3.disable_warnings() ssl._create_default_https_context = ssl._create_unverified_context requestUtils = requests.Session() # show TimeUtils timeUtils = TimeUtils() # app config db path appPath = 'Resources/app.json' # button image path btnImagePath = 'Resources\\Art\\ButtonImage\\{}' # login check code position m_loginAnswer = { '0': (31, 35), '1': (116, 46), '2': (191, 24), '3': (243, 50), '4': (22, 114), '5': (117, 94), '6': (167, 120), '7': (251, 105)
def parse_duration(duration: int): return TimeUtils.parse_seconds(duration)