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 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