def test_video_player(self): """ Play a video in the courseware. """ # Navigate to a video self.course_info_page.visit() self.tab_nav.go_to_tab("Courseware") # The video should start off paused # Since the video hasn't loaded yet, it's elapsed time is 0 self.assertFalse(self.video.is_playing) self.assertEqual(self.video.elapsed_time, 0) # Play the video self.video.play() # Now we should be playing self.assertTrue(self.video.is_playing) # Wait for the video to load the duration video_duration_loaded = EmptyPromise(lambda: self.video.duration > 0, "video has duration", timeout=20) with fulfill_before(video_duration_loaded): # Pause the video self.video.pause() # Expect that the elapsed time and duration are reasonable # Again, we can't expect the video to actually play because of # latency through the ssh tunnel self.assertGreaterEqual(self.video.elapsed_time, 0) self.assertGreaterEqual(self.video.duration, self.video.elapsed_time)
def submit(self): """ Submit the rubric. """ # Wait for the button to become enabled button_css = 'input.submit-button' button_enabled = EmptyPromise( lambda: all(self.css_map(button_css, lambda el: not el['disabled']) ), "Submit button enabled") # Submit the assessment with fulfill_before(button_enabled): self.css_click(button_css)
def submit(self): """ Submit the rubric. """ # Wait for the button to become enabled button_css = 'input.submit-button' button_enabled = EmptyPromise( lambda: all(self.css_map(button_css, lambda el: not el['disabled'])), "Submit button enabled" ) # Submit the assessment with fulfill_before(button_enabled): self.css_click(button_css)
def trigger_output(self): """ Wait for click handlers to be installed, then click a button and retrieve the output that appears after a delay. """ click_ready = EmptyPromise( lambda: self.is_css_present('div#ready'), "Click ready" ) output_ready = EmptyPromise( lambda: self.is_css_present('div#output'), "Output available" ) with fulfill_after(output_ready): with fulfill_before(click_ready): self.css_click('div#fixture button')
def submit_self_assessment(self, scores): """ Submit a self-assessment rubric. `scores` is a list of scores (0 to max score) for each category in the rubric. """ # Warn if we have the wrong number of scores num_categories = len(self.rubric_categories) if len(scores) != num_categories: msg = "Recieved {0} scores but there are {1} rubric categories".format( len(scores), num_categories) self.warning(msg) # Set the score for each category for score_index in range(len(scores)): # Check that we have the enough radio buttons category_css = "div.rubric>ul.rubric-list:nth-of-type({0})".format( score_index + 1) if scores[score_index] > self.css_count(category_css + ' input.score-selection'): msg = "Tried to select score {0} but there are only {1} options".format( score_index, len(scores)) self.warning(msg) # Check the radio button at the correct index else: input_css = ( category_css + ">li.rubric-list-item:nth-of-type({0}) input.score-selection" .format(scores[score_index] + 1)) self.css_check(input_css) # Wait for the button to become enabled button_css = 'input.submit-button' button_enabled = EmptyPromise( lambda: all(self.css_map(button_css, lambda el: not el['disabled']) ), "Submit button enabled") # Submit the assessment with fulfill_before(button_enabled): self.css_click(button_css)
def submit_self_assessment(self, scores): """ Submit a self-assessment rubric. `scores` is a list of scores (0 to max score) for each category in the rubric. """ # Warn if we have the wrong number of scores num_categories = len(self.rubric_categories) if len(scores) != num_categories: msg = "Recieved {0} scores but there are {1} rubric categories".format( len(scores), num_categories ) self.warning(msg) # Set the score for each category for score_index in range(len(scores)): # Check that we have the enough radio buttons category_css = "div.rubric>ul.rubric-list:nth-of-type({0})".format(score_index + 1) if scores[score_index] > self.css_count(category_css + ' input.score-selection'): msg = "Tried to select score {0} but there are only {1} options".format(score_index, len(scores)) self.warning(msg) # Check the radio button at the correct index else: input_css = ( category_css + ">li.rubric-list-item:nth-of-type({0}) input.score-selection".format(scores[score_index] + 1) ) self.css_check(input_css) # Wait for the button to become enabled button_css = 'input.submit-button' button_enabled = EmptyPromise( lambda: all(self.css_map(button_css, lambda el: not el['disabled'])), "Submit button enabled" ) # Submit the assessment with fulfill_before(button_enabled): self.css_click(button_css)
def test_video_player(self): """ Play a video in the courseware. """ # Navigate to a video self.course_info_page.visit() self.tab_nav.go_to_tab('Courseware') # The video should start off paused # Since the video hasn't loaded yet, it's elapsed time is 0 self.assertFalse(self.video.is_playing) self.assertEqual(self.video.elapsed_time, 0) # Play the video self.video.play() # Now we should be playing self.assertTrue(self.video.is_playing) # Wait for the video to load the duration video_duration_loaded = EmptyPromise(lambda: self.video.duration > 0, 'video has duration', timeout=20) with fulfill_before(video_duration_loaded): # Pause the video self.video.pause() # Expect that the elapsed time and duration are reasonable # Again, we can't expect the video to actually play because of # latency through the ssh tunnel self.assertGreaterEqual(self.video.elapsed_time, 0) self.assertGreaterEqual(self.video.duration, self.video.elapsed_time)