class WidevineTest(UIATestBase): """ @summary: Test Widevine """ config = TestConfig() def setUp(self): """ @summary: set up @return: None """ super(WidevineTest, self).setUp() self.d = g_common_obj.get_device() self._test_name = __name__ self.video_button_widget_dict = { "play": "android:id/pause", "pause": "android:id/pause", "volume_up": "volume_up", "volume_down": "volume_down", "back": "back" } print "[Setup]: %s" % self._test_name def tearDown(self): """ @summary: tear tearDown @return: None """ super(WidevineTest, self).tearDown() print "[Teardown]: %s" % self._test_name g_common_obj.stop_exp_handle() def appPrepare(self, model=1): self.cfg_file = os.path.join(os.environ.get('TEST_DATA_ROOT', ''), \ 'tests.tablet.mum_auto_drm.conf') self.cfg = self.config.read(self.cfg_file, self.case_name) self.multimedia_handle = MultiMediaHandle() self.multimedia_setting = MultiMediaSetting(self.cfg_file) self.multimedia_drm_helper = MultiMediaDRMHelper() self.multimedia_setting.install_apk( "widevine_apk") #install widevine apk self.widevine_package_name, self.widevine_activity_name = self.multimedia_setting.get_package_and_activity_name( "widevine_apk") if model == 1: # play local video mode self.dst_path = self.cfg.get("dst_path") self.clearResourcefolder() self.dst_path = self.multimedia_setting.push_file_new( self.cfg.get("src_path"), self.dst_path) #push video file to device elif model == 2: # play network video mode self.src_path = self.cfg.get("src_path") # g_common_obj.set_vertical_screen() g_common_obj.stop_app_am(self.widevine_package_name) g_common_obj.adb_cmd_capture_msg("input keyevent 82") #Unlock screen def disableVerityDUT(self): serial = self.d.server.adb.device_serial() result = os.popen("adb -s %s disable-verity" % serial).read() logger.debug("result=%s" % result) assert "version" not in result and "error" not in result, "Please update sdk version!" assert "fail" not in result and "error" not in result, "The DUT can't disable-verity, please reboot and check it" def remountDUT(self): serial = self.d.server.adb.device_serial() os.system("adb -s %s remount" % serial) time.sleep(3) result = os.popen("adb -s %s remount" % serial).read() logger.debug("result=%s" % result) assert "fail" not in result and "error" not in result, "The DUT can't remount, please reboot and check it" def getDeviceTypeMapCfg(self): if "device_type_map" not in dir(self): self.device_type_map_cfg = self.config.read( self.cfg_file, "device_type_map") return self.device_type_map_cfg def executeCommandWithPopen(self, cmd): logger.debug(cmd) # return subprocess.Popen(cmd, shell=True) return subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) def clearResourcefolder(self): g_common_obj.adb_cmd_capture_msg("rm -rf %s" % os.path.split(self.dst_path)[0]) def launchWidevineApp(self): SystemUI().unlock_screen() # g_common_obj.stop_app_am(self.widevine_package_name) g_common_obj.launch_app_am(self.widevine_package_name, self.widevine_activity_name) time.sleep(5) for _ in range(5): if self.d(textContains="Downloads").exists: return time.sleep(5) assert self.d( textContains="Downloads").exists, "launch Winevine App failed!" def findVideoExistInWidevineApp(self, video_name): logger.debug("findVideoExistInWidevineApp video_name=%s" % video_name) time.sleep(5) for _ in range(10): if self.d(textContains=video_name).exists: break self.d(text=">>").click() time.sleep(20) assert self.d(textContains=video_name ).exists, "Video not exist! video_name=%s" % video_name bounds = self.d(textContains=video_name).info["bounds"] x = bounds["left"] + (bounds["right"] - bounds["left"]) / 2 y = bounds["top"] - (bounds["bottom"] - bounds["top"]) / 2 self.d.click(x, y) def clear_edit_text_layout(self, layout): while layout.text != "": layout.clear_text() def setContentPage(self, path): self.d(text="Settings").click() time.sleep(2) edit_text_layout = self.d( className="android.widget.EditText", resourceId="com.widevine.demo:id/content_page") if edit_text_layout.text != path: self.clear_edit_text_layout(edit_text_layout) edit_text_layout.set_text(path) self.d.press.back() time.sleep(1) self.d(text="Update Button").click() self.d(text="Ok").click() def wait_boot_completed(self, timeout=1000): ''' wait Android boot_completed args: timeout -- optional timeout in second, default 1000s ''' count = 0 sleep_time = 5 while count < timeout: prop_val = adb.adb_cmd_capture_msg('getprop sys.boot_completed') if '1' in prop_val: print 'boot_completed' return count += sleep_time time.sleep(sleep_time) raise Exception('%ds timeout waiting for boot_completed' % timeout) def widevineVideoPlayBack(self): self.d(text="Downloads").click() time.sleep(5) dst_name = os.path.split(self.dst_path)[1] assert self.d( textContains=dst_name ).exists, "resource file not exist! file_name=%s" % dst_name self.d(className="android.widget.ImageView", index="0").click() time.sleep(5) self.d(text="Acquire Rights").click() time.sleep(3) acquire_rights_value = -1 for _ in range(3): widevine_value = self.getWidevineValue() logger.debug("widevine_value=%s" % widevine_value) if "acquireRights" in widevine_value and "Rights installed" in widevine_value: acquire_rights_value = self.getWidevineValue_acquireRights() logger.debug("acquire_rights_value=%s" % str(acquire_rights_value)) break time.sleep(3) assert "error" not in widevine_value and "fail" not in widevine_value, "error widevine_value!! widevine_value=%s" % widevine_value assert acquire_rights_value == 0, "error acquire_rights_value!!! acquire_rights_value=%d" % acquire_rights_value self.d(text="Play").click() def widevineStreamingVideoPlayBack(self): self.d(text="Streaming").click() time.sleep(5) video_index = self.findVideoExistInWidevineApp(self.src_path) self.d(className="android.widget.ImageView", index=video_index).click() time.sleep(5) self.d(text="Acquire Rights").click() time.sleep(3) acquire_rights_value = -1 for _ in range(10): widevine_value = self.getWidevineValue() logger.debug("widevine_value=%s" % widevine_value) if "acquireRights" in widevine_value and "Rights installed" in widevine_value: acquire_rights_value = self.getWidevineValue_acquireRights() logger.debug("acquire_rights_value=%s" % str(acquire_rights_value)) break time.sleep(3) assert "error" not in widevine_value and "fail" not in widevine_value, "error widevine_value!! widevine_value=%s" % widevine_value assert acquire_rights_value == 0, "error acquire_rights_value!!! acquire_rights_value=%d" % acquire_rights_value self.d(text="Play").click() def getWidevineValue(self): self.widevine_value_text = self.d( className="android.widget.TextView").text return self.widevine_value_text def get_acquire_rights_pattern(self): if "acquire_rights_pattern" not in dir(self): GET_ACQUIRERIGHTS_PATTERN = ".*acquireRights = (.*)\n.*" self.acquire_rights_pattern = re.compile(GET_ACQUIRERIGHTS_PATTERN) return self.acquire_rights_pattern def getWidevineValue_acquireRights(self): try: acquire_rights_pattern = self.get_acquire_rights_pattern() widevine_value = self.getWidevineValue() acquire_rights_value = acquire_rights_pattern.findall( widevine_value) acquire_rights_value = int(acquire_rights_value[0]) except Exception as e: logger.debug("widevine_value=%s" % widevine_value) logger.debug("acquire_rights_value=%s" % str(acquire_rights_value)) assert 0, e return acquire_rights_value def getPlatform(self): cmd = "adb shell getprop ro.board.platform" platform = os.popen(cmd).read() platform = platform.replace("\n", "", 1) return platform.strip() def getDeviceTypeMapNum(self): device_platform = self.getPlatform() device_platform = device_platform.lower() if "sofia_lte" in device_platform: num = 2 else: num = 1 # num = self.getDeviceTypeMapCfg().get(device_platform) return num def clickScreen(self): self.multimedia_setting.clickScreen() def click_widget(self, t_widget): try: t_widget.click() self.s_t_text = 0 except Exception as e: logger.debug("click_widget error:%s" % e) self.s_t_text = -2 assert 0, "click_widget error:%s" % e def get_widget(self, t_str): logger.debug("get_widget---t_str=%s" % t_str) assert t_str in self.video_button_widget_dict, "%s not in video_button_widget_dict!" % t_str t_resource_id = self.video_button_widget_dict[t_str] if t_resource_id == t_str: return t_resource_id else: return self.d(resourceId=t_resource_id) def widget_operation_with_thread(self, t_str, t_operation): self.s_t_text = -1 t_widget = self.get_widget(t_str) if t_operation == "click": thread.start_new_thread(self.click_widget, (t_widget, )) else: assert 0, "Error operation!" while self.s_t_text == -1: if not t_widget.exists: self.clickScreen() time.sleep(1) return self.s_t_text def click_button(self, t_str): logger.debug("click_button---t_str=%s" % t_str) t_widget = self.video_button_widget_dict[t_str] if t_str != t_widget: result = self.widget_operation_with_thread(t_str, "click") assert result == 0, "click failed! reselt=%d" % result else: getattr(self.d.press, t_widget)() def checkVideoPlayBackWithWidevine(self): self.launchWidevineApp() # launch widevine app self.widevineVideoPlayBack() # play video file time.sleep(10) assert not self.d( textContains="can't" ).exists, "video playback failed!" #check play status of video time.sleep(140) assert not self.d( textContains="can't" ).exists, "video playback failed!" #check play status of video def checkStreamingVideoPlayBackWithWidevine(self): self.launchWidevineApp() self.setContentPage(self.cfg.get("web_page")) self.widevineStreamingVideoPlayBack() time.sleep(10) assert not self.d( textContains="can't").exists, "video playback failed!" time.sleep(140) assert not self.d( textContains="can't").exists, "video playback failed!" def checkVideoPlayBackWithClickButton(self, click_list): self.launchWidevineApp() # launch widevine app self.widevineVideoPlayBack() # play video file time.sleep(10) assert not self.d( textContains="can't" ).exists, "video playback failed!" #check play status of video for t_str in click_list: if t_str == "sleep": time.sleep(5) else: self.click_button(t_str) time.sleep(2) time.sleep(60) assert not self.d( textContains="can't" ).exists, "video playback failed!" #check play status of video def winevine_main_test(self, sub_func_name="", model=1, *arg, **keywords): """ This test used to test WinevineApp App The test case spec is following: 1. Start record video 2. do sub_func() 3. Stop record video """ self.case_name = sys._getframe().f_back.f_code.co_name if sub_func_name == "": sub_func_name = "%s_sub_func" % self.case_name logger.debug("case_name=%s" % self.case_name) logger.debug("exoplayer_main_test---sub_func_name=%s" % sub_func_name) self.appPrepare(model) try: self.multimedia_drm_helper.startRecord( self.case_name) #start record logger.debug("Arbitrary parameter is %s" % str(arg)) logger.debug("keywords parameter is %s" % str(keywords)) getattr(self, sub_func_name)(*arg, **keywords) self.d.press.back() self.d.press.back() self.d.press.home() if model == 1: self.clearResourcefolder() time.sleep(1) self.multimedia_drm_helper.stopRecord() #stop record except Exception as e: self.multimedia_drm_helper.stopRecord() assert 0, e assert 0, "Playback complete! Please check video!" logger.debug("Case %s is pass!" % self.case_name) def test_video_playback_with_check_S0I3(self): self.case_name = sys._getframe().f_back.f_code.co_name self.appPrepare() after_S0I3_str = self.multimedia_setting.getS0I3() self.launchWidevineApp() self.widevineVideoPlayBack() time.sleep(10) assert not self.d( textContains="can't").exists, "video playback failed!" self.d.press.power() logger.debug("Step: sleep 800s, please wait...") time.sleep(800) logger.debug("Step: sleep 800s, complete!") self.d.press.power() SystemUI().unlock_screen() self.d.press.back() self.d.press.home() before_S0I3_str = self.multimedia_setting.getS0I3() assert after_S0I3_str != before_S0I3_str, "after_S0I3_str=%s, before_S0I3_str=%s" % ( after_S0I3_str, before_S0I3_str) def checkVideoPlayBackWithWidevineWithReboot(self, t_time): self.case_name = sys._getframe().f_back.f_code.co_name self.appPrepare() self.launchWidevineApp() self.widevineVideoPlayBack() time.sleep(20) assert not self.d( textContains="can't").exists, "video playback failed!" for _ in range(t_time): adb.reboot_device() self.wait_boot_completed() time.sleep(20) self.launchWidevineApp() self.widevineVideoPlayBack() time.sleep(20) assert not self.d( textContains="can't").exists, "video playback failed!" def checkProvision(self): self.case_name = sys._getframe().f_back.f_code.co_name logger.debug("case_name=%s" % self.case_name) self.appPrepare(0) if "false" == self.cfg.get("test"): logger.debug("Case %s is skip auto test!" % self.case_name) return num = self.getDeviceTypeMapNum() if num == 1: g_common_obj.root_on_device() self.disableVerityDUT() adb.reboot_device() self.wait_boot_completed() g_common_obj.root_on_device() self.remountDUT() time.sleep(3) bin_src_path = self.getDeviceTypeMapCfg().get("%s_bin_src_path" % (num)) bin_dst_path = self.getDeviceTypeMapCfg().get("%s_bin_src_path" % (num)) bin_src_path = self.multimedia_setting.download_file_to_host( bin_src_path) bin_src_folder = os.path.split(bin_src_path)[0] bin_dst_filename = os.path.split(bin_dst_path)[1] unzip_cmd = self.getDeviceTypeMapCfg().get("unzip_command") self.executeCommandWithPopen(unzip_cmd % (bin_src_path, bin_src_folder)) bin_src_path = os.path.join(bin_src_folder, bin_dst_filename) bin_dst_path = self.multimedia_setting.push_file_to_dut( bin_src_path, bin_dst_path) tools_src_path = self.getDeviceTypeMapCfg().get("%s_tool_src_path" % (num)) tools_dst_path = self.getDeviceTypeMapCfg().get("%s_tool_dst_path" % (num)) tools_dst_path = self.multimedia_setting.push_file_new( tools_src_path, tools_dst_path) g_common_obj.adb_cmd_capture_msg("chmod 777 %s" % tools_dst_path) time.sleep(5) i = 1 while "%s_execute_command_%s" % (num, i) in self.getDeviceTypeMapCfg(): cmd = self.getDeviceTypeMapCfg().get("%s_execute_command_%s" % (num, i)) fdp = self.executeCommandWithPopen(cmd) time.sleep(3) stdout_log = fdp.stdout.read() assert "cannot" not in stdout_log and "error" not in stdout_log and "fail" not in stdout_log and "not found" not in stdout_log, "(%s) cmd error: %s" % ( cmd, stdout_log) i += 1 logger.debug("Case %s is pass!" % self.case_name) def testWVClassicPlayback_WVDemo_Local_720p(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_Local_1080p(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_Local_360(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_SD(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_Local_480p(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_HD_Local(self): self.winevine_main_test("checkVideoPlayBackWithWidevine") def testWVClassic_WVDemo_WiFi_360p(self): self.winevine_main_test("checkStreamingVideoPlayBackWithWidevine", 2) def testWVClassic_WVDemo_WiFi_480P(self): self.winevine_main_test("checkStreamingVideoPlayBackWithWidevine", 2) def testWVClassic_WVDemo_WiFi_720p(self): self.winevine_main_test("checkStreamingVideoPlayBackWithWidevine", 2) def testWVClassic_WVDemo_WiFi_1080p(self): self.winevine_main_test("checkStreamingVideoPlayBackWithWidevine", 2) def testWVClassic_WVDemo_Menu_Interaction(self): self.winevine_main_test("checkVideoPlayBackWithClickButton", 1, ["volume_up"] * 4 + ["sleep"] + ["volume_down"] * 4) def testWVClassic_WVDemo_Volume_Adjustment_Paused(self): self.winevine_main_test("checkVideoPlayBackWithClickButton", 1, ["pause"] + ["volume_up"] * 10 + ["sleep"] + ["volume_down"] * 10 + ["play"] + ["volume_down"] * 10 + ["pause"]) def testWVClassic_Reboot_Multi_Times(self): self.checkVideoPlayBackWithWidevineWithReboot(20) def testWVClassic_Resume_S0i3(self): self.test_video_playback_with_check_S0I3() def testProvisionKeyBox_Reboot(self): self.checkProvision() def testWVClassic_Provision(self): self.checkProvision()
class ExoPlayerTest(UIATestBase): """ @summary: Test Widevine """ config = TestConfig() def setUp(self): """ @summary: set up @return: None """ super(ExoPlayerTest, self).setUp() self.d = g_common_obj.get_device() self._test_name = __name__ self.playback_state_str = "playbackState" self.video_button_index_dict = { "Paused": 1, "Play": 1, "Forward": 2, "Backward": 0 } print "[Setup]: %s" % self._test_name def tearDown(self): """ @summary: tear tearDown @return: None """ super(ExoPlayerTest, self).tearDown() print "[Teardown]: %s" % self._test_name g_common_obj.stop_exp_handle() def appPrepare(self, model=1): self.cfg_file = os.path.join(os.environ.get('TEST_DATA_ROOT', ''), \ 'tests.tablet.mum_auto_drm.conf') self.cfg = self.config.read(self.cfg_file, self.case_name) # read config file self.multimedia_setting = MultiMediaSetting(self.cfg_file) self.multimedia_drm_helper = MultiMediaDRMHelper() self.multimedia_video_quality_helper = MultiMediaVideoQualityHelper() self.multimedia_setting.install_apk( "exoplayer_apk") #install exoplayer apk self.exoplayer_package_name, self.exoplayer_activity_name = self.multimedia_setting.get_package_and_activity_name( "exoplayer_apk") #get app info # g_common_obj.set_vertical_screen() g_common_obj.stop_app_am(self.exoplayer_package_name) g_common_obj.adb_cmd_capture_msg("input keyevent 82") #Unlock screen def clickScreen(self): self.multimedia_setting.clickScreen() def launchEXOPlayerApp(self): SystemUI().unlock_screen() # g_common_obj.stop_app_am(self.widevine_package_name) g_common_obj.launch_app_am(self.exoplayer_package_name, self.exoplayer_activity_name) time.sleep(5) for _ in range(5): if self.d(textContains="ExoPlayer Demo").exists: return time.sleep(5) assert self.d(textContains="ExoPlayer Demo" ).exists, "launch Exoplayer App failed!" def get_playback_state_pattern(self): if "playback_state_pattern" not in dir(self): GET_PLAYBACKSTATE_PATTERN = "playbackState=(.*)" self.playback_state_pattern = re.compile(GET_PLAYBACKSTATE_PATTERN) return self.playback_state_pattern def getPlaybackState(self): playback_state_str = self.playback_state_str for _ in range(3): if not self.d(textContains=playback_state_str).exists: self.clickScreen() time.sleep(1) assert self.d(textContains=playback_state_str ).exists, "playbackState not exist! please check it!" status = self.d(textContains=playback_state_str).text logger.debug("all_status=%s" % status) playback_state_pattern = self.get_playback_state_pattern() playback_state = playback_state_pattern.findall(status) logger.debug("playback_state=%s" % str(playback_state)) return playback_state[0] def checkPlaybackState(self): for _ in range(5): playback_state = self.getPlaybackState() if playback_state == "ready": return 0 time.sleep(5) assert 0, "Error! playback_state=%s" % playback_state def clickVideoButton(self, t_str): logger.debug("clickVideoButton---t_str=%s" % t_str) assert t_str in self.video_button_index_dict, "%s not in video_button_index_dict!" % t_str t_index = self.video_button_index_dict[t_str] if not self.d(className="android.widget.ImageButton", index=t_index).exists: self.clickScreen() self.d(className="android.widget.ImageButton", index=t_index).click() def wait_boot_completed(self, timeout=1000): ''' wait Android boot_completed args: timeout -- optional timeout in second, default 180s ''' count = 0 sleep_time = 5 while count < timeout: prop_val = adb.adb_cmd_capture_msg('getprop sys.boot_completed') if '1' in prop_val: print 'boot_completed' return count += sleep_time time.sleep(sleep_time) raise Exception('%ds timeout waiting for boot_completed' % timeout) def clickRetryButton(self): retry_str = "Retry" if not self.d(text=retry_str).exists: self.clickScreen() time.sleep(3) if not self.d(text=retry_str).exists: self.clickVideoButton("Paused") time.sleep(1) self.clickVideoButton("Play") time.sleep(5) if self.d(text=retry_str).exists: logger.debug("Click retry button!") self.d(text=retry_str).click() time.sleep(1) else: logger.debug("Can't find retry button!") def clickRecentApp(self, app_name): self.multimedia_setting.click_recent_app(app_name) def checkVideoPlayback(self, t_time, expect_resolution=532): timeNow = time.time() if t_time >= 20: self.multimedia_video_quality_helper.checkSurfaceViewResolutionWithThread_start( expect_resolution) while time.time() - timeNow < t_time: playback_state = self.getPlaybackState() if playback_state == "end": logger.debug("Video playback finish!") break elif playback_state != "ready": logger.debug("checkVideoPlayback-- playback_state=%s" % playback_state) self.clickRetryButton() time.sleep(3) if t_time >= 20: assert self.multimedia_video_quality_helper.checkSurfaceViewResolutionWithThread_stop( ) == 1, "Looks like Video didn't reach HD(%d)..." % expect_resolution def exoplayerPlayBack(self, mode=""): if mode == "": mode = "WV: Secure video path required" elif mode == "HDCP": mode = "WV: HDCP + secure video path required" self.d(scrollable=True).scroll.vert.to(text=mode) self.d(text=mode).click() time.sleep(5) self.checkPlaybackState() def test_video_playback(self, t_time=60, mode="", expect_resolution=532): self.exoplayerPlayBack(mode) # play video with exoplayer app time.sleep(20) self.checkVideoPlayback( t_time, expect_resolution) # check play status of video def test_video_playback_with_pause(self, t_time=60): self.exoplayerPlayBack() # play video with exoplayer app time.sleep(20) self.checkVideoPlayback(20) self.clickVideoButton("Paused") #click paused button time.sleep(t_time) self.clickVideoButton("Play") #click play button self.checkVideoPlayback(20) # check play status of video def test_video_playback_with_control(self): self.exoplayerPlayBack() time.sleep(20) self.checkVideoPlayback(20) self.clickVideoButton("Paused") time.sleep(5) self.clickVideoButton("Play") time.sleep(5) self.clickVideoButton("Forward") time.sleep(5) self.clickVideoButton("Backward") time.sleep(10) def test_video_playback_with_repeatedly(self, click_list, t_time, mode=""): self.exoplayerPlayBack(mode) time.sleep(10) self.checkVideoPlayback(20) for i in range(t_time): logger.debug("clickVideoButton---%d time" % i) for t_str in click_list: self.clickVideoButton(t_str) time.sleep(2) time.sleep(5) def test_video_playback_with_background(self): self.exoplayerPlayBack() time.sleep(20) self.checkVideoPlayback(20) self.clickVideoButton("Paused") time.sleep(5) self.clickVideoButton("Play") time.sleep(5) self.d.press.home() time.sleep(3) self.clickRecentApp("ExoPlayer Demo") def test_video_playback_with_swipe(self, t_time, percent, mode=""): self.exoplayerPlayBack(mode) time.sleep(20) self.checkVideoPlayback(t_time) self.multimedia_setting.set_play_time(percent) self.checkVideoPlayback(20) def test_video_playback_with_sleep_mode(self, mode=""): self.exoplayerPlayBack(mode) time.sleep(20) self.checkVideoPlayback(10) self.d.press.power() time.sleep(5) self.d.press.power() SystemUI().unlock_screen() self.checkVideoPlayback(20) def test_video_playback_with_orientation(self, orientation_list, t_time, mode=""): self.exoplayerPlayBack(mode) time.sleep(10) self.checkVideoPlayback(20) for i in range(t_time): logger.debug("change orientation---%d time" % i) for t_str in orientation_list: self.d.orientation = t_str time.sleep(5) self.d.freeze_rotation(False) time.sleep(5) def test_video_playback_with_reboot(self, t_time): self.case_name = sys._getframe().f_back.f_code.co_name self.appPrepare() self.launchEXOPlayerApp() self.exoplayerPlayBack() time.sleep(20) self.checkVideoPlayback(10) for _ in range(t_time): adb.reboot_device() self.wait_boot_completed() time.sleep(20) self.lock = SystemUI() self.lock.unlock_screen() self.launchEXOPlayerApp() self.exoplayerPlayBack() time.sleep(20) self.checkVideoPlayback(10) self.d.press.back() self.d.press.home() def test_video_playback_with_check_S0I3(self): self.case_name = sys._getframe().f_back.f_code.co_name self.appPrepare() after_S0I3_str = self.multimedia_setting.getS0I3() self.launchEXOPlayerApp() self.exoplayerPlayBack() time.sleep(20) self.checkVideoPlayback(10) self.d.press.power() logger.debug("Step: sleep 800s, please wait...") time.sleep(800) logger.debug("Step: sleep 800s, complete!") self.d.press.power() SystemUI().unlock_screen() self.d.press.back() self.d.press.home() before_S0I3_str = self.multimedia_setting.getS0I3() assert after_S0I3_str != before_S0I3_str, "after_S0I3_str=%s, before_S0I3_str=%s" % ( after_S0I3_str, before_S0I3_str) def test_video_playback_with_check_log(self, mode="", check_str="CopyBuffer"): self.multimedia_setting.clearLogs() self.multimedia_setting.checkLogs_start(check_str) self.exoplayerPlayBack(mode) time.sleep(20) self.checkVideoPlayback(20) self.multimedia_setting.checkLogs_end(check_str) def test_video_playback_with_pause_1hour(self, delay_time=3600): ''' This test used to pause play 1 hours and resume test cases spec is following: 1.pause palying video 2.stop record video 3.resume video 4.start record the second video ''' self.exoplayerPlayBack() time.sleep(20) self.clickVideoButton("Paused") self.multimedia_drm_helper.stopRecord() logger.debug("Step: sleep 1 hours, please wait...") time.sleep(delay_time) self.multimedia_drm_helper.startRecord(self.case_name + '_2') time.sleep(10) self.clickVideoButton("Paused") time.sleep(5) self.checkVideoPlayback(20) def exoplayer_main_test(self, sub_func_name="", *arg, **keywords): """ This test used to test Exoplayer App The test case spec is following: 1. Start record video 2. do sub_func() 3. Stop record video """ self.case_name = sys._getframe().f_back.f_code.co_name if sub_func_name == "": sub_func_name = "%s_sub_func" % self.case_name logger.debug("case_name=%s" % self.case_name) logger.debug("exoplayer_main_test---sub_func_name=%s" % sub_func_name) self.appPrepare() try: self.multimedia_drm_helper.startRecord( self.case_name) #start record self.launchEXOPlayerApp() #launch exoplayer app logger.debug("Arbitrary parameter is %s" % str(arg)) logger.debug("keywords parameter is %s" % str(keywords)) getattr(self, sub_func_name)(*arg, **keywords) time.sleep(10) self.d.press.back() self.d.press.home() time.sleep(1) self.multimedia_drm_helper.stopRecord() #stop record except Exception as e: self.multimedia_drm_helper.stopRecord() assert 0, e assert 0, "Playback complete! Please check video!" logger.debug("Case %s is pass!" % self.case_name) def testWVModular_Exoplayer_Display(self): self.exoplayer_main_test("test_video_playback", 20) def testWVModular_Exoplayer_Video_Playback(self): self.exoplayer_main_test("test_video_playback", 20) def testWVModualr_Exoplayer_Audio_Video_Synchronization(self): self.exoplayer_main_test("test_video_playback", 20) def testWVModular_Exoplayer_Play(self): self.exoplayer_main_test("test_video_playback", 20) def testWVModular_Exoplayer_End(self): self.exoplayer_main_test("test_video_playback", 600) def testWVModular_Exoplayer_Secure_HD_MP4_H264(self): self.exoplayer_main_test("test_video_playback", 20, "WV: Secure HD (MP4,H264)", 500) def testWVModular_ExoPlayer_Control(self): self.exoplayer_main_test("test_video_playback_with_control") def testWVModular_Exoplayer_Pause_Play_Repeatedly(self): self.exoplayer_main_test("test_video_playback_with_repeatedly", ["Paused", "Play"], 20) def testWVModular_Exoplayer_Forward_Rewind_Repeatedly(self): self.exoplayer_main_test("test_video_playback_with_repeatedly", ["Forward", "Backward"], 20) def testWVModular_Exoplayer_Forward_Rewind_Paused(self): self.exoplayer_main_test("test_video_playback_with_repeatedly", ["Paused", "Forward", "Backward", "Play"], 1) def testWVModular_Exoplayer_Forward_Rewind(self): self.exoplayer_main_test("test_video_playback_with_repeatedly", ["Forward", "Backward"], 1) def testWVModular_Exoplayer_Rewind_Less_10s(self): self.exoplayer_main_test("test_video_playback_with_repeatedly", ["Forward", "Backward"], 1, "HDCP") def testWVModular_Exoplayer_Pause_One_Minute(self): self.exoplayer_main_test("test_video_playback_with_pause") def testWVModular_Exoplayer_Resume_Background(self): self.exoplayer_main_test("test_video_playback_with_background") def testRewind_WVModular_Exoplayer(self): self.exoplayer_main_test("test_video_playback_with_swipe", 10, 0.01) def testWVModular_Exoplayer_Forward_Till_End(self): self.exoplayer_main_test("test_video_playback_with_swipe", 10, 0.98) def testWVModular_Exoplayer_Sleep_Paused(self): self.exoplayer_main_test("test_video_playback_with_sleep_mode") def testWVModular_Exoplayer_Power_Button(self): self.exoplayer_main_test("test_video_playback_with_sleep_mode", "HDCP") def testWVModular_Exoplayer_Changeorientation(self): self.exoplayer_main_test("test_video_playback_with_orientation", ["l", "r", "n", "l"], 1, "HDCP") def testWVModular_Verify_WV10_Copy_Buffer(self): self.exoplayer_main_test("test_video_playback_with_check_log", "HDCP", "CopyBuffer") def testWVModular_HDCP_Capability(self): self.exoplayer_main_test("test_video_playback_with_check_log", "HDCP", "GetHDCPCapability") def testWVClassic_Reboot_Multi_Times(self): self.test_video_playback_with_reboot(20) def testWVModular_Exoplayer_Resume_S0i3(self): self.test_video_playback_with_check_S0I3() def testWVModular_Resume_1hour_Paused(self): self.exoplayer_main_test("test_video_playback_with_pause_1hour", delay_time=3600)
class NetflixTest(UIATestBase): """ @summary: Test Widevine """ config = TestConfig() def setUp(self): """ @summary: set up @return: None """ super(NetflixTest, self).setUp() self.d = g_common_obj.get_device() self._test_name = __name__ self.playback_state_str = "playbackState" self.video_button_widget_dict={"play":"com.netflix.mediaclient:id/player", "pause":"com.netflix.mediaclient:id/player", "back_30s":"com.netflix.mediaclient:id/skip_back", "current_time":"com.netflix.mediaclient:id/current_timeLabel", "remain_time":"com.netflix.mediaclient:id/label_duration", "seek_bar":"com.netflix.mediaclient:id/timeline", "volume_up":"volume_up", "volume_down":"volume_down", "back":"back"} print "[Setup]: %s" % self._test_name def tearDown(self): """ @summary: tear tearDown @return: None """ super(NetflixTest, self).tearDown() print "[Teardown]: %s" % self._test_name g_common_obj.stop_exp_handle() def appPrepare(self, model=1): self.cfg_file = os.path.join(os.environ.get('TEST_DATA_ROOT', ''), \ 'tests.tablet.mum_auto_drm.conf') self.cfg = self.config.read(self.cfg_file, self.case_name) self.multimedia_setting = MultiMediaSetting(self.cfg_file) self.multimedia_drm_helper = MultiMediaDRMHelper() self.multimedia_video_quality_helper = MultiMediaVideoQualityHelper() self.multimedia_setting.install_apk("netflix_apk") self.netflix_package_name, self.netflix_activity_name = self.multimedia_setting.get_package_and_activity_name("netflix_apk") # g_common_obj.set_vertical_screen() g_common_obj.stop_app_am(self.netflix_package_name) SystemUI().unlock_screen() def clickScreen(self): self.multimedia_setting.clickScreen() def registerNetflix(self): t_email = "*****@*****.**" t_password = "******" if self.d(description="Choose a Credential").exists: if self.d(textContains=t_email).exists: self.d(textContains=t_email).click() for _ in range(10): if self.d(textContains="Kids").exists: self.d(textContains="Kids").click() time.sleep(10) return time.sleep(3) else: self.d(textContains="None of the above").click() time.sleep(2) else: self.d(textContains="Sign In").click() time.sleep(5) self.d(className="android.widget.EditText", resourceId="com.netflix.mediaclient:id/login_email").set_text(t_email) self.d(className="android.widget.EditText", resourceId="com.netflix.mediaclient:id/login_password").set_text(t_password) self.d(textContains="Sign In").click() time.sleep(10) #wait DUT sign in def launchNetflixApp(self): SystemUI().unlock_screen() for _ in range(2): g_common_obj.launch_app_am(self.netflix_package_name, self.netflix_activity_name) time.sleep(5) for _ in range(6): if self.d(description="Search").exists: return if self.d(textContains="New version of application").exists: time.sleep(2) self.d(textContains="Cancel").click(2) if self.d(textContains="Sign In").exists or self.d(description="Choose a Credential").exists: self.registerNetflix() time.sleep(5) if self.d(description="test").exists: self.d(description="test").click(3) if self.d(textContains="Notifications may include newly-added movi").exists: self.d(textContains="No Thanks").click(2) assert self.d(description="Search").exists, "launch Netflix App failed!" def clickNetflixMenu(self, menu_str="Action"): self.d(description="Navigate up").click() #menu button time.sleep(2) self.d(className="android.widget.ScrollView").scroll.vert.to(textContains=menu_str) self.d(textContains=menu_str).click() time.sleep(5) def get_widget(self, t_str): logger.debug("get_widget---t_str=%s" % t_str) assert t_str in self.video_button_widget_dict, "%s not in video_button_widget_dict!" % t_str t_resource_id = self.video_button_widget_dict[t_str] if t_resource_id == t_str: return t_resource_id else: return self.d(resourceId=t_resource_id) @staticmethod def setTimeToSec(time): time = time.split(":") i = 1 temp = 0 for s in time[::-1]: temp += int(s) * i i *= 60 return int(temp) def get_widget_text(self, t_widget): try: self.s_t_text = t_widget.text except Exception as e: logger.debug("get_widget_text error:%s" % e) self.s_t_text = -2 def click_widget(self, t_widget): try: t_widget.click() self.s_t_text = 0 except Exception as e: logger.debug("click_widget error:%s" % e) self.s_t_text = -2 assert 0, "click_widget error:%s" % e def get_widget_bounds(self, t_widget): try: bounds = t_widget.info["bounds"] progress_bar_bounds = {} progress_bar_bounds["y"] = bounds["top"] + (bounds["bottom"] - bounds["top"])/2 progress_bar_bounds["x_start"] = bounds["left"] + 10 progress_bar_bounds["x_end"] = bounds["right"] - 10 self.s_t_text = progress_bar_bounds except Exception as e: logger.debug("get_widget_text error:%s" % e) self.s_t_text = -2 def widget_operation_with_thread(self, t_str, t_operation): self.s_t_text = -1 t_widget = self.get_widget(t_str) if t_operation == "get_text": thread.start_new_thread(self.get_widget_text, (t_widget, )) elif t_operation == "click": thread.start_new_thread(self.click_widget, (t_widget, )) elif t_operation == "get_bounds": thread.start_new_thread(self.get_widget_bounds, (t_widget, )) else: assert 0, "Error operation!" while self.s_t_text == -1: if not t_widget.exists: self.clickScreen() time.sleep(1) return self.s_t_text def click_button(self, t_str): logger.debug("click_button---t_str=%s" % t_str) # t_widget = self.get_widget(t_str) t_widget = self.video_button_widget_dict[t_str] if t_str != t_widget: self.widget_operation_with_thread(t_str, "click") else: getattr(self.d.press, t_widget)() def get_play_time_coordinate(self, percent): if "progress_bar_bounds" not in dir(self): self.progress_bar_bounds = self.widget_operation_with_thread("seek_bar", "get_bounds") x = self.progress_bar_bounds["x_start"] + (self.progress_bar_bounds["x_end"] - self.progress_bar_bounds["x_start"]) * percent x = int(x) y = self.progress_bar_bounds["y"] y = int(y) logger.debug("progress_bar_bounds=%s, percent=%s" % (self.progress_bar_bounds, percent)) return x, y def set_play_time(self, percent=0.5): x, y = self.get_play_time_coordinate(percent) seek_bar_widget = self.get_widget("seek_bar") if not seek_bar_widget.exists: self.clickScreen() self.d.click(x,y) def set_play_time_with_swipe(self, percent): ct, tt = self.get_play_time() ct = ct + 2 if ct > tt: ct = tt start_x, start_y = self.get_play_time_coordinate(ct / float(tt)) end_x, end_y = self.get_play_time_coordinate(percent) self.d.swipe(start_x, start_y, end_x, end_y) def get_play_time(self, t_time=60): logger.debug("get_play_time start") timeNow = time.time() while time.time() - timeNow < t_time: current_time_widget = self.get_widget("current_time") if current_time_widget.exists: ct = self.widget_operation_with_thread("current_time", "get_text") rt = self.widget_operation_with_thread("remain_time", "get_text") ct = self.setTimeToSec(ct) rt = self.setTimeToSec(rt) logger.debug("ct---tt:%s, %s" % (ct, ct + rt)) return ct, ct + rt else: logger.debug("%s times, don't find current time or total time!" % str(time.time() - timeNow)) assert not self.d(textContains="error").exists, "Play error!" time.sleep(1) self.clickScreen() assert not self.d(textContains="OTC Alarm is triggered").exists, "OTC Alarm is triggered! wait time=%d" % (t_time) assert 0, "Play error! playback timeout %d s, network problem." % (t_time) def checkVideoPlayback(self, t_time, skip_flag=0, expect_resolution=480): flag = 0 timeNow = time.time() if t_time >= 20 and skip_flag == 0: self.multimedia_video_quality_helper.checkSurfaceViewResolutionWithThread_start(expect_resolution) while time.time() - timeNow < t_time: if flag == 1 or self.d(textContains="Loading").exists: time.sleep(2) elif self.get_widget("current_time").exists: logger.debug("%s times, find current time and total time!!" % str(time.time() - timeNow)) flag = 1 if skip_flag: break else: logger.debug("%s times, don't find current time or total time!!" % str(time.time() - timeNow)) assert not self.d(textContains="error").exists, "Play error!" time.sleep(1) self.clickScreen() if t_time >=20 and skip_flag == 0 : assert self.multimedia_video_quality_helper.checkSurfaceViewResolutionWithThread_stop() == 1, "Looks like Video didn't reach HD(%d)..." % expect_resolution assert not self.d(textContains="OTC Alarm is triggered").exists, "OTC Alarm is triggered! wait time=%d" % (time.time() - timeNow) assert flag, "Play error! playback timeout %d s, network problem.." % (t_time) def netflixPlayBack(self, t_index=0): #instance self.d(className="android.widget.ImageView", index=t_index).click() time.sleep(3) for _ in range(10): if self.d(className="android.widget.ImageView").exists: break time.sleep(3) self.d(className="android.widget.ImageView").click() time.sleep(5) for _ in range(20): if not self.d(textContains="Loading").exists: break time.sleep(5) assert not self.d(textContains="Loading").exists, "Error! loading %d s" % (5*20) def netflixLongPlayBack(self): self.d(scrollable=True).scroll.vert.to(description="The Lost World: Jurassic Park") for _ in range(10): if self.d(description="The Lost World: Jurassic Park").exists: break time.sleep(3) self.d(description="The Lost World: Jurassic Park").click() self.d(description="Play Video The Lost World: Jurassic Park").click() time.sleep(5) for _ in range(20): if not self.d(textContains="Loading").exists: break time.sleep(5) assert not self.d(textContains="Loading").exists, "Error! loading %d s" % (5 * 20) def wait_boot_completed(self, timeout=1000): ''' wait Android boot_completed args: timeout -- optional timeout in second, default 180s ''' count = 0 sleep_time = 5 while count < timeout: prop_val = adb.adb_cmd_capture_msg('getprop sys.boot_completed') if '1' in prop_val: print 'boot_completed' return count += sleep_time time.sleep(sleep_time) raise Exception('%ds timeout waiting for boot_completed' % timeout) def clickRecentApp(self, app_name): self.multimedia_setting.click_recent_app(app_name) def test_video_playback(self, t_time=60): self.clickNetflixMenu()#open netflix menu self.netflixPlayBack()#play video with netflix app self.checkVideoPlayback(t_time)# check play status of video def test_video_playback_with_back(self, t_time=1): self.clickNetflixMenu() self.netflixPlayBack() self.checkVideoPlayback(60) for _ in range(t_time): self.click_button("back") self.d(className="android.widget.ImageView").click() time.sleep(5) self.checkVideoPlayback(60, 1) self.checkVideoPlayback(30, 0, 384) def test_video_playback_with_app_change(self): self.multimedia_setting.install_apk("video_apk") self.clickNetflixMenu() self.netflixPlayBack() self.checkVideoPlayback(60, 1) self.multimedia_handle = MultiMediaHandle() self.multimedia_handle.launchVideoApp() time.sleep(2) self.clickRecentApp("Netflix") self.d(className="android.widget.ImageView").click() time.sleep(5) self.checkVideoPlayback(60, 1) self.checkVideoPlayback(20) def test_video_playback_with_sleep_mode(self): self.clickNetflixMenu() self.netflixPlayBack() self.checkVideoPlayback(40, 1) ct, tt = self.get_play_time() if tt - ct <= 300: self.set_play_time(0.01) self.checkVideoPlayback(30, 1) self.click_button("pause") self.d.press.power() time.sleep(10) self.d.press.power() SystemUI().unlock_screen() time.sleep(5) self.click_button("play") self.checkVideoPlayback(20) def test_video_playback_with_repeatedly(self, click_list, t_time, step_skip_time=2, begin_check_time=30): self.clickNetflixMenu() self.netflixPlayBack() self.checkVideoPlayback(30, 1) ct, tt = self.get_play_time() logger.debug("ct, tt---%d, %d" % (ct, tt)) if tt - ct <= 300: self.set_play_time(0.01) self.checkVideoPlayback(30, 1) for i in range(t_time): logger.debug("click_button---%d time" % i) for t_str in click_list: if t_str == "sleep": time.sleep(5) elif "swipe" in t_str: self.set_play_time_with_swipe(float(t_str.split(" ")[1])) self.checkVideoPlayback(30, 1) else: self.click_button(t_str) time.sleep(step_skip_time) time.sleep(5) def test_video_playback_with_longtime(self,t_time=7200): ''' This test used to test netflix app over 2 hours The case spec is following: 1.select HD(or better) protected content clip 2.Watch movices for about 2 hours 3.Play Another Netflix movices for 10 minutes ''' self.clickNetflixMenu('Home') self.netflixLongPlayBack() self.checkVideoPlayback(120) self.multimedia_drm_helper.stopRecord() time.sleep(5) logger.debug("Step 2: Watch movices for about 2 hours") self.set_play_time(0.01) ct, tt = self.get_play_time() while ct<= t_time: self.multimedia_drm_helper.startRecord(self.case_name + '_step2_' + str(ct/60) + '_mins') logger.debug("Current palytime is :%s seconds" %ct) self.checkVideoPlayback(1800) ct, tt = self.get_play_time() self.multimedia_drm_helper.stopRecord() logger.debug("Play time is %s seconds" % (tt-ct)) logger.debug("Step 3: Play Another Netflix movices for 10 minutes") self.multimedia_drm_helper.startRecord(self.case_name + '_step3') for _ in range(2): self.d.press.back() #self.launchNetflixApp() self.clickNetflixMenu() self.netflixPlayBack(2) self.checkVideoPlayback(600) def test_video_playback_with_check_WVinfo(self,check_str='WVCdm'): ''' This test used to test netflix app and check WVinfo The case spec is following: 1.Play HD video via netflix 2.Check its logs "adb logcat |grep WVCdm" ''' self.multimedia_setting.clearLogs() self.launchNetflixApp() logger.debug("get WVCdm info:") self.multimedia_setting.checkLogs_start(check_str) self.clickNetflixMenu() # open netflix menu self.netflixPlayBack() # play video with netflix app self.checkVideoPlayback(120) # check play status of video self.multimedia_setting.checkLogs_end(check_str) def netflix_main_test(self, sub_func_name="", *arg, **keywords): """ This test used to test Exoplayer App The test case spec is following: 1. Start record video 2. do sub_func() 3. Stop record video """ self.case_name = sys._getframe().f_back.f_code.co_name if sub_func_name == "": sub_func_name = "%s_sub_func" % self.case_name logger.debug("case_name=%s" % self.case_name) logger.debug("netflix_main_test---sub_func_name=%s" % sub_func_name) self.appPrepare() try: self.multimedia_drm_helper.startRecord(self.case_name)#start record self.launchNetflixApp()#launch netflix app logger.debug("Arbitrary parameter is %s" % str(arg)) logger.debug("keywords parameter is %s" % str(keywords)) getattr(self, sub_func_name)(*arg, **keywords) time.sleep(10) self.d.press.back() self.d.press.home() time.sleep(1) self.multimedia_drm_helper.stopRecord()#stop record except Exception as e: self.multimedia_drm_helper.stopRecord()#stop record assert 0, e assert 0, "Playback complete! Please check video!" logger.debug("Case %s is pass!" % self.case_name) def testWVModular_Netflix_HD(self): self.netflix_main_test("test_video_playback", 120) def testWVModular_NetFlix_SD(self): self.netflix_main_test("test_video_playback", 120) def testWVModular_Netflix_Menu(self): self.netflix_main_test("test_video_playback", 120) def testWVModular_Netflix_Pause(self): self.netflix_main_test("test_video_playback_with_repeatedly", ["pause", "play"], 2, 4) def testWVModular_NetFlix_Volume_Change(self): self.netflix_main_test("test_video_playback_with_repeatedly", ["volume_up"]*4 + ["sleep"]*2 +["volume_down"]*4 , 1, 1) def testWVModular_Netflix_Volume_Pause(self): self.netflix_main_test("test_video_playback_with_repeatedly", ["pause"] + ["volume_up"]*4 + ["play"] + ["sleep"]*2 + ["pause"] + ["volume_down"]*4 + ["play"] + ["sleep"], 1, 1) def testWVModular_NetFlix_AV_Synced(self): self.netflix_main_test("test_video_playback_with_repeatedly", ["pause"] + ["volume_up"]*4 + ["play"] + ["sleep"]*2 + ["pause"] + ["volume_down"]*4 + ["play"] + ["sleep"], 1, 1) def testWVModular_Netflix_Rewind_10(self): self.netflix_main_test("test_video_playback_with_repeatedly", ["back_30s"], 1, 20, 40) def testWVModular_NetFlix_Resume_Sleep(self): self.netflix_main_test("test_video_playback_with_sleep_mode") def testWVModular_NetFlix_Power_Button(self): self.netflix_main_test("test_video_playback_with_sleep_mode") def testWVModular_Netflix_Back(self): self.netflix_main_test("test_video_playback_with_back", 1) def testWVModular_Netflix_Back_Stress(self): self.netflix_main_test("test_video_playback_with_back", 10) def testWVModular_NetFlix_Apps_Change(self): self.netflix_main_test("test_video_playback_with_app_change") def testWVModular_Netflix_Scrub(self): self.netflix_main_test("test_video_playback_with_repeatedly", ["swipe 0.7"] + ["sleep"]*2 + ["swipe 0.2"], 1, 1) def testWVModualr_Netflix_HD_Control(self): self.netflix_main_test("test_video_playback_with_repeatedly", ["pause", "play", "swipe 0.7"] + ["sleep"]*2 + ["swipe 0.2"], 1, 1) def testWVModular_Netflix_HD_WVinfo(self): self.netflix_main_test("test_video_playback_with_check_WVinfo") def testWVModular_Netflix_Long_Playback(self): self.netflix_main_test("test_video_playback_with_longtime", 7200)