def test_notification_updates(self): """ Verifies that the notification is removed and not visible when it should be """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) problem_page.click_choice("choice_2") self.assertFalse(problem_page.is_success_notification_visible()) problem_page.click_submit() problem_page.wait_success_notification() self.assertEqual('Question 1: correct', problem_page.status_sr_text) # Clicking Save should clear the submit notification problem_page.click_save() self.assertFalse(problem_page.is_success_notification_visible()) problem_page.wait_for_save_notification() # Changing the answer should clear the save notification problem_page.click_choice("choice_1") self.assertFalse(problem_page.is_save_notification_visible()) problem_page.click_save() problem_page.wait_for_save_notification() # Submitting the problem again should clear the save notification problem_page.click_submit() problem_page.wait_incorrect_notification() self.assertEqual('Question 1: incorrect', problem_page.status_sr_text) self.assertFalse(problem_page.is_save_notification_visible())
def test_logout_after_click_redirect(self): """ 1) User goes to a problem page. 2) User fills out an answer to the problem. 3) User is logged out because their session id is invalidated or removed. 4) User clicks "check", and sees a confirmation modal asking them to re-authenticate, since they've just been logged out. 5) User clicks "ok". 6) User is redirected to the login page. 7) User logs in. 8) User is redirected back to the problem page they started out on. 9) User is able to submit an answer """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) self.assertEqual(problem_page.problem_name, 'TEST PROBLEM') problem_page.fill_answer_numerical('1') self.log_user_out() with problem_page.handle_alert(confirm=True): problem_page.click_submit() login_page = CombinedLoginAndRegisterPage(self.browser) login_page.wait_for_page() login_page.login(self.email, self.password) problem_page.wait_for_page() self.assertEqual(problem_page.problem_name, 'TEST PROBLEM') problem_page.fill_answer_numerical('1') problem_page.click_submit() self.assertTrue(problem_page.simpleprob_is_correct())
def _fulfill_prerequisite(self): """ Fulfill the prerequisite needed to see gated content """ problem_page = ProblemPage(self.browser) self.assertEqual(problem_page.wait_for_page().problem_name, 'HEIGHT OF EIFFEL TOWER') problem_page.click_choice('choice_1') problem_page.click_submit()
def test_feedback_notification_hides_after_save(self): self.courseware_page.visit() problem_page = ProblemPage(self.browser) problem_page.click_choice("choice_0") problem_page.click_submit() problem_page.wait_for_feedback_message_visibility() problem_page.click_choice("choice_1") problem_page.click_save() self.assertFalse(problem_page.is_feedback_message_notification_visible())
def test_partial_credit(self): """ Test that we can see the partial credit value and feedback. """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) self.assertEqual(problem_page.problem_name, 'PARTIAL CREDIT TEST PROBLEM') problem_page.fill_answer_numerical('-1') problem_page.click_submit() problem_page.wait_for_status_icon() self.assertTrue(problem_page.simpleprob_is_partially_correct())
def test_conditional_displays_content(self): self.install_course_fixture() self.courseware_page.visit() # Answer the problem problem_page = ProblemPage(self.browser) problem_page.fill_answer('correct string') problem_page.click_submit() # The conditional does not update on its own, so we need to reload the page. self.courseware_page.visit() # Verify that we can see the content. conditional_page = ConditionalPage(self.browser) self.assertTrue(conditional_page.is_content_visible())
def verify_check_hint(self, answer, answer_text, expected_events): """ Verify clicking Check shows the extended hint in the problem message. """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) self.assertEqual(problem_page.problem_text[0], u'question text') problem_page.fill_answer(answer) problem_page.click_submit() self.assertEqual(problem_page.message_text, answer_text) # Check for corresponding tracking event actual_events = self.wait_for_events( event_filter={'event_type': 'edx.problem.hint.feedback_displayed'}, number_of_matches=1 ) self.assert_events_match(expected_events, actual_events)
def test_reset_button_not_rendered_after_correct_submission(self): """ Scenario: Verify that formula problem can not be resetted after an incorrect submission. Given I am attempting a formula response problem type When I input a correct answer Then I should be able to see the mathjax generated preview When I submit the answer Then the correct status is visible And reset button is not rendered """ problem_page = ProblemPage(self.browser) problem_page.fill_answer_numerical('R_1*R_2/R_3') problem_page.verify_mathjax_rendered_in_preview() problem_page.click_submit() self.assertTrue(problem_page.simpleprob_is_correct()) self.assertFalse(problem_page.is_reset_button_present())
def test_course_is_unblocked_as_soon_as_student_passes_entrance_exam(self): """ Scenario: Ensure that entrance exam status message is updated and courseware is unblocked as soon as student passes entrance exam. Given I have a course with entrance exam as pre-requisite When I pass entrance exam Then I can see complete TOC of course And I can see message indicating my pass status """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) self.assertEqual(problem_page.wait_for_page().problem_name, 'HEIGHT OF EIFFEL TOWER') self.assertTrue(self.courseware_page.has_entrance_exam_message()) self.assertFalse(self.courseware_page.has_passed_message()) problem_page.click_choice('choice_1') problem_page.click_submit() self.courseware_page.wait_for_page() self.assertTrue(self.courseware_page.has_passed_message()) self.assertEqual(self.courseware_page.chapter_count_in_navigation, 2)
def test_max_attempts(self): """ Verifies that the Submit button disables when the max number of attempts is reached. """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) # Submit first answer (correct) problem_page.click_choice("choice_2") self.assertFalse(problem_page.is_submit_disabled()) problem_page.click_submit() problem_page.wait_success_notification() # Submit second and final answer (incorrect) problem_page.click_choice("choice_1") problem_page.click_submit() problem_page.wait_incorrect_notification() # Make sure that the Submit button disables. problem_page.wait_for_submit_disabled()
def test_logout_cancel_no_redirect(self): """ 1) User goes to a problem page. 2) User fills out an answer to the problem. 3) User is logged out because their session id is invalidated or removed. 4) User clicks "check", and sees a confirmation modal asking them to re-authenticate, since they've just been logged out. 5) User clicks "cancel". 6) User is not redirected to the login page. """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) self.assertEqual(problem_page.problem_name, 'TEST PROBLEM') problem_page.fill_answer_numerical('1') self.log_user_out() with problem_page.handle_alert(confirm=False): problem_page.click_submit() problem_page.wait_for_page() self.assertEqual(problem_page.problem_name, 'TEST PROBLEM')
def test_reset_problem_after_submission(self, input_value, correctness): """ Scenario: Test that reset button works regardless the submission correctness status. Given I am attempting a formula problem type with randomization:always configuration When I input the answer Then I should be able to see the MathJax generated preview When I submit the problem Then I should be able to see the reset button When reset button is clicked Then the input pane contents should be clear """ problem_page = ProblemPage(self.browser) problem_page.fill_answer_numerical(input_value) problem_page.verify_mathjax_rendered_in_preview() problem_page.click_submit() self.assertEqual(problem_page.get_simpleprob_correctness(), correctness) self.assertTrue(problem_page.is_reset_button_present()) problem_page.click_reset() self.assertEqual(problem_page.get_numerical_input_value, '')
def test_python_execution_in_problem(self): # Navigate to the problem page self.course_home_page.visit() self.course_home_page.outline.go_to_section('Test Section', 'Test Subsection') problem_page = ProblemPage(self.browser) self.assertEqual(problem_page.problem_name.upper(), 'PYTHON PROBLEM') # Does the page have computation results? self.assertIn("What is the sum of 17 and 3?", problem_page.problem_text) # Fill in the answer correctly. problem_page.fill_answer("20") problem_page.click_submit() self.assertTrue(problem_page.is_correct()) # Fill in the answer incorrectly. problem_page.fill_answer("4") problem_page.click_submit() self.assertFalse(problem_page.is_correct())
def test_python_execution_in_problem(self): # Navigate to the problem page self.course_home_page.visit() self.course_home_page.outline.go_to_section('Test Section', 'Test Subsection') problem_page = ProblemPage(self.browser) self.assertEqual(problem_page.problem_name.upper(), 'PYTHON PROBLEM') # Does the page have computation results? self.assertIn("What is the sum of 17 and 3?", problem_page.problem_text) # Fill in the answer correctly. problem_page.fill_answer("20") problem_page.click_submit() self.assertTrue(problem_page.is_correct()) # Fill in the answer incorrectly. problem_page.fill_answer("4") problem_page.click_submit() self.assertFalse(problem_page.is_correct())
def test_max_attempts(self): """ Verifies that the Submit button disables when the max number of attempts is reached. """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) # Submit first answer (correct) problem_page.click_choice("choice_2") self.assertFalse(problem_page.is_submit_disabled()) problem_page.click_submit() problem_page.wait_success_notification() # Submit second and final answer (incorrect) problem_page.click_choice("choice_1") problem_page.click_submit() problem_page.wait_incorrect_notification() # Make sure that the Submit button disables. problem_page.wait_for_submit_disabled()
def test_logout_cancel_no_redirect(self): """ 1) User goes to a problem page. 2) User fills out an answer to the problem. 3) User is logged out because their session id is invalidated or removed. 4) User clicks "check", and sees a confirmation modal asking them to re-authenticate, since they've just been logged out. 5) User clicks "cancel". 6) User is not redirected to the login page. """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) self.assertEqual(problem_page.problem_name, 'TEST PROBLEM') problem_page.fill_answer_numerical('1') self.log_user_out() with problem_page.handle_alert(confirm=False): problem_page.click_submit() problem_page.wait_for_page() self.assertEqual(problem_page.problem_name, 'TEST PROBLEM')
def test_reset_problem_after_submission(self, input_value, correctness): """ Scenario: Test that reset button works regardless the submission correctness status. Given I am attempting a formula problem type with randomization:always configuration When I input the answer Then I should be able to see the MathJax generated preview When I submit the problem Then I should be able to see the reset button When reset button is clicked Then the input pane contents should be clear """ problem_page = ProblemPage(self.browser) problem_page.fill_answer_numerical(input_value) problem_page.verify_mathjax_rendered_in_preview() problem_page.click_submit() self.assertEqual(problem_page.get_simpleprob_correctness(), correctness) self.assertTrue(problem_page.is_reset_button_present()) problem_page.click_reset() self.assertEqual(problem_page.get_numerical_input_value, '')
def test_course_is_unblocked_as_soon_as_student_passes_entrance_exam_2( self): """ Scenario: Ensure that entrance exam status message is updated and courseware is unblocked as soon as student passes entrance exam. Given I have a course with entrance exam as pre-requisite When I pass entrance exam Then I can see complete TOC of course And I can see message indicating my pass status """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) self.assertEqual(problem_page.wait_for_page().problem_name, 'HEIGHT OF EIFFEL TOWER') self.assertTrue(self.courseware_page.has_entrance_exam_message()) self.assertFalse(self.courseware_page.has_passed_message()) problem_page.click_choice('choice_1') problem_page.click_submit() self.courseware_page.wait_for_page() self.assertTrue(self.courseware_page.has_passed_message()) self.assertEqual(self.courseware_page.num_sections, 2)
def test_score_reset_after_resetting_problem(self, input_value, correctness, score_before_reset, score_after_reset): """ Scenario: Test that score resets after the formula problem is resetted. Given I am attempting a formula problem type with randomization:always configuration When I input the answer Then I should be able to see the MathJax generated preview When I submit the problem Then I should be able to view the score that I received And The reset button should be present and is clickable When the reset button is clicked Then the score resets to zero """ problem_page = ProblemPage(self.browser) problem_page.fill_answer_numerical(input_value) problem_page.verify_mathjax_rendered_in_preview() problem_page.click_submit() self.assertEqual(problem_page.get_simpleprob_correctness(), correctness) self.assertIn(score_before_reset, problem_page.problem_progress_graded_value) self.assertTrue(problem_page.is_reset_button_present()) problem_page.click_reset() self.assertIn(score_after_reset, problem_page.problem_progress_graded_value)
def test_notification_updates(self): """ Verifies that the notification is removed and not visible when it should be """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) problem_page.click_choice("choice_2") self.assertFalse(problem_page.is_success_notification_visible()) problem_page.click_submit() problem_page.wait_success_notification() # Clicking Save should clear the submit notification problem_page.click_save() self.assertFalse(problem_page.is_success_notification_visible()) problem_page.wait_for_save_notification() # Changing the answer should clear the save notification problem_page.click_choice("choice_1") self.assertFalse(problem_page.is_save_notification_visible()) problem_page.click_save() # Submitting the problem again should clear the save notification problem_page.click_submit() problem_page.wait_incorrect_notification() self.assertFalse(problem_page.is_save_notification_visible())
def test_score_reset_after_resetting_problem(self, input_value, correctness, score_before_reset, score_after_reset): """ Scenario: Test that score resets after the formula problem is resetted. Given I am attempting a formula problem type with randomization:always configuration When I input the answer Then I should be able to see the MathJax generated preview When I submit the problem Then I should be able to view the score that I received And The reset button should be present and is clickable When the reset button is clicked Then the score resets to zero """ problem_page = ProblemPage(self.browser) problem_page.fill_answer_numerical(input_value) problem_page.verify_mathjax_rendered_in_preview() problem_page.click_submit() self.assertEqual(problem_page.get_simpleprob_correctness(), correctness) self.assertIn(score_before_reset, problem_page.problem_progress_graded_value) self.assertTrue(problem_page.is_reset_button_present()) problem_page.click_reset() self.assertIn(score_after_reset, problem_page.problem_progress_graded_value)
def test_reset_problem_after_changing_correctness(self): """ Scenario: Verify that formula problem can be resetted after changing the correctness. Given I am attempting a formula problem type When I answer it correctly Then the correctness status should be visible And reset button is not rendered When I change my submission to incorrect Then the reset button appears and is clickable """ problem_page = ProblemPage(self.browser) problem_page.fill_answer_numerical('R_1*R_2/R_3') problem_page.verify_mathjax_rendered_in_preview() problem_page.click_submit() self.assertTrue(problem_page.simpleprob_is_correct()) self.assertFalse(problem_page.is_reset_button_present()) problem_page.fill_answer_numerical('R_1/R_3') problem_page.click_submit() self.assertFalse(problem_page.simpleprob_is_correct()) self.assertTrue(problem_page.is_reset_button_present()) problem_page.click_reset() self.assertEqual(problem_page.get_numerical_input_value, '')
def test_reset_problem_after_changing_correctness(self): """ Scenario: Verify that formula problem can be resetted after changing the correctness. Given I am attempting a formula problem type When I answer it correctly Then the correctness status should be visible And reset button is not rendered When I change my submission to incorrect Then the reset button appears and is clickable """ problem_page = ProblemPage(self.browser) problem_page.fill_answer_numerical('R_1*R_2/R_3') problem_page.verify_mathjax_rendered_in_preview() problem_page.click_submit() self.assertTrue(problem_page.simpleprob_is_correct()) self.assertFalse(problem_page.is_reset_button_present()) problem_page.fill_answer_numerical('R_1/R_3') problem_page.click_submit() self.assertFalse(problem_page.simpleprob_is_correct()) self.assertTrue(problem_page.is_reset_button_present()) problem_page.click_reset() self.assertEqual(problem_page.get_numerical_input_value, '')
def test_status_removed_after_save_before_submit(self): """ Scenario: User should see the status removed when saving after submitting an answer and reloading the page. Given that I have loaded the problem page And a choice has been selected and submitted When I change the choice And Save the problem And reload the problem page Then I should see the save notification and I should not see any indication of problem status """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) problem_page.click_choice("choice_1") problem_page.click_submit() problem_page.wait_incorrect_notification() problem_page.wait_for_expected_status('label.choicegroup_incorrect', 'incorrect') problem_page.click_choice("choice_2") self.assertFalse(problem_page.is_expected_status_visible('label.choicegroup_incorrect')) problem_page.click_save() problem_page.wait_for_save_notification() # Refresh the page and the status should not be added self.courseware_page.visit() self.assertFalse(problem_page.is_expected_status_visible('label.choicegroup_incorrect')) self.assertTrue(problem_page.is_save_notification_visible())
def test_reset_correctness_after_changing_answer(self, input_value, correctness, next_input): """ Scenario: Test that formula problem can be resetted after changing the answer. Given I am attempting a formula problem type with randomization:always configuration When I input an answer Then the mathjax generated preview should be visible When I submit the problem, I can see the correctness status When I only input another answer Then the correctness status is no longer visible And I am able to see the reset button And when I click the reset button Then input pane contents are cleared """ problem_page = ProblemPage(self.browser) problem_page.fill_answer_numerical(input_value) problem_page.verify_mathjax_rendered_in_preview() problem_page.click_submit() self.assertEqual(problem_page.get_simpleprob_correctness(), correctness) problem_page.fill_answer_numerical(next_input) self.assertIsNone(problem_page.get_simpleprob_correctness()) self.assertTrue(problem_page.is_reset_button_present()) problem_page.click_reset() self.assertEqual(problem_page.get_numerical_input_value, '')
def test_status_removed_after_save_before_submit(self): """ Scenario: User should see the status removed when saving after submitting an answer and reloading the page. Given that I have loaded the problem page And a choice has been selected and submitted When I change the choice And Save the problem And reload the problem page Then I should see the save notification and I should not see any indication of problem status """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) problem_page.click_choice("choice_1") problem_page.click_submit() problem_page.wait_incorrect_notification() problem_page.wait_for_expected_status('label.choicegroup_incorrect', 'incorrect') problem_page.click_choice("choice_2") self.assertFalse(problem_page.is_expected_status_visible('label.choicegroup_incorrect')) problem_page.click_save() problem_page.wait_for_save_notification() # Refresh the page and the status should not be added self.courseware_page.visit() self.assertFalse(problem_page.is_expected_status_visible('label.choicegroup_incorrect')) self.assertTrue(problem_page.is_save_notification_visible())
def test_reset_correctness_after_changing_answer(self, input_value, correctness, next_input): """ Scenario: Test that formula problem can be resetted after changing the answer. Given I am attempting a formula problem type with randomization:always configuration When I input an answer Then the mathjax generated preview should be visible When I submit the problem, I can see the correctness status When I only input another answer Then the correctness status is no longer visible And I am able to see the reset button And when I click the reset button Then input pane contents are cleared """ problem_page = ProblemPage(self.browser) problem_page.fill_answer_numerical(input_value) problem_page.verify_mathjax_rendered_in_preview() problem_page.click_submit() self.assertEqual(problem_page.get_simpleprob_correctness(), correctness) problem_page.fill_answer_numerical(next_input) self.assertIsNone(problem_page.get_simpleprob_correctness()) self.assertTrue(problem_page.is_reset_button_present()) problem_page.click_reset() self.assertEqual(problem_page.get_numerical_input_value, '')