def get_widget_menu(driver,key='微件'): test = Action(driver) touchAction = TouchAction(driver) windows_height = test.get_windows_height() windows_width = test.get_windows_width() for x in range(4): if x == 0: xx = windows_width/3 yy = windows_height/3 elif x == 1: xx = windows_width / 3 yy = windows_height * 2 / 3 elif x == 2: xx = windows_width * 2 / 3 yy = windows_height * 2 / 3 else: xx = windows_width * 2 / 3 yy = windows_height / 3 touchAction.long_press(x=xx ,y=yy) time.sleep(2) touchAction.release().perform() time.sleep(0.3) tmp = test.find_list_byid(bubble_text,key) if tmp is not None: return tmp return None
def wait_X(dev,cls,key,timeout=3,isKey=False): """ :param dev: dev :param cls: 元素类名 :param key: 元素文本名 :param timeout: 超时 :param isKey: 是否精确匹配文本 :return: 元素 """ test = Action(dev) tmp = None for x in range(timepit): tmp = test.find_byclass(cls, key, isKey) if tmp is not None: return tmp time.sleep(1) return None
def widget_list_swipe_Down(dev): test = Action(dev) for x in range(10): if test.find_list_byid(widget_name,'音乐') is not None: return test.find_list_byid(widget_name,'音乐') test.swipe_Down(600,1) time.sleep(0.2) return None
def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey
class Music_Video_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self): """检查是否可以正常启动""" self.Case.assertTrue( self.test.start_activity(music_video_pkg, music_video_acivity), '启动 视频 失败,超时5秒未检测到主界面') def case_if_music_base(self, skip=False): """检查是否可以正常启动""" self.test.start_activity(music_video_pkg, music_video_music_acivity) time.sleep(1) if not skip: for x in range(3): if self.test.wait_if_activity(Permissions_Activity, timeout=3): time.sleep(0.3) self.test.find_byid(Permission_allow_button).click() time.sleep(0.5) else: time.sleep(1) break self.Case.assertTrue( self.test.wait_if_activity(music_video_music_acivity), '启动 音乐 失败,超时5秒未检测到主界面') time.sleep(1) def case_play_video(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.Case.assertTrue( self.test.start_activity(music_video_pkg, music_video_acivity), '启动 视频 失败,超时5秒未检测到主界面') time.sleep(1) if self._check_video_list('video_1'): self.test.find_list_byid(TEXT_ID_1, 'video_1').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') for y in range(5): if y > 2: self.Case.assertTrue( self.test.wait_if_activity(music_video_acivity), '启动 视频播放完毕未返回主界面,超时5秒未检测到界面') break time.sleep(3) time.sleep(1) def case_play_stop_video(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.Case.assertTrue( self.test.start_activity(music_video_pkg, music_video_acivity), '启动 视频 失败,超时5秒未检测到主界面') time.sleep(1) if self._check_video_list('video_2'): self.test.find_list_byid(TEXT_ID_1, 'video_2').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') self.test.find_byid(gallery_video_surface_view).click() self.test.find_byid(gallery_video_surface_view).click() time.sleep(1) tmp = self.test.find_byacc('播放视频') if tmp is not None: tmp.click() else: self.Case.fail('视频暂停失败,请检查') for y in range(16): if y > 13: self.Case.assertTrue( self.test.wait_if_activity(music_video_acivity), '启动 视频播放完毕未返回主界面,超时5秒未检测到界面') break time.sleep(3) time.sleep(1) def case_sleep_replay_video(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.Case.assertTrue( self.test.start_activity(music_video_pkg, music_video_acivity), '启动 视频 失败,超时5秒未检测到主界面') time.sleep(1) if self._check_video_list('video_2'): self.test.find_list_byid(TEXT_ID_1, 'video_2').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') time.sleep(3) self.driver.lock(1) # 休眠一秒 self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') for y in range(16): if y > 12: self.Case.assertTrue( self.test.wait_if_activity(music_video_acivity), '启动 视频播放完毕未返回主界面,超时5秒未检测到界面') break time.sleep(3) time.sleep(1) def case_play_music(self): self.case_if_music_base(True) 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) self._find_music('music_7').click() time.sleep(1) tmp = self.test.find_byid(music_video_music_list_nowplay_icon) self.Case.assertIsNotNone(tmp, '歌曲未在播放') time.sleep(3) tmp.click() time.sleep(0.5) def _find_music(self, keytext): for y in range(10): el = self.test.find_list_byid(music_video_music_list, keytext) if el is not None: return el self.test.swipe_Down(600, 1) time.sleep(0.2) return None def _check_video_list(self, keytext): for y in range(10): if self.test.find_list_byid(TEXT_ID_1, keytext) is not None: return True self.test.swipe_Down(600, 1) time.sleep(0.2) return False def case_music_play_three_class_music_flie(self): self.case_if_music_base(True) ogg_flag = False mp3_flag = False flac_flag = False for i in range(3): time.sleep(3) flie_list = self.test.find_byid_list(music_video_music_list) for n in flie_list: if not ogg_flag: if ".ogg" in n.text: n.click() time.sleep(3) ogg_flag = True continue if not mp3_flag: if ".mp3" in n.text: n.click() time.sleep(3) mp3_flag = True continue if not flac_flag: if ".flac" in n.text: n.click() time.sleep(3) flac_flag = True continue if not ogg_flag or not mp3_flag or not flac_flag: # 若有未找到3类型中一种则下滑列表重新获取 self.test.swipe_Down(600, 1) time.sleep(0.3) if not ogg_flag or not mp3_flag or not flac_flag: self.Case.fail( f"播放失败,ogg:{ogg_flag},mp3{mp3_flag},flac{flac_flag}") self.test.find_byid(music_video_music_list_nowplay_icon).click() def case_music_detail_replay_music_1(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 replay = self.test.find_byid(music_video_music_detail_replay_button) replay_status = self._check_replay_close(replay) if not replay_status: self.Case.fail("未切换至关闭重新播放模式") elif replay_status: self._find_lost_muisc_and_play() self._replay_muisc_skip() totaltime = self.test.find_byid( music_video_music_detail_totaltime).text for i in range(10): time.sleep(3) currenttime = self.test.find_byid( music_video_music_detail_crrenttime).text if currenttime == totaltime: break replay_status = self._check_replay_list(replay) if not replay_status: self.Case.fail("未切换至重新播放列表模式") elif replay_status: self._find_lost_muisc_and_play() current_music = self.test.find_byid( music_video_music_list_song_name) self._replay_muisc_skip() for i in range(3): time.sleep(3) if not current_music.text == self.test.find_byid( music_video_music_list_song_name).text: self.test.find_byid( music_video_music_list_song_name).click() break def case_music_detail_replay_music_2(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 replay = self.test.find_byid(music_video_music_detail_replay_button) replay_status = self._check_replay_current(replay) if not replay_status: self.Case.fail("未切换至重新播放当前音乐模式") elif replay_status: current_music = self.test.find_byid( music_video_music_list_song_name) self.test.find_byid(music_video_music_play_pause).click() self._replay_muisc_skip() for i in range(3): time.sleep(3) if current_music.text == self.test.find_byid( music_video_music_list_song_name).text: break def _check_replay_close(self, el): for i in range(3): el.click() if self.test.if_toast_text("重复播放已关闭。") is not None: return True return False def _check_replay_list(self, el): for i in range(3): el.click() if self.test.if_toast_text("重复播放所有歌曲。") is not None: return True return False def _check_replay_current(self, el): for i in range(3): el.click() if self.test.if_toast_text("重复播放当前歌曲。") is not None: return True return False def _replay_muisc_skip(self): progress_loc = self.test.find_byid(music_video_music_detail_progress) loc = progress_loc.location actions = TouchAction(self.driver) actions.long_press(x=(self.test.get_windows_height() * 0.3), y=loc['y']) actions.move_to(x=(self.test.get_windows_width() * 0.98), y=loc['y']) actions.release().perform() def _find_lost_muisc_and_play(self): #self.test.find_byid(music_video_music_detail_currentlist).click() for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.3) detail_muisclist = self.test.find_byid_list(music_video_music_list) if detail_muisclist is not None: detail_lostmuisc = detail_muisclist[len(detail_muisclist) - 1] detail_lostmuisc.click() time.sleep(0.2) if self.test.find_byid(music_video_music_list_song_name ).text != detail_lostmuisc.text: self.Case.fail('播放的音乐与选定的音乐不同') def case_music_detail_pervious_play(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 current_music = self.test.find_byid(music_video_music_list_song_name) for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.3) detail_musiclist = self.test.find_byid_list( music_video_music_list) # 获取当前歌曲列表 pervious_music = detail_musiclist[len(detail_musiclist) - 1] if current_music.text != pervious_music.text: self.test.find_byid(music_video_music_detail_previous).click() time.sleep(1) if not self.test.find_byid(music_video_music_list_song_name ).text == pervious_music.text: self.Case.fail("上一曲功能失败") def case_music_detail_next_play(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() #进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() #显示当前播放列表 for i in range(3): self.test.swipe_UP(600, 1) time.sleep(0.3) detail_musiclist = self.test.find_byid_list( music_video_music_list) #获取当前歌曲列表 current_music = detail_musiclist[0] current_music.click() next_music = detail_musiclist[1] if current_music.text != next_music.text: self.test.find_byid(music_video_music_detail_next).click() if not self.test.find_byid( music_video_music_list_song_name).text == next_music.text: self.Case.fail("下一曲功能失败") def case_music_detail_play_and_pause(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 current_time = self.test.find_byid( music_video_music_detail_crrenttime).text play_and_pause = self.test.find_byid(music_video_music_play_pause) play_and_pause.click() time.sleep(2) if current_time == self.test.find_byid( music_video_music_detail_crrenttime).text: self.Case.fail("歌曲继续播放功能失败") play_and_pause.click() current_time = self.test.find_byid( music_video_music_detail_crrenttime).text for i in range(3): time.sleep(3) if current_time != self.test.find_byid( music_video_music_detail_crrenttime).text: self.Case.fail("歌曲暂停功能失败") def case_music_detail_random_close(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 time.sleep(1) detail_musiclist = self.test.find_byid_list(music_video_music_list) for i in range(3): self.test.find_byid(music_video_music_detail_random).click() if self.test.if_toast_text("随机播放已关闭。") is not None: detail_musiclist[0].click() time.sleep(0.2) next_button = self.test.find_byid( music_video_music_detail_next) next_button.click() if detail_musiclist[1].text != self.test.find_byid( music_video_music_list_song_name).text: self.Case.fail("随机播放关闭功能失败") break def case_music_detail_random(self): self.case_if_music_base(True) self.test.find_byid( music_video_music_current_song_album).click() # 进入歌曲详细页面 time.sleep(3) self.test.find_byid( music_video_music_detail_currentlist).click() # 显示当前播放列表 time.sleep(1) detail_musiclist = self.test.find_byid_list(music_video_music_list) for i in range(3): self.test.find_byid(music_video_music_detail_random).click() if self.test.if_toast_text("随机播放已打开。") is not None: detail_musiclist[0].click() time.sleep(0.2) next_button = self.test.find_byid( music_video_music_detail_next) next_button.click() time.sleep(0.2) if detail_musiclist[1].text == self.test.find_byid( music_video_music_list_song_name).text: next_button.click(0.2) if detail_musiclist[2].text == self.test.find_byid( music_video_music_list_song_name).text: self.Case.fail("随机播放功能失败") break def case_music_delete_file(self): self.case_if_music_base(True) music_list = self.test.find_byid_list(music_video_music_list) indicator_list = self.test.find_byid_list( music_video_music_indicator_list) music_name = music_list[0].text indicator_list[0].click() time.sleep(1) delete_button = self.test.find_list_byid(music_video_music_title_list, '删除') delete_button.click() time.sleep(1) delete_flie = self.test.find_byid(music_video_music_delete) delete_flie.click() time.sleep(1) if self.test.find_list_byid(music_video_music_list, music_name) is not None: self.Case.fail("删除音乐文件失败") def case_video_main_activity_keydown_recent(self): self.case_if_base() time.sleep(1) self.driver.press_keycode(187, 0, 0) # all apps list 多任务管理按钮 time.sleep(2) self.driver.press_keycode(4, 0, 0) time.sleep(2) self.Case.assertTrue(self.test.wait_if_activity(music_video_acivity), '没有返回视频 主界面') def case_video_Movie_activity_keydown_recent(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) if self._check_video_list('video_2'): self.test.find_list_byid(TEXT_ID_1, 'video_2').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') time.sleep(2) self.driver.press_keycode(187, 0, 0) # all apps list 多任务管理按钮 time.sleep(2) self.driver.press_keycode(4, 0, 0) time.sleep(2) self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '没有返回 播放 界面') time.sleep(0.5) self.driver.press_keycode(4, 0, 0) time.sleep(1) def case_video_Movie_activity_keydown_home(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) if self._check_video_list('video_2'): self.test.find_list_byid(TEXT_ID_1, 'video_2').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') time.sleep(2) self.driver.press_keycode(3, 0, 0) #HOME键 time.sleep(2) try: self.Case.assertTrue( self.test.start_activity(music_video_pkg, music_video_acivity), '未成功返回播放界面') except selenium.common.exceptions.WebDriverException: pass self.driver.press_keycode(4, 0, 0) time.sleep(1) def case_video_Movie_activity_longkeydown_power(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) if self._check_video_list('video_2'): self.test.find_list_byid(TEXT_ID_1, 'video_2').click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), '启动 视频播放 失败,超时5秒未检测到界面') time.sleep(2) self.driver.long_press_keycode(26, 0, 0) # power键 time.sleep(0.2) self.driver.press_keycode(4, 0, 0) time.sleep(1) def case_music_set_widget(self): self.driver.press_keycode(3, 0, 0) time.sleep(1) tmp = get_widget_menu(self.driver) if tmp is None: self.Case.fail('未成功长按出 桌面 小菜单') tmp.click() time.sleep(1) tmp = widget_list_swipe_Down(self.driver) if tmp is None: self.Case.fail('未找到音乐小挂件') touchAction = TouchAction(self.driver) touchAction.long_press(el=tmp) time.sleep(2) touchAction.release().perform() time.sleep(1) tmp = self.test.find_byid(music_video_widget_icon) if tmp is None: self.Case.fail('音乐桌面小图标,未放置成功') tmp.click() self.Case.assertTrue( self.test.wait_if_activity(music_video_music_acivity), '通过桌面小挂件打开音乐失败') time.sleep(1) def case_music_set_singer_view(self): self.case_if_music_base(True) time.sleep(1) 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_list_byclass(TextView) for x in tmp_list: t = x.text if '付娜' in t: time.sleep(1) return if '中央芭蕾舞团管弦乐队' in t: time.sleep(1) return if '周深' in t: time.sleep(1) return if '张含韵' in t: time.sleep(1) return self.Case.fail('歌曲非 歌手 列表排列') 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_music_favorite(self): 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_int = random.randint(1, 8) test_name = f'music_{tmp_int}' self._find_music(test_name).click() time.sleep(1) self.test.find_byid(music_video_music_list_nowplay_icon).click() time.sleep(1) self.test.find_byid(music_video_music_list_song_name).click() time.sleep(1) self.test.find_byid(music_video_music_favorite).click() if self.test.if_toast_text('歌曲已添加到播放列表') is None: log('error', '添加到 收藏,未找到 toast') self.driver.press_keycode(4, 0, 0) time.sleep(1) 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('我的收藏').click() time.sleep(1) tmp = self.test.find_byclass(TextView, test_name) if tmp is None: self.Case.fail(f'列表中没有音乐 {test_name}') def case_music_share(self): 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(1) if not self.test.wait_if_activity(Share_Activity): self.Case.fail(f'分享界面未显示') tmp_list = self.test.find_list_byclass(TextView) isBluetooth = False isNFC = False for x in tmp_list: t = x.text if '蓝牙' in t: isBluetooth = True if 'NFC' in t or 'Beam' in t: isNFC = True if isBluetooth and isNFC: time.sleep(1) return if not isNFC: self.Case.fail(f'没有NFC分享 选项,请确认是否需要') if not isBluetooth: self.Case.fail(f'没有蓝牙分享 选项,请确认是否需要') def case_music_bgm_rec_sms(self): 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) for x in range(5): tmp_int = random.randint(1, 8) test_name = f'music_{tmp_int}' tmp = self._find_music(test_name) if tmp is not None: tmp.click() break time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) messaging_CaseMethod = Messaging_CaseMethod( self.driver, 'case_Messaging_A_test_if_base') messaging_CaseMethod.case_if_send_and_rec_sms() time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) self.case_if_music_base(True) time.sleep(1) self.test.find_byid(music_video_music_list_nowplay_icon).click() time.sleep(1) def case_music_bgm_camera(self): 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) for x in range(5): tmp_int = random.randint(1, 8) test_name = f'music_{tmp_int}' tmp = self._find_music(test_name) if tmp is not None: tmp.click() break time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) camera_CaseMethod = Camera_CaseMethod(self.driver, 'case_Camera_A_test_if_base') camera_CaseMethod.case_back_front_take_a_picture() time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) self.case_if_music_base(True) time.sleep(1) self.test.find_byid(music_video_music_list_nowplay_icon).click() time.sleep(1) def case_music_bgm_video(self): 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) for x in range(5): tmp_int = random.randint(1, 8) test_name = f'music_{tmp_int}' tmp = self._find_music(test_name) if tmp is not None: tmp.click() break time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) camera_CaseMethod = Camera_CaseMethod(self.driver, 'case_Camera_A_test_if_base') camera_CaseMethod.case_back_front_take_a_video() time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) self.case_if_music_base(True) time.sleep(1) self.test.find_byid(music_video_music_list_nowplay_icon).click() time.sleep(1) def case_music_bgm_play_film(self): 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) for x in range(5): tmp_int = random.randint(1, 8) test_name = f'music_{tmp_int}' tmp = self._find_music(test_name) if tmp is not None: tmp.click() break time.sleep(1) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) self.case_play_video() time.sleep(1) def case_music_notifications_widget_test(self): 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) for x in range(5): tmp_int = random.randint(1, 8) test_name = f'music_{tmp_int}' tmp = self._find_music(test_name) if tmp is not None: tmp.click() break time.sleep(1) self.driver.open_notifications() time.sleep(0.5) self.test.find_byid(music_video_music_widget_next).click() time.sleep(1) tmp_text = self.test.find_byid(music_video_music_widget_song_name).text if test_name in tmp_text: self.Case.fail(f'没有更换下一曲') time.sleep(1) self.test.find_byid(music_video_music_widget_prev).click() time.sleep(1) tmp_text_1 = self.test.find_byid( music_video_music_widget_song_name).text if tmp_text in tmp_text_1: self.Case.fail(f'没有更换上一曲') time.sleep(1) self.test.find_byid(music_video_music_widget_pause).click() time.sleep(0.5) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(0.5) self.Case.assertTrue( self.test.wait_if_activity(music_video_music_acivity), '未检测到音乐界面') time.sleep(0.5) def _checK_play_list(self, key): for x in range(5): tmp = self.test.find_byclass(TextView, key) if tmp is not None: return tmp self.test.swipe_Down(600, 1) time.sleep(0.5) return None
class Clock_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self, Skip=False): """设置基础,检查是否可以正常启动""" self.driver.activate_app(clock_pkg) if not Skip: if self.test.wait_if_activity(Permissions_Activity): self.test.find_byid(Permission_allow_button).click() time.sleep(1) self.Case.assertTrue(self.test.wait_if_activity(clock_activity), '启动 时钟 失败,超时5秒未检测到主界面') self.test.set_PORTRAIT() time.sleep(1) 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_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 case_check_timer_input(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) for x in range(10): self.test.find_byid(f'{clock_timer_x}{x}').click() time.sleep(0.1) tmp_time = self.test.find_byid(clock_show_timer).text if f'0{x}秒' not in tmp_time: self.Case.fail(f'定时器设定 {x} 秒失败') self.test.find_byid(clock_del_timer_time).click() time.sleep(0.2) def case_set_timer(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_byid(clock_timer_6).click() tmp_time = self.test.find_byid(clock_show_timer).text if f'06秒' not in tmp_time: self.Case.fail(f'定时器设定 6 秒失败') self.test.find_byid(clock_start_timer).click() time.sleep(1) self.test.find_byid(clock_start_timer).click() time.sleep(1) text_time = self.test.find_byid(clock_show_timer_started).text try: if 6 > int(text_time) > 4: self.Case.fail(f'定时器计时失败,6秒计时器,剩余{text_time}') except ValueError: self.Case.fail(f'定时器显示失败,显示为:{text_time}') time.sleep(0.5) self.test.find_byid(clock_del_timer).click() time.sleep(0.5) self.Case.assertIsNone(self.test.find_byid(clock_start_timer), '定时器未删除') time.sleep(1) def case_check_Stopwatch(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.Case.assertIsNotNone(self.test.find_byid(clock_show_stopwatch), '秒表 计数盘 未显示') tmp = self.test.find_byid(clock_show_stopwatch_time) self.test.find_byid(clock_start_timer).click() time.sleep(3) self.test.find_byid(clock_start_timer).click() try: tmp_time = 0 """ for x in range(10): tmp = self.test.find_byid(clock_show_stopwatch_time) if tmp is not None: tmp_time = int(tmp.text) """ tmp_time = int(tmp.text) if tmp_time == 0: self.Case.fail(f'未获取到,秒表时间') except ValueError: self.Case.fail(f'秒表时间显示错误,计时约三秒,{tmp_time}') if tmp_time < 2.9: self.Case.fail(f'秒表时间显示错误,计时约三秒,未超过2.9秒:时间为:{tmp_time}') self.test.find_byacc('重置').click() time.sleep(1) def case_check_clock_UI_switch(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '时钟' in str_tmp: m.click() time.sleep(1) break detail_clock = self.test.find_byid(clock_show_time) if detail_clock is None: self.Case.fail("未找到当前详细时间,进入的页面非时钟页面") cities = self.test.find_list_byclass(ImageButton) city_flag = False for city in cities: str_tmp = city.get_attribute('content-desc') if '城市' in str_tmp: city_flag = True break if not city_flag: self.Case.fail("未找到时区(城市)选择按钮,进入的页面非时钟页面") self.test.swipe_Right(600, 1) time.sleep(1) switch_list = self.test.find_list_byclass(Switch) if switch_list is None: alarm_list = self.test.find_list_byclass(TextView) alarm_flag = False for alarm in alarm_list: str_tmp = alarm.text if '没有闹钟' in str_tmp: alarm_flag = True break if not alarm_flag: self.Case.fail("未找到闹钟和没有闹钟提示,进入的页面非闹钟页面") add_list = self.test.find_list_byclass(ImageButton) add_flag = False for add in add_list: str_tmp = add.get_attribute('content-desc') if '添加闹钟' in str_tmp: add_flag = True break if not add_flag: self.Case.fail("未找到添加闹钟的按钮,切换的页面非闹钟页面") self.test.swipe_Left(600, 1) time.sleep(1) self.test.swipe_Left(600, 1) time.sleep(1) timer_text = self.test.find_byid(clock_show_timer) if timer_text is None: self.Case.fail("未找到定时器时刻表,切换的页面非定时器页面") del_list = self.test.find_list_byclass(ImageButton) del_flag = False for d in del_list: str_tmp = d.get_attribute('content-desc') if '删除' in str_tmp: del_flag = True break if not del_flag: self.Case.fail("未找到定时器删除按钮,切换的页面非定时器页面") self.test.swipe_Left(600, 1) time.sleep(1) stopwatch_veiw = self.test.find_byid(clock_stopwatch_veiw) if stopwatch_veiw is None: self.Case.fail("未找到秒表面板,切换的为非秒表页面") start_stop_button_list = self.test.find_list_byclass(ImageButton) start_flag = False for s in start_stop_button_list: str_tmp = s.get_attribute('content-desc') if '开始' in str_tmp: start_flag = True break if not start_flag: self.Case.fail("未找到秒表开始计时的按钮,切换的为非秒表页面") def case_clock_set_city_time(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '时钟' in str_tmp: m.click() time.sleep(1) break city_button = self.test.find_list_byclass(ImageButton) city_flag = False for city in city_button: str_tmp = city.get_attribute('content-desc') if '城市' in str_tmp: city.click() time.sleep(2) city_flag = True break if not city_flag: self.Case.fail("未找到城市按钮,确认当前页面为时钟页面") city_check_list = self.test.find_list_byclass(CheckBox) for city in city_check_list: str_tmp = city.get_attribute('content-desc') if '阿比让' in str_tmp: city.click() time.sleep(1) break back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(2) break textview_list = self.test.find_list_byclass(TextView) city_flag = False for t in textview_list: str_tmp = t.text if '阿比让' in str_tmp: city_flag = True break if not city_flag: self.Case.fail("未找到选中的城市") city_button = self.test.find_list_byclass(ImageButton) city_flag = False for city in city_button: str_tmp = city.get_attribute('content-desc') if '城市' in str_tmp: city.click() time.sleep(2) city_flag = True break if not city_flag: self.Case.fail("未找到城市按钮,确认当前页面为时钟页面") city_check_list = self.test.find_list_byclass(CheckBox) for city in city_check_list: str_tmp = city.get_attribute('content-desc') if '阿比让' in str_tmp: city.click() time.sleep(1) break back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(2) break def case_back_and_home_out_of_clock(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '时钟' in str_tmp: m.click() time.sleep(1) break self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) if self.test.wait_if_activity(clock_activity): self.Case.fail("在时钟界面按返回键无法退出界面") else: self.case_if_base(True) self.driver.press_keycode(KEY_HOME, 0, 0) time.sleep(1) if self.test.wait_if_activity(clock_activity): self.Case.fail("在时钟界面按HOME按钮无法退出界面") def case_preview_and_play_timer_sounds(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '定时器' in str_tmp: m.click() time.sleep(1) break more_list = self.test.find_list_byclass(ImageView) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break set_list = self.test.find_list_byclass(TextView) for s in set_list: str_tmp = s.text if '设置' in str_tmp: s.click() time.sleep(1) break for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.1) setting_list = self.test.find_list_byclass(TextView) for sets in setting_list: str_tmp = sets.text if '定时器提示音' in str_tmp: sets.click() time.sleep(3) break sounds_list = self.test.find_list_byclass(TextView) sound_flag = False for sound in sounds_list: str_tmp = sound.text if '静音' in str_tmp: sound.click() time.sleep(2) sound_flag = True continue if sound_flag: sound.click() time.sleep(2) for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.2) sound_list = self.test.find_list_byclass(TextView) for s in sound_list: s.click() time.sleep(2) if not sound_flag: self.Case.fail("未找到任何铃声") def case_set_and_check_timer_sound(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '定时器' in str_tmp: m.click() time.sleep(1) break more_list = self.test.find_list_byclass(ImageView) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break set_list = self.test.find_list_byclass(TextView) for s in set_list: str_tmp = s.text if '设置' in str_tmp: s.click() time.sleep(1) break for i in range(3): self.test.swipe_Down(600, 1) time.sleep(0.1) setting_list = self.test.find_list_byclass(TextView) for sets in setting_list: str_tmp = sets.text if '定时器提示音' in str_tmp: sets.click() time.sleep(3) break sounds_list = self.test.find_list_byclass(TextView) for sound in sounds_list: str_tmp = sound.text if 'Argon' in str_tmp: sound.click() time.sleep(2) break back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(1) break setting_list = self.test.find_list_byclass(TextView) sound_check = False for sets in setting_list: str_tmp = sets.text if 'Argon' in str_tmp: sound_check = True break if not sound_check: self.Case.fail("定时器提示音设置失败") back_list = self.test.find_list_byclass(ImageButton) for back in back_list: str_tmp = back.get_attribute('content-desc') if '转到上一层级' in str_tmp: back.click() time.sleep(1) break self.test.find_byid(clock_timer_6).click() time.sleep(1) image_list = self.test.find_list_byclass(ImageButton) for i in image_list: str_tmp = i.get_attribute('content-desc') if '开始' in str_tmp: i.click() time.sleep(2) break for i in range(5): time.sleep(3) button_list = self.test.find_list_byclass(Button) for b in button_list: str_tmp = b.text if '删除' in str_tmp: b.click() time.sleep(2) break if self.test.find_byid(clock_show_timer) is None: self.Case.fail("删除定时器失败") def case_timer_add_one_minute_check(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base(True) mode_list = self.test.find_list_byclass(TextView) for m in mode_list: str_tmp = m.text if '定时器' in str_tmp: m.click() time.sleep(1) break one_button = self.test.find_byid(clock_timer_1) for i in range(6): one_button.click() time.sleep(1) for i in range(4): self.test.find_byid(clock_del_timer_time).click() time.sleep(1) image_list = self.test.find_list_byclass(ImageButton) for i in image_list: str_tmp = i.get_attribute('content-desc') if '开始' in str_tmp: i.click() time.sleep(2) break add_list = self.test.find_list_byclass(Button) for adds in add_list: str_tmp = adds.text if '+1:00' in str_tmp: adds.click() time.sleep(1) break button_list = self.test.find_list_byclass(Button) for b in button_list: str_tmp = b.text if '删除' in str_tmp: b.click() time.sleep(2) break
class CALC_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self): """检查是否可以正常启动""" try: self.driver.activate_app(calc_pkg) except: self.test.start_activity(calc_pkg, calc_acivity) self.Case.assertTrue(self.test.wait_if_activity(calc_acivity), '启动 计算器 失败,超时5秒未检测到主界面') time.sleep(1) def case_get_add_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_add).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text if (int_a + int_b) != int(tmp): self.Case.fail(f'计算结果失败,{int_a} + {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_get_sub_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_sub).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text tmp_new = re.search('\d+', tmp).group(0) if int_a >= int_b: if (int_a - int_b) != int(tmp): self.Case.fail( f'计算结果失败 int_a >= int_b: {int_a} - {int_b} = {tmp}') else: try: int(tmp) self.Case.fail( f'计算结果失败 - not in tmp: {int_a} - {int_b} = {tmp}') except ValueError: pass if (int_b - int_a) != int(tmp_new): self.Case.fail(f'计算结果失败 tmp_new: {int_a} - {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_get_mul_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_mul).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text if (int_a * int_b) != int(tmp): self.Case.fail(f'计算结果失败: {int_a} * {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_get_div_result(self): self.case_if_base() int_a = random.randint(0, 9) int_b = random.randint(0, 9) time.sleep(0.2) self.test.find_byid(f'{calc_number_test}{int_a}').click() self.test.find_byid(calc_op_div).click() self.test.find_byid(f'{calc_number_test}{int_b}').click() self.test.find_byid(calc_eq).click() time.sleep(0.1) tmp = self.test.find_byid(calc_show_result).text try: tmp = float(tmp) except ValueError: if int_b != 0: self.Case.fail(f'计算结果失败 ValueError: {int_a} / {int_b} = {tmp}') else: return tmp = round(tmp, 2) if round(int_a / int_b, 2) != tmp: self.Case.fail(f'计算结果失败: {int_a} / {int_b} = {tmp}') time.sleep(0.5) self.test.find_byid(calc_clr).click() tmp = self.test.find_byid(calc_show_result).text if tmp not in '': self.Case.fail(f'计算结果未清除') time.sleep(0.5) def case_switch_UI_check(self): self.case_if_base() if self.test.find_byid(calc_number_1) is None: self.Case.fail("未找到‘1’按钮") if self.test.find_byid(calc_number_2) is None: self.Case.fail("未找到‘2’按钮") if self.test.find_byid(calc_number_3) is None: self.Case.fail("未找到‘3’按钮") if self.test.find_byid(calc_number_4) is None: self.Case.fail("未找到‘4’按钮") if self.test.find_byid(calc_number_5) is None: self.Case.fail("未找到‘5’按钮") if self.test.find_byid(calc_number_6) is None: self.Case.fail("未找到‘6’按钮") if self.test.find_byid(calc_number_7) is None: self.Case.fail("未找到‘7’按钮") if self.test.find_byid(calc_number_8) is None: self.Case.fail("未找到‘8’按钮") if self.test.find_byid(calc_number_9) is None: self.Case.fail("未找到‘9’按钮") if self.test.find_byid(calc_eq) is None: self.Case.fail("未找到‘=’按钮") if self.test.find_byid(calc_number_0) is None: self.Case.fail("未找到‘0’按钮") if self.test.find_byid(calc_dec_point) is None: self.Case.fail("未找到点按钮") if self.test.find_byid(calc_del) is None: self.Case.fail("未找到删除按钮") if self.test.find_byid(calc_op_div) is None: self.Case.fail("未找到‘÷’按钮") if self.test.find_byid(calc_op_mul) is None: self.Case.fail("未找到’ב按钮") if self.test.find_byid(calc_op_sub) is None: self.Case.fail("未找到“-”按钮") if self.test.find_byid(calc_op_add) is None: self.Case.fail("未找到“+”按钮") self.test.swipe_Left(600, 1) time.sleep(1) if self.test.find_byid(calc_advanced_INV) is None: self.Case.fail("未找到“INV”按钮") if self.test.find_byid(calc_advanced_DEG) is None: self.Case.fail("未找到“DEG”按钮") if self.test.find_byid(calc_advanced_pct) is None: self.Case.fail("未找到“%”按钮") if self.test.find_byid(calc_advanced_sin) is None: self.Case.fail("未找到“sin”按钮") if self.test.find_byid(calc_advanced_cos) is None: self.Case.fail("未找到“cos”按钮") if self.test.find_byid(calc_advanced_tan) is None: self.Case.fail("未找到“tan”按钮") if self.test.find_byid(calc_advanced_ln) is None: self.Case.fail("未找到“ln”按钮") if self.test.find_byid(calc_advanced_log) is None: self.Case.fail("未找到“log”按钮") if self.test.find_byid(calc_advanced_fact) is None: self.Case.fail("未找到“!”按钮") if self.test.find_byid(calc_advanced_pi) is None: self.Case.fail("未找到“π”按钮") if self.test.find_byid(calc_advanced_e) is None: self.Case.fail("未找到“e”按钮") if self.test.find_byid(calc_advanced_pow) is None: self.Case.fail("未找到“^”按钮") def case_calc_basic_button_check(self): self.case_if_base() for i in range(10): self.test.find_byid(f'{calc_number_test}{i}').click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if f'{i}' not in result: self.Case.fail(f"按钮‘{i}’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_dec_point).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '.' not in result: self.Case.fail("按钮‘.’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_number_0).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '0' in result: self.test.find_byid(calc_op_div).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '÷' not in result: self.Case.fail("按钮‘÷’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_op_mul).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '×' not in result: self.Case.fail("按钮‘×’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_op_sub).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '−' not in result: self.Case.fail("按钮‘-’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_op_add).click() time.sleep(1) result = self.test.find_byid(calc_show_formula).text if '+' not in result: self.Case.fail("按钮‘+’功能未生效") else: self.test.find_byid(calc_del).click() time.sleep(1) self.test.find_byid(calc_eq).click() time.sleep(1) result = self.test.find_byid(calc_show_result).text if '0' in result: more_list = self.test.find_list_byclass(ImageButton) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break text_button_list = self.test.find_list_byclass(TextView) for t in text_button_list: str_tmp = t.text if '在结果中显示前导数' in str_tmp: t.click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) for text in text_list: str_tmp = text.text if '0 (精确)' not in str_tmp: self.Case.fail("结果显示错误") else: self.test.find_byclass(Button, '关闭').click() time.sleep(1) break break more_list = self.test.find_list_byclass(ImageButton) for more in more_list: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(1) break text_button_list = self.test.find_list_byclass(TextView) for t in text_button_list: str_tmp = t.text if '以分数形式显示结果' in str_tmp: t.click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) for text in text_list: str_tmp = text.text if '0' not in str_tmp: self.Case.fail("结果显示错误") else: self.test.find_byclass(Button, '关闭').click() time.sleep(1) break break def case_clac_advance_button_check(self): self.case_if_base() self.test.swipe_Left(600, 1) time.sleep(1) INV = self.test.find_byid(calc_advanced_INV) INV.click() time.sleep(1) btext_list = self.test.find_list_byclass(Button) b_flag = True for btext in btext_list: str_tmp = btext.text if f'sin⁻¹' == f'sin' and f'sin' in str_tmp: self.Case.fail("未出现sin⁻¹按钮") b_flag = False continue if f'cos⁻¹' == f'cos' and f'cos' in str_tmp: self.Case.fail("未出现cos⁻¹按钮") b_flag = False continue if f'tan⁻¹' == f'tan' and f'tan' in str_tmp: self.Case.fail("未出现tan⁻¹按钮") b_flag = False continue if f'eˣ' == f'ln' and f'ln' in str_tmp: self.Case.fail("未出现eˣ按钮") b_flag = False continue if f'10ˣ' == f'log' and f'log' in str_tmp: self.Case.fail("未出现10ˣ按钮") b_flag = False continue if f'x²' == f'√' and f'√' in str_tmp: self.Case.fail("未出现x²按钮") b_flag = False break if not b_flag: self.Case.fail("INV 功能不完整") self.test.find_byid(calc_advanced_DEG).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) t_flag = False for t in text_list: str_tmp = t.text if 'DEG' in str_tmp: t_flag = True break if not t_flag: self.Case.fail("DEG 角度切换失败") self.test.find_byid(calc_advanced_DEG).click() time.sleep(1) self.test.find_byid(calc_advanced_pct).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '%' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("% 功能失效") self.test.find_byid(calc_advanced_arcsin).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'sin⁻¹(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("sin⁻¹按钮失效") self.test.find_byid(calc_advanced_arccos).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'cos⁻¹(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("cos⁻¹按钮失效") self.test.find_byid(calc_advanced_arctan).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'tan⁻¹(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("tan⁻¹按钮失败") self.test.find_byid(calc_advanced_exp).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'exp(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("eˣ按钮失效") self.test.find_byid(calc_advacnced_tPow).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '10^' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("10ˣ按钮失效") self.test.find_byid(calc_advanced_fact).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '!' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("!按钮失效") self.test.find_byid(calc_advanced_pi).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'π' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("π按钮失效") self.test.find_byid(calc_advanced_e).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'e' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("e按钮失效") self.test.find_byid(calc_advanced_pow).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '^' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("^按钮失效") self.test.find_byid(calc_advanced_lparen).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '^(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("(按钮失效") self.test.find_byid(calc_advanced_rparen).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if ')' in str_tmp: text_flag = True break if not text_flag: self.Case.fail(")按钮失效") self.test.find_byid(calc_advanced_sqr).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if ')²' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("x²按钮失效") self.test.find_byid(calc_advanced_INV).click() time.sleep(1) self.test.find_byid(calc_advanced_sin).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'sin(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("sin按钮失效") self.test.find_byid(calc_advanced_cos).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'cos(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("cos按钮失效") self.test.find_byid(calc_advanced_tan).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'tan(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("tan按钮失效") self.test.find_byid(calc_advanced_ln).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'ln(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("ln按钮失效") self.test.find_byid(calc_advanced_log).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if 'log(' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("log按钮失效") self.test.find_byid(calc_advanced_sqrt).click() time.sleep(1) text_list = self.test.find_list_byclass(TextView) text_flag = False for text in text_list: str_tmp = text.text if '√' in str_tmp: text_flag = True break if not text_flag: self.Case.fail("√按钮失效")
class CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self): """检查是否可以正常启动""" try: self.driver.activate_app(phone_pkg) except: self.test.start_activity(phone_pkg,phone_main_activity) self.Case.assertTrue(self.test.wait_if_activity(phone_main_activity), '启动电话失败,超时5秒未检测到主界面') time.sleep(1) def case_get_imei_mdid(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.driver.activate_app(phone_pkg) self.Case.assertTrue(self.test.wait_if_activity(phone_main_activity), '等待5秒未检测到电话主界面') self.test.find_byid(phone_to_keypad).click() time.sleep(1) self.Case.assertIsNotNone(self.test.find_byid(phone_keypad_view),'拨号盘未显示') self.test.find_byid(phone_num_star).click() self.test.find_byid(phone_num_pound).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_6).click() self.test.find_byid(phone_num_pound).click() time.sleep(1) self.Case.assertTrue(('IMEI' in self.test.find_byid(phone_IMEI_Title).text),'IMEI 提示框 未显示') list_imei = self.test.find_byid_list(phone_imei_show) self.Case.assertIsNotNone(list_imei, 'IMEI号不存在') if len(list_imei) < 2: self.Case.fail('IMEI号不存在') for y in list_imei: str = y.text if len(str) == 15: try: int(str) except ValueError: self.Case.fail(f'IMEI号显示错误,非数字 (如果是MEID可能含有字母,并非bug): {str}') elif len(str) > 5: pass else: self.Case.fail(f'IMEI号显示错误 :长度为 0 : {str}') def case_call(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() self.test.find_byid(phone_to_keypad).click() time.sleep(1) self.Case.assertIsNotNone(self.test.find_byid(phone_keypad_view), '拨号盘未显示') num = devices_Config['operators'] if 10086 == num: self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_8).click() self.test.find_byid(phone_num_6).click() elif 10010 == num: self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_0).click() else: self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_0).click() self.test.find_byid(phone_num_0).click() tmp_num = self.test.find_byid(phone_number_view).text tmp_num = int(re.sub(r' ','',tmp_num)) if tmp_num != num: self.Case.fail(f'输入号码显示不正确,输入为:{num},显示为:{tmp_num}') self.test.find_byid(phone_dialpad_button).click() for x in range(20): tmp_time = self.test.find_byid(phone_call_time_view) if tmp_time is not None: break time.sleep(1) time.sleep(3) self.test.find_byid(phone_call_end).click() time.sleep(2) self.Case.assertIsNone(self.test.find_byid(phone_call_time_view),'通话未挂断') self.driver.press_keycode(3, 0, 0) def case_call_112(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() self.test.find_byid(phone_to_keypad).click() time.sleep(1) self.Case.assertIsNotNone(self.test.find_byid(phone_keypad_view), '拨号盘未显示') self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_1).click() self.test.find_byid(phone_num_2).click() tmp_num = self.test.find_byid(phone_number_view).text tmp_num = int(re.sub(r' ','',tmp_num)) if tmp_num != 112: self.Case.fail(f'输入号码显示不正确,输入为:{num},显示为:{tmp_num}') self.test.find_byid(phone_dialpad_button).click() for x in range(20): tmp_time = self.test.find_byid(phone_call_time_view) if tmp_time is not None: break time.sleep(1) time.sleep(3) self.test.find_byid(phone_call_end).click() time.sleep(2) self.Case.assertIsNone(self.test.find_byid(phone_call_time_view),'通话未挂断') self.driver.press_keycode(3, 0, 0) def case_ergodic_phone_view(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() tmp_list = self.test.find_byid_list(phone_bottom_Button) tmp_int = 0 for x in tmp_list: tmp_text = x.text if '快速拨号' in tmp_text: x.click() tmp_int += 1 if '通话记录' in tmp_text: x.click() tmp_int += 1 if '联系人' in tmp_text: x.click() tmp_int += 1 time.sleep(0.5) if tmp_int != 3: self.Case.fail("遍历 电话 界面失败,需要包含 :快速拨号 通话记录 联系人") def case_send_msg(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() self.test.find_byid(phone_to_keypad).click() time.sleep(1) self.Case.assertIsNotNone(self.test.find_byid(phone_keypad_view), '拨号盘未显示') test_number = self._random_number(times=5) self.test.find_list_byid(phone_search_action,'发送短信').click() self.Case.assertTrue(self.test.wait_if_activity(msg_edit_activity),'通过电话界面发送短信失败,未进入短信编辑界面') time.sleep(1) tmp_text = self.test.find_byid(msg_phone_edi).text tmp_text = re.sub(" ","",tmp_text) if test_number not in tmp_text: self.Case.fail(f"电话号码不匹配,拨号盘{test_number},短信界面{tmp_text}") def case_new_Contacts(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() self.test.find_byid(phone_to_keypad).click() time.sleep(1) self.Case.assertIsNotNone(self.test.find_byid(phone_keypad_view), '拨号盘未显示') test_number = self._random_number(times=5) self.test.find_list_byid(phone_search_action,'新建联系人').click() if self.test.find_list_byid(contacts_id_text,'联系人备份到') is not None: #取消备份到谷歌 self.test.find_byid(contacts_left_button).click() time.sleep(1) if not self.test.wait_if_activity(contacts_new_contacts_activity): self.Case.fail('未检测到新建联系人界面') time.sleep(1) tmp_text = self.test.find_byclass(Edit_Text,test_number[0:2]).text tmp_text = re.sub(" ","",tmp_text) if test_number not in tmp_text: self.Case.fail(f"电话号码不匹配,拨号盘{test_number},新建联系人{tmp_text}") def _random_number(self,times=11): int_tmp = '' for x in range(times): int_tmp_x = random.randint(0,9) if int_tmp_x == 0: self.test.find_byid(phone_num_0).click() int_tmp = f'{int_tmp}{0}' elif int_tmp_x == 1: self.test.find_byid(phone_num_1).click() int_tmp = f'{int_tmp}{1}' elif int_tmp_x == 2: self.test.find_byid(phone_num_2).click() int_tmp = f'{int_tmp}{2}' elif int_tmp_x == 3: self.test.find_byid(phone_num_3).click() int_tmp = f'{int_tmp}{3}' elif int_tmp_x == 4: self.test.find_byid(phone_num_4).click() int_tmp = f'{int_tmp}{4}' elif int_tmp_x == 5: self.test.find_byid(phone_num_5).click() int_tmp = f'{int_tmp}{5}' elif int_tmp_x == 6: self.test.find_byid(phone_num_6).click() int_tmp = f'{int_tmp}{6}' elif int_tmp_x == 7: self.test.find_byid(phone_num_7).click() int_tmp = f'{int_tmp}{7}' elif int_tmp_x == 8: self.test.find_byid(phone_num_8).click() int_tmp = f'{int_tmp}{8}' else: self.test.find_byid(phone_num_9).click() int_tmp = f'{int_tmp}{9}' time.sleep(0.3) return int_tmp
class Gallery_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self): """检查是否可以正常启动""" self.driver.activate_app(gallery_Pkg) self.Case.assertTrue(self.test.wait_if_activity(gallery_activity), '启动图库失败,超时5秒未检测到主界面') def case_swipe_view(self): self.case_if_base() time.sleep(1) root_view = self.test.find_byid(gallery_root_view) root_view.click() self.test.swipe_Right(200, 3) self.test.swipe_Left(200, 3) def case_swipe_L_view(self): self.case_if_base() time.sleep(1) self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() self.test.swipe_Right(200, 3) self.test.find_byid(photopage_bottom).click() def case_get_picture_date(self): """返回 hms 时分秒int时间戳,仅相机拍照""" self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp_text = self.test.find_list_byid(gallery_picture_details_text, '标题').text tmp_time = int(tmp_text.split('_')[2]) return tmp_time def case_get_picture_size(self): """ 返回照片的尺寸,[int , int] :return: tmp_width , tmp_hight """ self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp_hight = self.test.find_list_byid(gallery_picture_details_text, '高度').text #width tmp_hight = int(tmp_hight.split(' ')[1]) tmp_width = self.test.find_list_byid(gallery_picture_details_text, '宽度').text # width tmp_width = int(tmp_width.split(' ')[1]) return tmp_width, tmp_hight def case_get_picture_flash(self): """ 返回照片是否使用闪光灯 :return: boolean """ self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp = self.test.find_list_byid(gallery_picture_details_text, '闪光灯').text #width if "未使用" in tmp: return False return True def case_get_title(self): """ 返回照片名称 :return: name(str) """ self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) self.test.find_byacc('更多选项').click() tmp = self.test.find_list_byid(gallery_details_title, '详细信息') tmp.click() tmp_name = self.test.find_list_byid(gallery_picture_details_text, '标题').text #width return tmp_name def case_play_item(self): """预览第一张照片或者视频""" self.case_if_base() self.test.find_byid(gallery_root_view).click() time.sleep(2) self.test.find_byid(action_bar_spinner).click() self.test.find_byclass(TextView, '幻灯片视图').click() time.sleep(5) actions = TouchAction(self.driver) actions.press(x=self.test.get_windows_width() / 2, y=self.test.get_windows_height() / 2).release().perform() time.sleep(1) actions.press(x=self.test.get_windows_width() / 2, y=self.test.get_windows_height() / 2).release().perform() time.sleep(5)
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()
class Doc_CaseMethod: 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() def case_if_base(self, Skip=False): """设置基础,检查是否可以正常启动""" try: self.driver.activate_app(doc_pkg) except: self.test.start_activity(doc_pkg, doc_acivity) self.Case.assertTrue(self.test.wait_if_activity(doc_acivity), '启动 文件管理器 失败,超时5秒未检测到主界面') self.test.set_PORTRAIT() time.sleep(1) def case_check_root_menu(self): self.case_if_base() self.test.find_byacc(doc_root_menu).click() time.sleep(0.2) tmp_list = self.test.find_byid_list(ID_title) isImages = False isVideos = False isAudio = False isRecent = False for x in tmp_list: t = x.text if '最近' in t: isRecent = True continue if '图片' in t: isImages = True continue if '视频' in t: isVideos = True continue if '音频' in t: isAudio = True continue if not isRecent or not isAudio or not isVideos or not isImages: self.Case.fail( f'文件菜单不满足:图片:{isImages},视频:{isVideos},音频:{isAudio},最近:{isRecent}' ) time.sleep(1) def case_new_and_del_folder(self): self.case_if_base() self.test.find_byacc(Menu).click() time.sleep(0.2) tmp_list = self.test.find_byid_list(doc_action_menu) for x in tmp_list: t = x.text if '新建文件夹' in t: x.click() time.sleep(0.5) break tmp_list = self.test.find_list_byclass(Edit_Text) if tmp_list is None: self.Case.fail('文件夹名称输入框不存在') tmp_list[0].clear() tmp_list[0].send_keys(f'doc_{self.new_name}') tmp_list = self.test.find_byclass(Button, '确定').click() time.sleep(0.3) tmp_list = self.test.find_byid_list(ID_title) isNew = False touchAction = TouchAction(self.driver) for y in tmp_list: t = y.text if f'doc_{self.new_name}' in t: isNew = True touchAction.long_press(y) time.sleep(1.5) touchAction.release().perform() break if not isNew: self.Case.fail(f'文件夹不存在:[doc_{self.new_name}]') self.test.find_byid(doc_search_and_del).click() time.sleep(0.3) self.test.find_byclass(Button, '确定').click() time.sleep(1) tmp_list = self.test.find_byid_list(ID_title) if tmp_list is None: return for z in tmp_list: t = z.text if f'doc_{self.new_name}' in t: self.Case.fail(f'doc_{self.new_name},未删除') time.sleep(1) def case_new_and_change_folder(self): self.case_if_base() self.test.find_byacc(Menu).click() time.sleep(0.2) tmp_list = self.test.find_byid_list(doc_action_menu) for x in tmp_list: t = x.text if '新建文件夹' in t: x.click() time.sleep(0.5) break tmp_list = self.test.find_list_byclass(Edit_Text) if tmp_list is None: self.Case.fail('文件夹名称输入框不存在') tmp_list[0].clear() tmp_list[0].send_keys(f'doc_new_{self.new_name}') tmp_list = self.test.find_byclass(Button, '确定').click() time.sleep(0.3) tmp_list = self.test.find_byid_list(ID_title) isNew = False touchAction = TouchAction(self.driver) for y in tmp_list: t = y.text if f'doc_new_{self.new_name}' in t: isNew = True touchAction.long_press(y) time.sleep(1.5) touchAction.release().perform() break if not isNew: self.Case.fail(f'文件夹不存在:[doc_new_{self.new_name}]') self.test.find_byacc(Menu).click() time.sleep(0.2) tmp_list = self.test.find_byid_list(doc_action_menu) for x in tmp_list: t = x.text if '重命名' in t: x.click() time.sleep(0.5) break tmp_list = self.test.find_list_byclass(Edit_Text) if tmp_list is None: self.Case.fail('文件夹名称输入框不存在') tmp_list[0].clear() tmp_list[0].send_keys(f'doc_old_{self.new_name}') tmp_list = self.test.find_byclass(Button, '确定').click() time.sleep(0.3) tmp_list = self.test.find_byid_list(ID_title) isNew = False for y in tmp_list: t = y.text if f'doc_old_{self.new_name}' in t: isNew = True break if not isNew: self.Case.fail(f'文件夹不存在:[doc_old_{self.new_name}]') time.sleep(1) def case_del_music(self): self.case_if_base() self.test.find_byacc(doc_root_menu).click() time.sleep(0.2) tmp_list = self.test.find_byid_list(ID_title) for x in tmp_list: t = x.text if '音频' in t: x.click() time.sleep(0.5) break tmp_list = self.test.find_byid_list(ID_title) touchAction = TouchAction(self.driver) isNew = False for y in tmp_list: t = y.text if f'张含韵' in t: isNew = True y.click() time.sleep(1) break if not isNew: self.Case.fail(f"未找到相关歌曲文件: 张含韵") tmp_list = self.test.find_byid_list(ID_title) for z in tmp_list: t = z.text if f'歌曲' in t: z.click() time.sleep(1) break tmp_list = self.test.find_byid_list(ID_title) for g in tmp_list: t = g.text if f'doc_music' in t: touchAction.long_press(g) time.sleep(1.5) touchAction.release().perform() break time.sleep(0.5) self.test.find_byid(doc_search_and_del).click() time.sleep(0.3) self.test.find_byclass(Button, '确定').click() time.sleep(1) tmp_list = self.test.find_byid_list(ID_title) if tmp_list is None: return for d in tmp_list: t = d.text if 'doc_music' in t: self.Case.fail(f'张含韵 music ,未删除') time.sleep(1)
class Contacts_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self): """设置基础,检查是否可以正常启动""" self.driver.activate_app(contacts_pkg) self.Case.assertTrue(self.test.wait_if_activity(contacts_activity), '启动设置失败,超时5秒未检测到主界面') def case_new_contacts(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) tmp = self.test.find_byid(contacts_new_item) tmp.click() time.sleep(1) try: self.driver.hide_keyboard() except selenium.common.exceptions.WebDriverException: pass if self.test.find_list_byid(contacts_id_text, '联系人备份到') is not None: self.test.find_byid(contacts_left_button).click() time.sleep(1) if not self.test.wait_if_activity(contacts_new_contacts_activity): self.Case.fail('未检测到新建联系人界面') if self.test.find_byid(contacts_save_type_show).text not in '设备': pass tmp_list = self.test.find_list_byclass(Edit_Text) text_number = Config.Config.devices_Config['testNumber'] text_number = f"{text_number}" for x in tmp_list: str = x.text if '姓氏' in str: x.clear() x.send_keys('meig') if '名字' in str: x.clear() x.send_keys('test') if '电话' in str: x.clear() x.send_keys(text_number) self.test.find_byid(contacts_save_button).click() time.sleep(1) if not self.test.wait_if_activity(contacts_show_activity): self.Case.fail('未检测到联系人预览界面') if 'test meig' not in self.test.find_byid( contacts_show_Photo).get_attribute('content-desc'): self.Case.fail('联系人名称不正确,非 test meig') tmp = self.test.find_byid(contacts_show_number).text tmp = re.sub(' ', '', tmp) if text_number not in tmp: self.Case.fail(f"联系人号码不正确,非 {text_number}") time.sleep(0.2) def case_del_contacts(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) tmp_list = self.test.find_list_byid(contacts_name_list, 'test meig') if tmp_list is None: self.driver.terminate_app(contacts_pkg) time.sleep(1) self.case_new_contacts() self.driver.terminate_app(contacts_pkg) time.sleep(1) self.case_if_base() time.sleep(1) tmp_list = self.test.find_list_byid(contacts_name_list, 'test meig') tmp_list.click() time.sleep(1) if not self.test.wait_if_activity(contacts_show_activity): self.Case.fail('未检测到联系人预览界面') if 'test meig' not in self.test.find_byid( contacts_show_Photo).get_attribute('content-desc'): self.Case.fail('联系人名称不正确,非 test meig') self.test.find_byacc(Menu).click() time.sleep(0.2) tme_list_name = self.test.find_byid_list(ID_title) for y in tme_list_name: str_name = y.text if '删除' in str_name: y.click() time.sleep(0.2) break tmp_text = self.test.find_byid(ID_message).text if '删除' not in tmp_text: self.Case.fail("未显示删除提示框") self.test.find_byclass(Button, '删除').click() if self.test.if_toast_text('已删除test meig') is None: self.Case.fail("未显示删除 提示 toast ") def case_change_contacts(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) tmp_list = self.test.find_list_byid(contacts_name_list, 'test meig') if tmp_list is None: self.driver.terminate_app(contacts_pkg) time.sleep(1) self.case_new_contacts() self.driver.terminate_app(contacts_pkg) time.sleep(1) self.case_if_base() time.sleep(1) tmp_list = self.test.find_list_byid(contacts_name_list, 'test meig') tmp_list.click() time.sleep(1) if not self.test.wait_if_activity(contacts_show_activity): self.Case.fail('未检测到联系人预览界面') if 'test meig' not in self.test.find_byid( contacts_show_Photo).get_attribute('content-desc'): self.Case.fail('联系人名称不正确,非 test meig') self.test.find_byid(contacts_edit_contacts).click() if not self.test.wait_if_activity(contacts_new_contacts_activity): self.Case.fail('未检测到新建联系人界面') if self.test.find_byid(contacts_save_type_show).text not in '设备': pass tmp_list = self.test.find_list_byclass(Edit_Text) text_number = '112' text_testNumber = Config.Config.devices_Config['testNumber'] text_testNumber = f"{text_testNumber}" for x in tmp_list: str = x.text tmp = re.sub(' ', '', str) if 'meig' in str: x.clear() x.send_keys('test') if 'test' in str: x.clear() x.send_keys('meig') if text_testNumber in tmp: x.clear() tmp_list = self.test.find_list_byclass(Edit_Text) for y in tmp_list: str_tmp = y.text if '电话' in str_tmp: y.send_keys(text_number) break self.test.find_byid(contacts_save_button).click() time.sleep(1) if not self.test.wait_if_activity(contacts_show_activity): self.Case.fail('未检测到联系人预览界面') if 'meig test' not in self.test.find_byid( contacts_show_Photo).get_attribute('content-desc'): self.Case.fail('联系人名称不正确,非 meig test') tmp = self.test.find_byid(contacts_show_number).text tmp = re.sub(' ', '', tmp) if text_number not in tmp: self.Case.fail(f"联系人号码不正确,非 {text_number}") time.sleep(0.2) self.driver.terminate_app(contacts_pkg) time.sleep(1) self.case_if_base() time.sleep(1) self._del_contact() def case_editcontacts_set_photo(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) name_list = self.test.find_byid_list(contacts_name_list) name_list[0].click() time.sleep(1) self.test.find_byid(contacts_contact_edit_button).click() time.sleep(1) self.test.find_byid(contacts_set_photo).click() time.sleep(1) self.test.find_byclass('android.widget.TextView', '拍照').click() time.sleep(1) self.test.find_byid(contacts_contact_camera_shutter).click() if not self.test.wait_if_activity(cam_Activity, 15): self.Case.fail('打开拍照界面失败') time.sleep(1) self.test.find_byid(contacts_contact_camera_ok_button).click() time.sleep(1) self.test.find_byid(contatcs_contact_camera_save_button).click() time.sleep(1) self.test.find_byid(contacts_save_button).click() time.sleep(1) if not self.test.wait_if_activity(contacts_show_activity, 15): self.Case.fail('保存头像失败') def case_editcontacts_set_telephonenumber(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) name_list = self.test.find_byid_list(contacts_name_list) name_list[0].click() time.sleep(1) self.test.find_byid(contacts_contact_edit_button).click() time.sleep(1) tmp_list = self.test.find_list_byclass(Edit_Text) telephone_text = Config.Config.devices_Config['testNumber'] telephone_text = f"{telephone_text}" for x in tmp_list: str = x.text if telephone_text in str: x.clear() time.sleep(0.1) tmp_list = self.test.find_list_byclass(Edit_Text) for y in tmp_list: str_tmp = y.text if telephone_text in str_tmp: y.send_keys('18721590681') break tmp_list = self.test.find_list_byclass(Edit_Text) for z in tmp_list: z_flag = 0 str_tmp = z.text if telephone_text in str_tmp: break z_flag += 1 if z_flag == len(tmp_list): self.Case.fail("设置电话号码失败") usage_button = self.test.find_list_byclass('android.widget.Spinner') usage_button[0].click() time.sleep(1) usage_list = self.test.find_list_byclass(CheckedTextView) for t in usage_list: str_tmp = t.text if '电话' in str_tmp: t.click() time.sleep(1) time.sleep(1) usage = self.test.find_list_byclass(TextView) for u in usage: str_tmps = u.text u_flag = 0 if '手机' in str_tmps: break u_flag += 1 if u_flag == len(usage): self.Case.fail("设置电话号码用途为手机失败") self.test.find_byid(contacts_save_button).click() time.sleep(1) if not self.test.wait_if_activity(contacts_show_activity, 15): self.Case.fail('保存联系人修改失败') def _del_contact(self): actions = TouchAction(self.driver) flag = False while True: time.sleep(1) contcat_list = self.test.find_list_byclass(TextView) if contcat_list is None: break for c in contcat_list: str_tmps = c.text if 'test' in str_tmps or '10086' in str_tmps: flag = True actions.long_press(c).release().perform() delete_contact_button = self.test.find_byid( contacts_delete_button) delete_contact_button.click() time.sleep(1) delete_contact_button_list = self.test.find_byclass( Button, '删除') delete_contact_button_list.click() break else: flag = False if not flag: break flag = False contcat_list = self.test.find_list_byclass(TextView) for x in contcat_list: t = x.text if 'meig test' in t: flag = True if flag: self.Case.fail('删除失败') def case_create_set_name_by_num_and_English(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) tmp = self.test.find_byid(contacts_new_item) tmp.click() time.sleep(1) edit_list = self.test.find_list_byclass(Edit_Text) for e in edit_list: str_tmps = e.text if '姓氏' in str_tmps: e.clear() e.send_keys('yidong') if '名字' in str_tmps: e.clear() e.send_keys('10086') self.test.find_byid(contacts_save_button).click() time.sleep(1) if not self.test.wait_if_activity(contacts_show_activity): self.Case.fail('未检测到联系人预览界面') if '10086 yidong' not in self.test.find_byid( contacts_show_Photo).get_attribute('content-desc'): self.Case.fail('联系人名称不正确,非 10086 yidong') def case_create_more_contacts_use_same_name(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) i = 0 for n in range(7): tmp = self.test.find_byid(contacts_new_item) tmp.click() time.sleep(1) edit_list = self.test.find_list_byclass(Edit_Text) first_name = 'test' + str(i) for e in edit_list: str_tmp = e.text if '姓氏' in str_tmp: e.clear() e.send_keys(first_name) if '名字' in str_tmp: e.clear() e.send_keys('meig') self.test.find_byid(contacts_save_button).click() time.sleep(1) name = 'meig ' + first_name if not self.test.wait_if_activity(contacts_show_activity): self.Case.fail('未检测到联系人预览界面') if name not in self.test.find_byid( contacts_show_Photo).get_attribute('content-desc'): self.Case.fail('联系人名称不正确,非 test meig') self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) if not self.test.wait_if_activity(contacts_activity): self.Case.fail("保存联系人信息失败") i += 1 time.sleep(3) name_list = self.test.find_list_byclass(TextView) if name_list is None: self.driver.press_keycode(KEY_BACK, 0, 0) name_list = self.test.find_list_byclass(TextView) time.sleep(1) j = 0 flag = False for e in name_list: srt_tmp = e.text name = 'test' + str(j) if j > 6: break if name not in srt_tmp: flag = False continue else: flag = True j += 1 if not flag: self.Case.fail("联系人并未按顺序排列") def case_check_detail_info(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) name_list = self.test.find_list_byclass(TextView) for e in name_list: str_tmps = e.text name = 'test meig' if name in str_tmps: e.click() time.sleep(1) break if not self.test.wait_if_activity(contacts_show_activity): self.Case.fail("未找到对应的联系人详细界面") if name not in self.test.find_byid(contacts_show_Photo).get_attribute( 'content-desc'): self.Case.fail('联系人名称不正确,非 test meig') info_list = self.test.find_list_byclass(TextView) telephone = Config.Config.devices_Config['testNumber'] telephone = f"{telephone}" class_name = '车载电话' t_flag = False c_flag = False for i in info_list: str_tmps = i.text str_tmps = str_tmps.replace(" ", "") if telephone in str_tmps: t_flag = True continue if class_name in str_tmps: c_flag = True continue if not t_flag: self.Case.fail("电话号码与联系人信息不符") if not c_flag: self.Case.fail("电话类别与联系人信息不符") def case_share_contact(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) contacts_list = self.test.find_list_byclass(TextView) name = 'test meig' actions = TouchAction(self.driver) for c in contacts_list: str_tmp = c.text if name in str_tmp: actions.long_press(c).release().perform() time.sleep(1) break self.test.find_byid(contacts_share_contact).click() time.sleep(1) buletooth_list = self.test.find_list_byclass(TextView) devices = 'Redmi' devices_name = "" for b in buletooth_list: str_tmp = b.text if devices in str_tmp: b.click() devices_name = str_tmp time.sleep(2) break check_text = "正在向“" + devices_name + "”发送文件" if self.test.if_toast_text(check_text) is None: self.Case.fail("分享联系人失败") def case_check_long_press_and_back(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) contacts_list = self.test.find_list_byclass(TextView) name = 'test meig' actions = TouchAction(self.driver) for c in contacts_list: str_tmp = c.text if name in str_tmp: actions.long_press(c).release().perform() time.sleep(1) break share_button = self.test.find_byid(contacts_share_contact) if share_button is None: self.Case.fail("长按列表项切换功能按钮失败") self.driver.press_keycode(KEY_BACK, 0, 0) name_list = self.test.find_list_byclass(TextView) n_flag = False for n in name_list: str_tmps = n.text if "通讯录" in str_tmps: n_flag = True if not n_flag: self.Case.fail("返回通讯录主列表失败") def case_hide_contact_frist_name(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) name_list = self.test.find_list_byclass(TextView) for n in name_list: str_tmps = n.text test_name = 'test meig' if test_name in str_tmps: n.click() time.sleep(1) break edit_button = self.test.find_byid(contacts_contact_edit_button) if edit_button is None: self.Case.fail("进入详细信息页面失败") edit_button.click() time.sleep(1) edit_list = self.test.find_list_byclass(Edit_Text) for e in edit_list: str_tmps = e.text if "meig" in str_tmps: e.clear() break save_contacts = self.test.find_byid(contacts_save_button) if save_contacts is None: self.Case.fail("保存联系人失败") save_contacts.click() time.sleep(1) name = "test" #print(name_list) if name not in self.test.find_byid(contacts_show_Photo).get_attribute( 'content-desc'): self.Case.fail('联系人名称不正确,非 test,隐藏姓氏失败') def case_show_contacts_first_name(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) name_list = self.test.find_list_byclass(TextView) for n in name_list: str_tmps = n.text test_name = 'test' if test_name == str_tmps: n.click() time.sleep(1) break edit_button = self.test.find_byid(contacts_contact_edit_button) if edit_button is None: self.Case.fail("进入详细信息页面失败") edit_button.click() time.sleep(1) edit_list = self.test.find_list_byclass(Edit_Text) for e in edit_list: str_tmps = e.text if '姓氏' in str_tmps: e.clear() e.send_keys('meig') save_contact = self.test.find_byid(contacts_save_button) save_contact.click() time.sleep(1) name = "test meig" if name not in self.test.find_byid(contacts_show_Photo).get_attribute( 'content-desc'): self.Case.fail('联系人名称不正确,非 test meig,显示姓氏失败') def case_collect_contact(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) name_list = self.test.find_list_byclass(TextView) name = 'test meig' for e in name_list: str_tmp = e.text if name == str_tmp: e.click() time.sleep(1) break collect_button = self.test.find_byid(contacts_collection_contact) collect_button.click() time.sleep(1) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) collect = self.test.find_list_byclass(ImageView) name = '常用联系人' for c in collect: str_tmp = c.get_attribute('content-desc') if name in str_tmp: c.click() time.sleep(1) break contact_name = 'test meig' if contact_name not in self.test.find_byid( contacts_show_Photo).get_attribute('content-desc'): self.Case.fail('联系人名称不正确,非 test meig,收藏联系人失败') def case_set_ring_sound(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) name_list = self.test.find_list_byclass(TextView) name = 'test meig' for e in name_list: str_tmp = e.text if name == str_tmp: e.click() time.sleep(1) break more_list = self.test.find_list_byclass(ImageButton) more = '更多选项' for m in more_list: str_tmp = m.get_attribute('content-desc') if more in str_tmp: m.click() time.sleep(1) break memu_list = self.test.find_list_byclass(TextView) memu = '设置铃声' for me in memu_list: str_tmp = me.text if memu in str_tmp: me.click() time.sleep(1) break sound_list = self.test.find_list_byclass(CheckedTextView) sound = 'Atria' for s in sound_list: str_tmp = s.text if sound in str_tmp: s.click() time.sleep(1) self.test.find_byclass(Button, '确定', True).click() time.sleep(1) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) break name1_list = self.test.find_list_byclass(TextView) name1 = 'test meig' for e in name1_list: str_tmp = e.text if name1 == str_tmp: e.click() time.sleep(1) break more1_list = self.test.find_list_byclass(ImageButton) more1 = '更多选项' for m in more1_list: str_tmp = m.get_attribute('content-desc') if more1 in str_tmp: m.click() time.sleep(1) break memu1_list = self.test.find_list_byclass(TextView) memu1 = '设置铃声' for me in memu1_list: str_tmp = me.text if memu1 in str_tmp: me.click() time.sleep(1) break sound1_list = self.test.find_list_byclass(CheckedTextView) sound1 = 'Atria' if sound1 not in sound1_list[0].text: self.Case.fail("设置铃声失败") self.test.find_byclass(Button, '取消', True).click() time.sleep(1) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) self._del_contact()
def setUpClass(cls) -> None: # 此方法,当前测试类执行前执行,即 测试初始化 cls.driver = TestResult.getDvicer() cls.caseMethod = Music_Video_CaseMethod(cls.driver, 'case_Music_A_test_if_base') test = Action(cls.driver)
class Camera_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self): """检查是否可以正常启动""" self.driver.activate_app(cam_Pkg) camHelpOk = self.test.find_byid(cam_help_ok) if camHelpOk is not None: camHelpOk.click() if self.driver.current_activity != cam_Activity: self.Case.assertTrue(self.test.wait_if_activity(cam_Launcher), '启动相机失败,超时5秒未检测到主界面') else: self.Case.assertTrue(self.test.wait_if_activity(cam_Activity), '启动相机失败,超时5秒未检测到主界面') time.sleep(1) def case_take_a_picture(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.driver.activate_app(cam_Pkg) self.Case.assertTrue(self.test.wait_if_activity(cam_Launcher), '启动相机失败,超时5秒未检测到主界面') time.sleep(3) shutterButton = self.test.find_byid(shutter_button) shutterButton.click() time.sleep(3) self.test.find_byid(cam_gallery_button).click() self.Case.assertTrue( self.test.wait_if_activity(gallery_activity, timeout=10), '打开照片预览失败,超时10秒未检测到主界面') time.sleep(1) actions = TouchAction(self.driver) actions.press(x=self.test.get_windows_width() / 2, y=self.test.get_windows_height() / 2).release().perform() def case_back_front_take_a_picture(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() time.sleep(3) tmp_button = self.test.find_byid(cam_flash_button) if tmp_button is not None: shutterButton = self.test.find_byid(shutter_button) shutterButton.click() time.sleep(2) self.test.find_byid(cam_front_back_switcher).click() time.sleep(2) else: self.test.find_byid(cam_front_back_switcher).click() time.sleep(2) shutterButton = self.test.find_byid(shutter_button) shutterButton.click() time.sleep(2) self.test.find_byid(cam_front_back_switcher).click() time.sleep(2) tmp_button = self.test.find_byid(cam_flash_button) if tmp_button is not None: self.Case.assertFalse(self.test.check_element(tmp_button), '预期不符,非前摄界面') shutterButton = self.test.find_byid(shutter_button) shutterButton.click() time.sleep(2) self.test.find_byid(cam_front_back_switcher).click() time.sleep(2) tmp_button = self.test.find_byid(cam_flash_button) self.Case.assertTrue(self.test.check_element(tmp_button), '预期不符,非后摄界面') time.sleep(1) def case_take_a_video(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() time.sleep(3) tmp = self.test.find_list_byid(cam_mode_set, "录像") if tmp is None: self.test.find_list_byid(cam_mode_set, "视频").click() else: tmp.click() time.sleep(1) self.test.find_byid(cam_video_shutter_button).click() time.sleep(3) self.test.find_byid(shutter_button).click() time.sleep(1) self.test.find_byid(cam_video_pause).click() time.sleep(1) self.test.find_byid(cam_video_shutter_button).click() time.sleep(2) self.test.find_byid(cam_video_shutter_button).click() time.sleep(3) self.test.find_byid(cam_video_shutter_button).click() time.sleep(1) def case_back_front_take_a_video(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() time.sleep(3) tmp = self.test.find_list_byid(cam_mode_set, "录像") if tmp is None: self.test.find_list_byid(cam_mode_set, "视频").click() else: tmp.click() time.sleep(1) tmp_button = self.test.find_byid(cam_flash_button) if tmp_button is None: self.test.find_byid(cam_front_back_switcher).click() time.sleep(2) self.test.find_byid(cam_video_shutter_button).click() time.sleep(3) self.test.find_byid(cam_video_shutter_button).click() time.sleep(1) self.test.find_byid(cam_front_back_switcher).click() time.sleep(2) self.test.find_byid(cam_video_shutter_button).click() time.sleep(3) self.test.find_byid(cam_video_shutter_button).click() time.sleep(1) def case_into_camera_by_camera_button(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) button_list = self.test.find_list_byclass(TextView) for b in button_list: str_tmp = b.text app_name = '骁龙相机' if app_name in str_tmp: b.click() time.sleep(3) break if not self.test.wait_if_activity(cam_Launcher): self.Case.fail("由相机快捷方式进入相机取景界面失败") def case_tack_landscape_photo(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() # TODO 设置为横屏 # self.test.set_LANDSCAPE() time.sleep(1) tmp_button = self.test.find_byid(cam_flash_button) if tmp_button is not None: shutterButton = self.test.find_byid(shutter_button) shutterButton.click() time.sleep(2) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) self.test.swipe_UP(600, 3) time.sleep(1) self.test.find_byid(cam_front_back_switcher).click() time.sleep(2) else: self.test.find_byid(cam_front_back_switcher).click() time.sleep(2) shutterButton = self.test.find_byid(shutter_button) shutterButton.click() time.sleep(2) self.test.find_byid(cam_front_back_switcher).click() time.sleep(2) tmp_button = self.test.find_byid(cam_flash_button) if tmp_button is not None: self.Case.assertFalse(self.test.check_element(tmp_button), '预期不符,非前摄界面') shutterButton = self.test.find_byid(shutter_button) shutterButton.click() time.sleep(2) self.test.find_byid(cam_front_back_switcher).click() time.sleep(2) tmp_button = self.test.find_byid(cam_flash_button) self.Case.assertTrue(self.test.check_element(tmp_button), '预期不符,非后摄界面') time.sleep(1) def case_use_flash_take_photo(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() sutterButton = self.test.find_byid(shutter_button) sutterButton.click() time.sleep(2) self.driver.press_keycode(KEY_BACK, 0, 0) self.test.swipe_Down(600, 1) time.sleep(1) photo_info = self._check_photo_info() if photo_info is not None: flash_status = '使用了闪光灯' flag = False for photo in photo_info: str_tmp = photo.text if flash_status in str_tmp: flag = True break if not flag: self.Case.fail("未开启闪光灯") else: self.Case.fail("未找到照片信息") def case_sleep_when_taking_photo(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() if self.test.wait_if_activity(cam_Launcher): self.driver.lock(3) if not self.test.wait_if_activity(cam_Launcher): self.Case.fail("设备休眠后唤醒,不在取景界面") def case_set_vedio_and_photo(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() mode_list = self.test.find_list_byclass(TextView) for mode in mode_list: str_tmp = mode.text if '录像' in str_tmp: mode.click() time.sleep(2) break vedio_shutter = self.test.find_byid(cam_video_shutter_button) vedio_shutter.click() time.sleep(3) vedio_shutter.click() time.sleep(3) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) for i in range(3): self.test.swipe_Down(600, 1) time.sleep(1) file_text = self._check_photo_info('.mp4').text if file_text is None: self.Case.fail("录像失败,未找到录像文件") self.driver.terminate_app(filemanager_pkg) app_list = self.test.find_list_byclass(TextView) for app in app_list: str_tmp = app.text if '骁龙相机' in str_tmp: app.click() time.sleep(3) break mode_list = self.test.find_list_byclass(TextView) for mode in mode_list: str_tmp = mode.text if '拍照' in str_tmp: mode.click() time.sleep(1) break shutterbutton = self.test.find_byid(shutter_button) shutterbutton.click() shut_time = self.driver.get_device_time("h") time.sleep(3) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(2) for i in range(3): self.test.swipe_Down(600, 1) file_info_list = self._check_photo_info() file_flag = False if file_info_list is not None: for file_info in file_info_list: str_tmp = file_info.text if '时间' in str_tmp: if shut_time in str_tmp: file_flag = True break if not file_flag: self.Case.fail("拍照后,未找到照片") def case_take_a_front_and_back_veido_and_play(self): if TestResult.getTestFail(self.failkey): self.skipTest('case_base test fail, skip this') self.case_if_base() mode_list = self.test.find_list_byclass(TextView) for mode in mode_list: str_tmp = mode.text if '录像' in str_tmp: mode.click() time.sleep(2) break vedio_shutter = self.test.find_byid(cam_video_shutter_button) vedio_shutter.click() time.sleep(3) vedio_shutter.click() time.sleep(1) switch_button = self.test.find_byid(cam_front_back_switcher) if switch_button is None: self.test.fail("未找到切换") switch_button.click() time.sleep(3) vedio_shutter.click() time.sleep(3) vedio_shutter.click() self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) self.driver.press_keycode(KEY_BACK, 0, 0) time.sleep(1) for i in range(3): self.test.swipe_Down(600, 1) time.sleep(1) file_name = self._check_photo_info('.mp4') file_name.click() time.sleep(3) def _check_photo_info(self, file_class='.jpg'): """检测拍照后的图片信息""" app_list = self.test.find_list_byclass(TextView) for a in app_list: str_tmp = a.text if '文件管理器' in str_tmp: a.click() time.sleep(2) break self.test.set_PORTRAIT() time.sleep(2) folder_list = self.test.find_list_byclass(TextView) for f in folder_list: str_tmp = f.text if 'DCIM' in str_tmp: f.click() time.sleep(3) break folder_second_list = self.test.find_list_byclass(TextView) for folder in folder_second_list: str_tmp = folder.text if 'Camera' in str_tmp: folder.click() time.sleep(3) break flie_list = self.test.find_list_byclass(TextView) for file in flie_list: str_tmp = file.text if file_class in str_tmp: if file_class == '.mp4': return file else: file.click() time.sleep(3) break more_flag = False while True: more_button = self.test.find_list_byclass(ImageButton) if more_button is None: actions = TouchAction(self.driver) actions.press(x=self.test.get_windows_width() / 2, y=self.test.get_windows_height() / 2).release().perform() time.sleep(3) else: for more in more_button: str_tmp = more.get_attribute('content-desc') if '更多选项' in str_tmp: more.click() time.sleep(3) break more_flag = True memu_list = self.test.find_list_byclass(TextView) for memu in memu_list: str_tmp = memu.text if '详细信息' in str_tmp: memu.click() time.sleep(3) break if more_flag: break info_list = self.test.find_list_byclass(TextView) self.driver.terminate_app(cam_Pkg) return info_list
class Record_CaseMethod: def __init__(self, dev, failkey): self.driver = dev self.test = Action(self.driver) self.Case = TestCase() self.failkey = failkey def case_if_base(self): """设置基础,检测是否正常启动""" self.driver.activate_app(record_pkg) self.Case.assertTrue(self.test.wait_if_activity(record_acivity), '启动设置失败,超时5秒未检测到主界面') def case_check_record_state(self): """检测当前录音状态""" if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() state = 0 record_text = self.test.find_byid(record_state).text if record_text == '录音中': # 检测当前状态 state = 1 return state elif record_text == '暂停': state = 2 return state return state def case_record_and_save(self): """录音与保存文件""" if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail,skip this') self.case_if_base() record = self.test.find_byid(record_recordbutton) if self.case_check_record_state() == 0: record.click() while self.test.wait_if_activity(Permissions_Activity, 5): self.test.find_byid(Permission_allow_button).click() time.sleep(3) log('info', f'开始录音') time.sleep(3) # 录音3s elif self.case_check_record_state() == 1: log('info', f'正在录音中') record_stop = self.test.find_byid(record_stopbutton) record_stop.click() time.sleep(3) record_name = self.test.find_byid(record_filename).text record_name = record_name + '.amr' record_save = self.test.find_byid(record_savebutton) record_save.click() time.sleep(3) file = self.test.find_list_byid(record_listfilename, record_name, True) self.Case.assertIsNotNone(file, '文件未保存') def case_play_recordflie(self): """播放录音文件""" if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail,skip this') self.case_if_base() record_list = self.test.find_byid(record_listbutton) record_list.click() time.sleep(3) filelist = self.test.find_byid_list(record_listfilename) play_name = filelist[0].text play_file = filelist[0] play_file.click() time.sleep(3) self.Case.assertTrue( play_name == self.test.find_byid(record_playtitle).text, '名称不正确') def case_delete_file(self): """删除录音文件""" if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail,skip this') self.case_if_base() play_filelayout = self.test.find_byid(record_filelayout) actions = TouchAction(self.driver) actions.long_press(play_filelayout).release().perform() time.sleep(3) file_delete = self.test.find_byid(record_deletebutton) actions.press(file_delete) time.sleep(3)
class FileManager_CaseMethod: 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() def case_if_base(self, Skip=False): """设置基础,检查是否可以正常启动""" try: self.driver.activate_app(filemanager_pkg) except: self.test.start_activity(filemanager_pkg, filemanager_acivity) if not Skip: if self.test.wait_if_activity(Permissions_Activity): self.test.find_byid(Permission_allow_button).click() time.sleep(1) self.Case.assertTrue(self.test.wait_if_activity(filemanager_acivity), '启动 文件管理器 失败,超时5秒未检测到主界面') self.test.set_PORTRAIT() time.sleep(1) def case_new_folder(self): self.case_if_base(True) self.test.find_byid(filemanager_action_menu).click() time.sleep(0.5) tme_list = self.test.find_list_byclass(TextView) for x in tme_list: tmp_text = x.text if '新建文件夹' in tmp_text: x.click() time.sleep(0.5) break tmp_edit = self.test.find_byid(filemanager_input_nanme_edit) tmp_edit.clear() tmp_edit.send_keys('A_new_test_meig') self.test.find_byclass(Button, '确定').click() time.sleep(1) self.Case.assertTrue(self._find_folder_or_file('A_new_test_meig'), '未找到新建的文件夹 [A_new_test_meig]') def case_del_folder(self): self.case_if_base(True) if not self._find_folder_or_file('A_new_test_meig'): self.driver.terminate_app(filemanager_pkg) time.sleep(1) self.case_new_folder() time.sleep(1) tmp = self.test.find_list_byid(filemanager_list_name, 'A_new_test_meig') touchAction = TouchAction(self.driver) touchAction.long_press(tmp) time.sleep(1.5) touchAction.release().perform() time.sleep(0.5) self._get_action('删除').click() time.sleep(0.5) tmp = self.test.find_byid(filemanager_action_menu_title).text if '确认删除' not in tmp: self.Case.fail('未显示 删除 确认对话框') self.test.find_byclass(Button, '是').click() time.sleep(1) self.Case.assertFalse(self._find_folder_or_file('A_new_test_meig'), '未删除文件夹 [A_new_test_meig]') def case_change_folder(self): self.case_if_base(True) if not self._find_folder_or_file('A_new_test_meig'): self.driver.terminate_app(filemanager_pkg) time.sleep(1) self.case_new_folder() time.sleep(1) tmp = self.test.find_list_byid(filemanager_list_name, 'A_new_test_meig') touchAction = TouchAction(self.driver) touchAction.long_press(tmp) time.sleep(1.5) touchAction.release().perform() time.sleep(0.5) self._get_action('重命名').click() time.sleep(0.5) tmp_edit = self.test.find_byid(filemanager_input_nanme_edit) tmp_edit.clear() tmp_edit.send_keys(f'A_new_{self.new_name}') self.test.find_byclass(Button, '确定').click() time.sleep(1) self.Case.assertTrue( self._find_folder_or_file(f'A_new_{self.new_name}'), f'未找到 重命名 的文件夹[A_new_{self.new_name}]') def case_check_file(self): self.case_if_base(True) tmp = self._find_folder_or_file('text_test.txt') #text_test.txt if not tmp: self.Case.fail('未找到 [text_test.txt]') tmp = self.test.find_list_byid(filemanager_list_name, 'text_test.txt') tmp.click() self.Case.assertTrue(self.test.wait_if_activity(HTML_Activity), '文本编辑器未打开') time.sleep(1) isPass = False for x in range(5): if self.test.find_byclass(View, '1234567890abc') is not None: time.sleep(0.5) isPass = True break if not isPass: self.Case.fail('未找到 文本内容 [1234567890abc]') self.driver.terminate_app(HTML_pkg) time.sleep(1) def case_change_name_file(self): self.case_if_base(True) tmp = self._find_folder_or_file('text_test.txt') #text_test.txt if not tmp: self.Case.fail('未找到 [text_test.txt]') tmp = self.test.find_list_byid(filemanager_list_name, 'text_test.txt') touchAction = TouchAction(self.driver) touchAction.long_press(tmp) time.sleep(1.5) touchAction.release().perform() time.sleep(0.5) self._get_action('重命名').click() time.sleep(0.5) tmp_edit = self.test.find_byid(filemanager_input_nanme_edit) tmp_edit.clear() tmp_edit.send_keys(f'text_test_{self.new_name}.txt') self.test.find_byclass(Button, '确定').click() time.sleep(1) self.Case.assertTrue( self._find_folder_or_file(f'text_test_{self.new_name}.txt'), f'未找到 重命名 的文件夹[text_test_{self.new_name}.txt]') def case_new_del_file(self): self.case_if_base(True) self.test.find_byid(filemanager_action_menu).click() time.sleep(0.5) tme_list = self.test.find_list_byclass(TextView) for x in tme_list: tmp_text = x.text if '新建文件' == tmp_text: x.click() time.sleep(0.5) break tmp_edit = self.test.find_byid(filemanager_input_nanme_edit) tmp_edit.clear() tmp_edit.send_keys(f'A_new_file_{self.new_name}') self.test.find_byclass(Button, '确定').click() time.sleep(1) self.Case.assertTrue( self._find_folder_or_file(f'A_new_file_{self.new_name}'), f'未找到新建的文件夹 [A_new_file_{self.new_name}]') tmp = self._find_folder_or_file( f'A_new_file_{self.new_name}') #text_test.txt if not tmp: self.Case.fail(f'未找到 [A_new_file_{self.new_name}]') tmp = self.test.find_list_byid(filemanager_list_name, f'A_new_file_{self.new_name}') touchAction = TouchAction(self.driver) touchAction.long_press(tmp) time.sleep(1.5) touchAction.release().perform() time.sleep(0.5) self._get_action('删除').click() time.sleep(0.5) tmp = self.test.find_byid(filemanager_action_menu_title).text if '确认删除' not in tmp: self.Case.fail('未显示 删除 确认对话框') self.test.find_byclass(Button, '是').click() time.sleep(1) self.Case.assertFalse( self._find_folder_or_file(f'A_new_file_{self.new_name}'), f'未删除文件夹 [A_new_file_{self.new_name}]') def case_set_sort(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) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_y, y_1 = self._get_checkbox_isTrue_number(tmp_checkbox) self._get_setting_menu('排列时区分大小写').click() time.sleep(0.5) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_x, x_1 = self._get_checkbox_isTrue_number(tmp_checkbox) if tmp_y == tmp_x: self.Case.fail('[排列时区区分大小写] ,设置失败') time.sleep(0.5) def case_set_Folder_statistics(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) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_y, y_1 = self._get_checkbox_isTrue_number(tmp_checkbox) self._get_setting_menu('计算文件夹统计数据').click() time.sleep(2) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_x, x_1 = self._get_checkbox_isTrue_number(tmp_checkbox) if tmp_y == tmp_x: if x_1 == y_1: self.Case.fail('[计算文件夹统计数据] ,设置失败') time.sleep(0.5) def case_set_preview(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) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_y, y_1 = self._get_checkbox_isTrue_number(tmp_checkbox) self._get_setting_menu('预览').click() time.sleep(0.5) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_x, x_1 = self._get_checkbox_isTrue_number(tmp_checkbox) if tmp_y == tmp_x: self.Case.fail('[预览] ,设置失败') time.sleep(0.5) def case_set_sub_user_Permission(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) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_y, y_1 = self._get_checkbox_isTrue_number(tmp_checkbox) self._get_setting_menu('限制用户访问').click() time.sleep(0.5) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_x, x_1 = self._get_checkbox_isTrue_number(tmp_checkbox) if tmp_y == tmp_x: self.Case.fail('[限制用户访问] ,设置失败') time.sleep(0.5) def case_set_save_log(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) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_y, y_1 = self._get_checkbox_isTrue_number(tmp_checkbox) tmp = self._get_setting_menu('记录调试信息') if tmp is None: time.sleep(1) return tmp.click() time.sleep(0.5) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_x, x_1 = self._get_checkbox_isTrue_number(tmp_checkbox) if tmp_y == tmp_x: self.Case.fail('[记录调试信息] ,设置失败') time.sleep(0.5) def case_set_swipe_del(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) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_y, y_1 = self._get_checkbox_isTrue_number(tmp_checkbox) tmp = self._get_setting_menu('使用滑动手势') tmp.click() time.sleep(0.5) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_x, x_1 = self._get_checkbox_isTrue_number(tmp_checkbox) if tmp_x <= tmp_y: self._get_setting_menu('使用滑动手势').click() time.sleep(0.5) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_x, x_1 = self._get_checkbox_isTrue_number(tmp_checkbox) if tmp_x < tmp_y: self.Case.fail('[使用滑动手势] ,设置失败') time.sleep(1) 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_set_search_CheckBox(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) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_1, y_1 = self._get_checkbox_isTrue_number(tmp_checkbox) self._get_setting_menu('高亮').click() time.sleep(0.5) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_2, y_1 = self._get_checkbox_isTrue_number(tmp_checkbox) self._get_setting_menu('显示相关部件').click() time.sleep(0.5) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_3, y_1 = self._get_checkbox_isTrue_number(tmp_checkbox) self._get_setting_menu('保存关键').click() time.sleep(0.5) tmp_checkbox = self.test.find_list_byclass(CheckBox) tmp_4, y_1 = self._get_checkbox_isTrue_number(tmp_checkbox) if tmp_1 != tmp_2 != tmp_3 != tmp_4: pass else: self.Case.fail( f'勾选框 设置失败:总计[{tmp_1}], 高亮 {tmp_2},显示相关部件 {tmp_3},保存关键字 {tmp_4}' ) time.sleep(0.5) def case_set_search_del_keyword(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) tmp = self._get_setting_menu('删除保存的关键') if tmp.get_attribute('enabled') == "false": self._get_setting_menu('保存关键').click() time.sleep(0.5) self._get_setting_menu('删除保存的关键').click() self.test.if_toast_text('已删除所有搜索关键字') time.sleep(0.5) def case_set_search_result_sort(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) tmp = self.test.find_list_byid(ID_summary, '按名称') self.Case.assertIsNotNone(tmp, '设置 [按名称] 失败') time.sleep(1) def case_edit_settings(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) self.test.find_list_byid(ID_title, '编辑器选项').click() time.sleep(1) tmp = self._get_setting_menu('不显示建议') if tmp is None: self.Case.fail('编辑器界面未打开') tmp_list = self.test.find_list_byclass(CheckBox) isOpen = 0 for y in tmp_list: bool = y.get_attribute('checked') if bool == 'true': isOpen += 1 tmp_list = self.test.find_byid_list(ID_title) for x in tmp_list: tmp_text = x.text if "不显示建议" in tmp_text: x.click() if "自动换行" in tmp_text: x.click() if "二进制文件" in tmp_text: x.click() if "高亮语法" in tmp_text: x.click() time.sleep(1) tmp_list = self.test.find_list_byclass(CheckBox) isOpen1 = 0 for z in tmp_list: bool = z.get_attribute('checked') if bool == 'true': isOpen1 += 1 if isOpen1 == isOpen: self.Case.fail('编辑器选项子开光操作失败') time.sleep(1) def case_check_about_view(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) self.test.find_list_byid(ID_title, '关于').click() time.sleep(1) tmp = None for x in range(3): tmp = self.test.find_byid(filemanager_dialog_title_text) if tmp is not None: break time.sleep(1) if tmp is None: self.Case.fail('关于界面未打开') def case_check_filesystem_info(self): self.case_if_base(True) time.sleep(0.5) self.test.find_byid(filemanager_filesystem_info).click() tmp = None for x in range(3): tmp = self.test.find_byid(filemanager_dialog_title_text) if tmp is not None: break time.sleep(1) if tmp is None: self.Case.fail('文件系统 界面未打开') tmp = self.test.find_byid(filemanager_filesystem_info_mount_point).text if "emulated" not in tmp: self.Case.fail("未检测到挂载点或者挂载点非{emulated}") self.test.find_byid( filemanager_filesystem_info_dialog_tab_disk_usage).click() time.sleep(1) tmp_total = self.test.find_byid( filemanager_filesystem_info_total_disk_usage).text tmp_used = self.test.find_byid( filemanager_filesystem_info_used_disk_usage).text tmp_free = self.test.find_byid( filemanager_filesystem_info_free_disk_usage).text try: tmp_total = re.search('[\d\\\.]+', tmp_total).group(0) tmp_used = re.search('[\d\\\.]+', tmp_used).group(0) tmp_free = re.search('[\d\\\.]+', tmp_free).group(0) except: self.Case.fail( f"正则匹配 空间大小数据失败,总共 {tmp_total}, 已使用 {tmp_used}, 剩余 {tmp_free}") try: if float(tmp_total) != (float(tmp_free) + float(tmp_used)): self.Case.fail( f"使用空间计算错误,总共 {tmp_total}, 已使用 {tmp_used}, 剩余 {tmp_free}") except ValueError: self.Case.fail( f"使用空间计算错误 ValueError ,总共 {tmp_total}, 已使用 {tmp_used}, 剩余 {tmp_free}" ) def case_set_sort_mode(self): self.case_if_base(True) time.sleep(0.5) for t in range(2): self.test.find_byid(filemanager_ab_configuration).click() tmp = None for x in range(3): tmp = self.test.find_byid(filemanager_ab_sort_mode) if tmp is not None: break time.sleep(1) if tmp is None: self.Case.fail('未找到 排列方式 按钮') tmp.click() tmp = None for x in range(3): if t == 0: tmp = self.test.find_list_byid( filemanager_option_list_item_text, '按名称排列 ▼') else: tmp = self.test.find_list_byid( filemanager_option_list_item_text, '按名称排列 ▲') if tmp is not None: break time.sleep(1) if tmp is None: self.Case.fail('未找到 排列方式 [按名称排列 ] 按钮') tmp.click() tmp = None for x in range(3): if t == 0: tmp = self.test.find_list_byid(filemanager_list_name, 'storage') else: tmp = self.test.find_list_byid(filemanager_list_name, 'Alarms') if tmp is not None: break time.sleep(1) if tmp is None: if t == 0: self.Case.fail('排列方式不正确,未按照字母表 降序') else: self.Case.fail('排列方式不正确,未按照字母表 升序') def case_set_layout_mode(self): self.case_if_base(True) time.sleep(0.5) for t in range(2): self.test.find_byid(filemanager_ab_configuration).click() tmp = None for x in range(3): tmp = self.test.find_byid(filemanager_ab_layout_mode) if tmp is not None: break time.sleep(1) if tmp is None: self.Case.fail('未找到 布局 按钮') tmp.click() tmp = None for x in range(3): if t == 0: tmp = self.test.find_list_byid( filemanager_option_list_item_text, '图标') else: tmp = self.test.find_list_byid( filemanager_option_list_item_text, '详细信息') if tmp is not None: break time.sleep(1) if tmp is None: self.Case.fail('未找到 布局方式 按钮') tmp.click() time.sleep(1) def case_check_menu_list(self): self.case_if_base(True) time.sleep(0.5) self.test.find_byid(filemanager_action_menu).click() for x in range(3): if self.test.find_byid(filemanager_action_menu_title) is not None: break time.sleep(1) tmp = self.test.find_list_byclass(TextView) tmp_int = 0 for x in tmp: tmp_text = x.text if "属性" == tmp_text: tmp_int += 1 if "刷新" == tmp_text: tmp_int += 1 if "新建文件夹" == tmp_text: tmp_int += 1 if "新建文件" == tmp_text: tmp_int += 1 if "全部选择" == tmp_text: tmp_int += 1 if "取消全选" == tmp_text: tmp_int += 1 if "添加到书签" == tmp_text: tmp_int += 1 if "添加快捷方式" == tmp_text: tmp_int += 1 if "设置为主页" == tmp_text: tmp_int += 1 time.sleep(0.3) if tmp_int != 9: self.Case.fail(f'菜单不正确,没有9个,实际{tmp_int}') def case_check_file_info(self): self.case_if_base(True) tmp = self._find_folder_or_file('text_test_view.txt') #text_test.txt if not tmp: self.Case.fail('未找到 [text_test_view.txt]') tmp = self.test.find_list_byid(filemanager_list_name, 'text_test_view.txt') touchAction = TouchAction(self.driver) touchAction.long_press(el=tmp).release().perform() time.sleep(1) self._get_action("属性").click() tmp_int = 0 for x in range(3): if self.test.find_byid(filemanager_action_menu_title) is not None: break time.sleep(1) tmp = self.test.find_list_byclass(TextView) for x in tmp: tmp_text = x.text if "text_test_view.txt" == tmp_text: tmp_int += 1 if "text/plain" == tmp_text: tmp_int += 1 if "文本" == tmp_text: tmp_int += 1 time.sleep(0.4) if tmp_int != 3: self.Case.fail( f'文件名称、类型或者类别不正确,非 text_test_view.txt text/plain 文本') def case_click_refresh(self): self.case_if_base(True) time.sleep(0.5) self.test.find_byid(filemanager_action_menu).click() for x in range(3): if self.test.find_byid(filemanager_action_menu_title) is not None: break time.sleep(1) self._get_action("刷新").click() time.sleep(1) def case_check_png(self): self.case_if_base(True) time.sleep(0.5) tmp = self._find_folder_or_file('picture_11.png') #text_test.txt if not tmp: self.Case.fail('未找到 [picture_11.png]') tmp = self.test.find_list_byid(filemanager_list_name, 'picture_11.png') tmp.click() self.Case.assertTrue(self.test.wait_if_activity(gallery_activity), "图片未打开") time.sleep(0.5) self.driver.press_keycode(KEY_BACK, 0, 0) self.Case.assertTrue(self.test.wait_if_activity(filemanager_acivity), "未返回到文件管理器界面") time.sleep(0.5) def case_check_gif(self): self.case_if_base(True) time.sleep(0.5) tmp = self._find_folder_or_file('picture_12.gif') #text_test.txt if not tmp: self.Case.fail('未找到 [picture_12.gif]') tmp = self.test.find_list_byid(filemanager_list_name, 'picture_12.gif') tmp.click() self.Case.assertTrue(self.test.wait_if_activity(gallery_activity), "图片未打开") time.sleep(0.5) self.driver.press_keycode(KEY_BACK, 0, 0) self.Case.assertTrue(self.test.wait_if_activity(filemanager_acivity), "未返回到文件管理器界面") time.sleep(0.5) def case_check_music(self): self.case_if_base(True) time.sleep(0.5) tmp = self._find_folder_or_file('music_') #text_test.txt if not tmp: self.Case.fail('未找到 [music_]') tmp = self.test.find_list_byid(filemanager_list_name, 'music_') tmp.click() self.Case.assertTrue( self.test.wait_if_activity( music_video_music_AudioPreview_Activity), "播放音乐界面未打开") time.sleep(0.5) tmp = None for x in range(3): tmp = self.test.find_byid(music_video_music_progress) if tmp is not None: break self.Case.assertIsNotNone(tmp, '未检测到播放进度条') self.driver.press_keycode(KEY_BACK, 0, 0) self.Case.assertTrue(self.test.wait_if_activity(filemanager_acivity), "未返回到文件管理器界面") time.sleep(0.5) def case_check_video(self): self.case_if_base(True) time.sleep(0.5) tmp = self._find_folder_or_file('video_') #text_test.txt if not tmp: self.Case.fail('未找到 [video_]') tmp = self.test.find_list_byid(filemanager_list_name, 'video_') tmp.click() self.Case.assertTrue( self.test.wait_if_activity(music_video_Movie_acivity), "视频界面未打开") time.sleep(2) self.driver.press_keycode(KEY_BACK, 0, 0) self.Case.assertTrue(self.test.wait_if_activity(filemanager_acivity), "未返回到文件管理器界面") time.sleep(0.5) def case_Bluetooth_share(self): self.case_if_base(True) time.sleep(0.5) tmp = self._find_folder_or_file('text_test_view.txt') #text_test.txt if not tmp: self.Case.fail('未找到 [text_test_view.txt]') tmp = self.test.find_list_byid(filemanager_list_name, 'text_test_view.txt') touchAction = TouchAction(self.driver) touchAction.long_press(el=tmp).release().perform() time.sleep(1) self._get_action("发送").click() tmp = None for x in range(3): tmp = self.test.find_list_byid(filemanager_associations_item_text, "蓝牙") if tmp is not None: break time.sleep(1) tmp.click() time.sleep(1) tmp = self.test.find_list_byid(filemanager_associations_item_text, "蓝牙") if tmp is not None: tmp.click() self.Case.assertTrue(self.test.wait_if_activity(Bluetooth_share), '蓝牙分享界面未显示') tmp_list = None for x in range(5): tmp_list = self.test.find_byid_list(ID_title) tmp_int = len(tmp_list) if tmp_int > 4: break time.sleep(1) tmp_list[len(tmp_list) - 1].click() time.sleep(1) def _find_folder_or_file(self, textkey): for y in range(10): if self.test.find_list_byid(filemanager_list_name, textkey) is not None: return True self.test.swipe_Down(600, 1) time.sleep(0.3) return False def _get_action(self, keytext): tme_list = self.test.find_list_byclass(TextView) for x in tme_list: tmp_text = x.text if keytext in tmp_text: return x return None def _get_checkbox_isTrue_number(self, list_checkbox): y = 0 for x in list_checkbox: if 'true' in x.get_attribute('checked'): y += 1 return y, len(list_checkbox) def _get_setting_menu(self, keytext): for x in range(5): tmp = self.test.find_list_byid(ID_title, keytext) if tmp is not None: return tmp self.test.swipe_Down(600, 1) time.sleep(1) return None