From aa0e8041af446c0bd236346a80c14a8bc241e1da Mon Sep 17 00:00:00 2001 From: Muhammad Ammar Date: Fri, 9 May 2014 07:01:03 +0000 Subject: [PATCH] Bok-Choy Video Tests Batch6 --- common/test/acceptance/pages/lms/video.py | 87 +++++++++++++++---- .../acceptance/tests/test_video_module.py | 47 ++++++++++ .../courseware/features/video.feature | 41 +++------ 3 files changed, 128 insertions(+), 47 deletions(-) diff --git a/common/test/acceptance/pages/lms/video.py b/common/test/acceptance/pages/lms/video.py index e4a76e36d4..40e93cd3f8 100644 --- a/common/test/acceptance/pages/lms/video.py +++ b/common/test/acceptance/pages/lms/video.py @@ -32,7 +32,8 @@ CSS_CLASS_NAMES = { 'video_xmodule': '.xmodule_VideoModule', 'video_init': '.is-initialized', 'video_time': 'div.vidtime', - 'video_display_name': '.vert h2' + 'video_display_name': '.vert h2', + 'captions_lang_list': '.langs-list li' } VIDEO_MODES = { @@ -246,39 +247,62 @@ class VideoPage(PageObject): selector = self.get_element_selector(video_display_name, VIDEO_BUTTONS[button_id]) return self.q(css=selector).visible - @wait_for_js def show_captions(self, video_display_name=None): """ - Show the video captions. + Make Captions Visible. Arguments: video_display_name (str or None): Display name of a Video. """ - subtitle_selector = self.get_element_selector(video_display_name, CSS_CLASS_NAMES['closed_captions']) + self._captions_visibility(True, video_display_name) - def _is_subtitles_open(): + def hide_captions(self, video_display_name=None): + """ + Make Captions Invisible. + + Arguments: + video_display_name (str or None): Display name of a Video. + + """ + self._captions_visibility(False, video_display_name) + + @wait_for_js + def _captions_visibility(self, captions_new_state, video_display_name=None): + """ + Set the video captions visibility state. + + Arguments: + video_display_name (str or None): Display name of a Video. + captions_new_state (bool): True means show captions, False means hide captions + + """ + states = {True: 'Shown', False: 'Hidden'} + state = states[captions_new_state] + + caption_state_selector = self.get_element_selector(video_display_name, CSS_CLASS_NAMES['closed_captions']) + + def _captions_current_state(): """ - Check if subtitles are opened + Get current visibility sate of captions. Returns: - bool: Subtitles Visibility + bool: True means captions are visible, False means captions are not visible """ - is_open = not self.q(css=subtitle_selector).present - return is_open + return not self.q(css=caption_state_selector).present # Make sure that the CC button is there - EmptyPromise(lambda: self.is_button_shown('CC', video_display_name), + EmptyPromise(lambda: self.is_button_shown('CC'), "CC button is shown").fulfill() - # Check if the captions are already open and click if not - if _is_subtitles_open() is False: - self.click_player_button('CC', video_display_name) + # toggle captions visibility state if needed + if _captions_current_state() != captions_new_state: + self.click_player_button('CC') - # Verify that they are now open - EmptyPromise(_is_subtitles_open, - "Subtitles are shown").fulfill() + # Verify that captions state is toggled/changed + EmptyPromise(lambda: _captions_current_state() == captions_new_state, + "Captions are {state}".format(state=state)).fulfill() @property def captions_text(self, video_display_name=None): @@ -594,3 +618,34 @@ class VideoPage(PageObject): return False return True + + def sources(self, video_display_name=None): + """ + Extract all video source urls on current page. + + Arguments: + video_display_name (str or None): Display name of a Video. + + Returns: + list: Video Source URLs. + + """ + sources_selector = self.get_element_selector(video_display_name, CSS_CLASS_NAMES['video_sources']) + return self.q(css=sources_selector).map(lambda el: el.get_attribute('src').split('?')[0]).results + + def caption_languages(self, video_display_name=None): + """ + Get caption languages available for a video. + + Arguments: + video_display_name (str or None): Display name of a Video. + + Returns: + dict: Language Codes('en', 'zh' etc) as keys and Language Names as Values('English', 'Chinese' etc) + + """ + languages_selector = self.get_element_selector(video_display_name, CSS_CLASS_NAMES['captions_lang_list']) + language_codes = self.q(css=languages_selector).attrs('data-lang-code') + language_names = self.q(css=languages_selector).attrs('textContent') + + return dict(zip(language_codes, language_names)) diff --git a/common/test/acceptance/tests/test_video_module.py b/common/test/acceptance/tests/test_video_module.py index ad33afb98a..e0caee264f 100644 --- a/common/test/acceptance/tests/test_video_module.py +++ b/common/test/acceptance/tests/test_video_module.py @@ -490,6 +490,38 @@ class YouTubeVideoTest(VideoBaseTest): # menu "download_transcript" doesn't exist self.assertFalse(self.video.is_menu_exist('download_transcript')) + def test_video_language_menu_working(self): + """ + Scenario: Language menu works correctly in Video component + Given the course has a Video component in "Youtube" mode + And I have defined multiple language transcripts for the videos + And I make sure captions are closed + And I see video menu "language" with correct items + And I select language with code "zh" + Then I see "好 各位同学" text in the captions + And I select language with code "en" + Then I see "Hi, welcome to Edx." text in the captions + """ + self.assets.extend(['chinese_transcripts.srt', 'subs_OEoXaMPEzfM.srt.sjson']) + data = {'transcripts': {"zh": "chinese_transcripts.srt"}, 'sub': 'OEoXaMPEzfM'} + self.metadata = self.metadata_for_mode('youtube', additional_data=data) + + # go to video + self.navigate_to_video() + + self.video.hide_captions() + + correct_languages = {'en': 'English', 'zh': 'Chinese'} + self.assertEqual(self.video.caption_languages(), correct_languages) + + self.video.select_language('zh') + + unicode_text = "好 各位同学".decode('utf-8') + self.assertIn(unicode_text, self.video.captions_text) + + self.video.select_language('en') + self.assertIn('Hi, welcome to Edx.', self.video.captions_text) + class YouTubeHtml5VideoTest(VideoBaseTest): """ Test YouTube HTML5 Video Player """ @@ -676,3 +708,18 @@ class Html5VideoTest(VideoBaseTest): # check if we see "好 各位同学" text in the captions unicode_text = "好 各位同学".decode('utf-8') self.assertIn(unicode_text, self.video.captions_text) + + def test_video_rendering(self): + """ + Scenario: Video component is fully rendered in the LMS in HTML5 mode + Given the course has a Video component in "HTML5" mode + Then the video has rendered in "HTML5" mode + And video sources are correct + """ + self.metadata = self.metadata_for_mode('html5') + + self.navigate_to_video() + + self.assertTrue(self.video.is_video_rendered('html5')) + + self.assertTrue(all([source in HTML5_SOURCES for source in self.video.sources()])) diff --git a/lms/djangoapps/courseware/features/video.feature b/lms/djangoapps/courseware/features/video.feature index 98890218dd..3a3cf285eb 100644 --- a/lms/djangoapps/courseware/features/video.feature +++ b/lms/djangoapps/courseware/features/video.feature @@ -3,12 +3,6 @@ Feature: LMS.Video component As a student, I want to view course videos in LMS # 1 - Scenario: Video component is fully rendered in the LMS in HTML5 mode - Given the course has a Video component in "HTML5" mode - When the video has rendered in "HTML5" mode - And all sources are correct - - # 2 Scenario: Multiple videos in sequentials all load and work, switching between sequentials Given I am registered for the course "test_course" And it has a video "A" in "Youtube" mode in position "1" of sequential @@ -30,7 +24,7 @@ Feature: LMS.Video component When I open video "A" Then video "A" should start playing at speed "2.0" - # 3 + # 2 Scenario: Video component stores speed correctly when each video is in separate sequence Given I am registered for the course "test_course" And it has a video "A" in "Youtube" mode in position "1" of sequential @@ -52,21 +46,6 @@ Feature: LMS.Video component When I open video "C" Then video "C" should start playing at speed "1.0" - # 4 - Scenario: Language menu works correctly in Video component - Given I am registered for the course "test_course" - And I have a "chinese_transcripts.srt" transcript file in assets - And I have a "subs_OEoXaMPEzfM.srt.sjson" transcript file in assets - And it has a video in "Youtube" mode: - | transcripts | sub | - | {"zh": "chinese_transcripts.srt"} | OEoXaMPEzfM | - And I make sure captions are closed - And I see video menu "language" with correct items - And I select language with code "zh" - Then I see "好 各位同学" text in the captions - And I select language with code "en" - And I see "Hi, welcome to Edx." text in the captions - # 9 # Scenario: Youtube video has correct transcript if fields for other speeds are filled # Given I am registered for the course "test_course" @@ -85,7 +64,7 @@ Feature: LMS.Video component # "1:56" is the duration in the VCR timer before the video plays. # And I see duration "1:56" - # 6 + # 3 Scenario: Verify that each video in each sub-section includes a transcript for non-Youtube countries Given youtube server is up and response time is 2 seconds And I am registered for the course "test_course" @@ -126,7 +105,7 @@ Feature: LMS.Video component # And I click video button "play" # Then I see video slider at "0:10" position - # 7 + # 4 Scenario: End time works for Youtube video Given I am registered for the course "test_course" And it has a video in "Youtube" mode: @@ -136,7 +115,7 @@ Feature: LMS.Video component And I wait "5" seconds Then I see video slider at "0:02" position - # 8 + # 5 Scenario: Youtube video with end-time at 1:00 and the video starts playing at 0:58 Given I am registered for the course "test_course" And it has a video in "Youtube" mode: @@ -148,7 +127,7 @@ Feature: LMS.Video component And I wait "5" seconds Then I see video slider at "1:00" position - # 9 + # 6 Scenario: Start time and end time work together for Youtube video Given I am registered for the course "test_course" And it has a video in "Youtube" mode: @@ -159,7 +138,7 @@ Feature: LMS.Video component And I wait "5" seconds Then I see video slider at "0:12" position - # 10 + # 7 Scenario: Youtube video after pausing at end time video plays to the end from end time Given I am registered for the course "test_course" And it has a video in "Youtube" mode: @@ -174,7 +153,7 @@ Feature: LMS.Video component # The default video length is 00:01:55. Then I see video slider at "1:55" position - # 11 + # 8 Scenario: Youtube video with end-time at 0:32 and start-time at 0:30, the video starts playing from 0:28 Given I am registered for the course "test_course" And it has a video in "Youtube" mode: @@ -186,7 +165,7 @@ Feature: LMS.Video component And I wait "8" seconds Then I see video slider at "0:32" position - # 12 + # 9 Scenario: Youtube video with end-time at 1:00, the video starts playing from 1:52 Given I am registered for the course "test_course" And it has a video in "Youtube" mode: @@ -199,7 +178,7 @@ Feature: LMS.Video component # Video stops at the end. Then I see video slider at "1:55" position - # 13 + # 10 @skip_firefox Scenario: Quality button appears on play Given the course has a Video component in "Youtube" mode @@ -207,7 +186,7 @@ Feature: LMS.Video component And I click video button "play" Then I see video button "quality" is visible - # 14 + # 11 @skip_firefox Scenario: Quality button works correctly Given the course has a Video component in "Youtube" mode