def test_timed_exam_flow(self, hide_after_due): """ Given that I am a staff member on the exam settings section select advanced settings tab When I Make the exam timed. And I login as a verified student. And visit the courseware as a verified student. And I start the timed exam Then I am taken to the exam with a timer bar showing When I finish the exam Then I see the exam submitted dialog in place of the exam When I log back into studio as a staff member And change the problem's due date to be in the past And log back in as the original verified student Then I see the exam or message in accordance with the hide_after_due setting """ self._setup_and_take_timed_exam(hide_after_due) LogoutPage(self.browser).visit() self._auto_auth("STAFF_TESTER", "*****@*****.**", True) self.course_outline.visit() last_week = (datetime.today() - timedelta(days=7)).strftime("%m/%d/%Y") self.course_outline.change_problem_due_date(last_week) LogoutPage(self.browser).visit() self._auto_auth(self.USERNAME, self.EMAIL, False) self.courseware_page.visit() self.assertEqual(self.courseware_page.has_submitted_exam_message(), hide_after_due)
def _delete_section(self, index): """ Delete a section at index `index` """ # Logout and login as staff LogoutPage(self.browser).visit() AutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id, staff=True).visit() # Visit course outline page in studio. self.studio_course_outline_page.visit() self.studio_course_outline_page.wait_for_page() self.studio_course_outline_page.section_at(index).delete() # Logout and login as a student. LogoutPage(self.browser).visit() AutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id).visit() # Visit courseware as a student. self.courseware_page.visit() self.courseware_page.wait_for_page()
def test_entrance_exam_section(self): """ Scenario: Any course that is enabled for an entrance exam, should have entrance exam section in the course outline. Given that I visit the course outline And entrance exams are not yet enabled Then I should not see an "Entrance Exam" section When I log in as staff And enable entrance exams And I visit the course outline again as student Then there should be an "Entrance Exam" chapter.' """ # visit the course outline and make sure there is no "Entrance Exam" section. self.course_home_page.visit() self.assertNotIn('Entrance Exam', list(self.course_home_page.outline.sections.keys())) # Logout and login as a staff. LogoutPage(self.browser).visit() AutoAuthPage(self.browser, course_id=self.course_id, staff=True).visit() # visit course settings page and set/enabled entrance exam for that course. self.settings_page.visit() self.settings_page.require_entrance_exam() self.settings_page.save_changes() # Logout and login as a student. LogoutPage(self.browser).visit() AutoAuthPage(self.browser, course_id=self.course_id, staff=False).visit() # visit the course outline and make sure there is an "Entrance Exam" section. self.course_home_page.visit() self.assertIn('Entrance Exam', list(self.course_home_page.outline.sections.keys()))
def test_courseware(self): """ Test courseware if recent visited subsection become unpublished. """ # Visit problem page as a student. self._goto_problem_page() # Logout and login as a staff user. LogoutPage(self.browser).visit() self._auto_auth("STAFF_TESTER", "*****@*****.**", True) # Visit course outline page in studio. self.course_outline.visit() # Set release date for subsection in future. self.course_outline.change_problem_release_date() # Logout and login as a student. LogoutPage(self.browser).visit() self._auto_auth(self.USERNAME, self.EMAIL, False) # Visit courseware as a student. self.courseware_page.visit() # Problem name should be "Test Problem 2". self.assertEqual(self.problem_page.problem_name, 'Test Problem 2')
def _auto_auth(self, username, email, staff): """ Logout and login with given credentials. """ LogoutPage(self.browser).visit() AutoAuthPage(self.browser, username=username, email=email, staff=staff).visit()
def test_hinted_login(self): """ Test the login page when coming from course URL that specified which third party provider to use """ # Create a user account and link it to third party auth with the dummy provider: AutoAuthPage(self.browser, course_id=self.course_id).visit() self._link_dummy_account() try: LogoutPage(self.browser).visit() # When not logged in, try to load a course URL that includes the provider hint ?tpa_hint=... course_page = CoursewarePage(self.browser, self.course_id) self.browser.get(course_page.url + '?tpa_hint=oa2-dummy') # We should now be redirected to the login page self.login_page.wait_for_page() self.assertIn( "Would you like to sign in using your Dummy credentials?", self.login_page.hinted_login_prompt) # Baseline screen-shots are different for chrome and firefox. #self.assertScreenshot('#hinted-login-form', 'hinted-login-{}'.format(self.browser.name), .25) #The line above is commented out temporarily see SOL-1937 self.login_page.click_third_party_dummy_provider() # We should now be redirected to the course page course_page.wait_for_page() finally: self._unlink_dummy_account()
def test_field_visiblity_with_all_exam_types(self): """ Given that I am a staff member And I have visited the course outline page in studio. And the subsection edit dialog is open select advanced settings tab For each of None, Timed, Proctored, and Practice exam types The time allotted and review rules fields have proper visibility None: False, False Timed: True, False Proctored: True, True Practice: True, False """ LogoutPage(self.browser).visit() self._auto_auth("STAFF_TESTER", "*****@*****.**", True) self.course_outline.visit() self.course_outline.open_subsection_settings_dialog() self.course_outline.select_advanced_tab() self.course_outline.select_none_exam() self.assertFalse(self.course_outline.time_allotted_field_visible()) self.assertFalse(self.course_outline.exam_review_rules_field_visible()) self.course_outline.select_timed_exam() self.assertTrue(self.course_outline.time_allotted_field_visible()) self.assertFalse(self.course_outline.exam_review_rules_field_visible()) self.course_outline.select_proctored_exam() self.assertTrue(self.course_outline.time_allotted_field_visible()) self.assertTrue(self.course_outline.exam_review_rules_field_visible()) self.course_outline.select_practice_exam() self.assertTrue(self.course_outline.time_allotted_field_visible()) self.assertFalse(self.course_outline.exam_review_rules_field_visible())
def _create_user(self): """ Create a unique user """ auto_auth = AutoAuthPage(self.browser).visit() user_info = auto_auth.user_info LogoutPage(self.browser).visit() return user_info
def test_visit_login_page(self): """ Produce a HAR for loading the Login page. """ login_page = LoginPage(self.browser) # Logout previously logged in user to be able to see Login page. LogoutPage(self.browser).visit() self._make_har_file(login_page)
def test_third_party_register(self): """ Test that we can register using third party credentials, and that the third party account gets linked to the edX account. """ # Navigate to the register page self.register_page.visit() # Baseline screen-shots are different for chrome and firefox. #self.assertScreenshot('#register .login-providers', 'register-providers-{}'.format(self.browser.name), .25) # The line above is commented out temporarily see SOL-1937 # Try to authenticate using the "Dummy" provider self.register_page.click_third_party_dummy_provider() # The user will be redirected somewhere and then back to the register page: msg_text = self.register_page.wait_for_auth_status_message() self.assertEqual(self.register_page.current_form, "register") self.assertIn("You've successfully signed into Dummy", msg_text) self.assertIn("We just need a little more information", msg_text) # Now the form should be pre-filled with the data from the Dummy provider: self.assertEqual(self.register_page.email_value, "*****@*****.**") self.assertEqual(self.register_page.full_name_value, "William Adama") self.assertIn("Galactica1", self.register_page.username_value) # Set country, accept the terms, and submit the form: self.register_page.register(country="US", favorite_movie="Battlestar Galactica", terms_of_service=True) # Expect that we reach the dashboard and we're auto-enrolled in the course course_names = self.dashboard_page.wait_for_page().available_courses self.assertIn(self.course_info["display_name"], course_names) # Now logout and check that we can log back in instantly (because the account is linked): LogoutPage(self.browser).visit() login_page = CombinedLoginAndRegisterPage(self.browser, start_page="login") login_page.visit() login_page.click_third_party_dummy_provider() self.dashboard_page.wait_for_page() # Now unlink the account (To test the account settings view and also to prevent cross-test side effects) account_settings = AccountSettingsPage(self.browser).visit() # switch to "Linked Accounts" tab account_settings.switch_account_settings_tabs('accounts-tab') field_id = "auth-oa2-dummy" account_settings.wait_for_field(field_id) self.assertEqual("Unlink This Account", account_settings.link_title_for_link_field(field_id)) account_settings.click_on_link_in_link_field(field_id) account_settings.wait_for_message(field_id, "Successfully unlinked")
def setUp(self): super(GatingTest, self).setUp() self.logout_page = LogoutPage(self.browser) self.course_home_page = CourseHomePage(self.browser, self.course_id) self.courseware_page = CoursewarePage(self.browser, self.course_id) self.studio_course_outline = StudioCourseOutlinePage( self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run']) xml = dedent(""" <problem> <p>What is height of eiffel tower without the antenna?.</p> <multiplechoiceresponse> <choicegroup label="What is height of eiffel tower without the antenna?" type="MultipleChoice"> <choice correct="false">324 meters<choicehint>Antenna is 24 meters high</choicehint></choice> <choice correct="true">300 meters</choice> <choice correct="false">224 meters</choice> <choice correct="false">400 meters</choice> </choicegroup> </multiplechoiceresponse> </problem> """) self.problem1 = XBlockFixtureDesc('problem', 'HEIGHT OF EIFFEL TOWER', data=xml) # Install a course with sections/problems course_fixture = CourseFixture(self.course_info['org'], self.course_info['number'], self.course_info['run'], self.course_info['display_name']) course_fixture.add_advanced_settings({ "enable_subsection_gating": { "value": "true" }, 'enable_proctored_exams': { "value": "true" } }) course_fixture.add_children( XBlockFixtureDesc('chapter', 'Test Section 1').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 1').add_children( self.problem1), XBlockFixtureDesc('sequential', 'Test Subsection 2').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 2')), XBlockFixtureDesc('sequential', 'Test Subsection 3').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 3')), )).install()
def _go_to_unit_page(self, change_login=True): """ Open unit page in Studio """ if change_login: LogoutPage(self.browser).visit() self._auto_auth(self.STAFF_USERNAME, self.STAFF_EMAIL, True) self.course_outline.visit() subsection = self.course_outline.section(SECTION_NAME).subsection(SUBSECTION_NAME) return subsection.expand_subsection().unit(UNIT_NAME).go_to()
def test_bookmark_shows_updated_breadcrumb_after_publish(self): """ Scenario: A bookmark breadcrumb trail is updated after publishing the changed display name. Given that I am a registered user And I visit my courseware page And I can see bookmarked unit Then I visit unit page in studio Then I change unit display_name And I publish the changes Then I visit my courseware page And I visit bookmarks list page When I see the bookmark Then I can see the breadcrumb trail with updated display_name. """ self._test_setup(num_chapters=1) self._bookmark_units(num_units=1) self._navigate_to_bookmarks_list() self._verify_breadcrumbs(num_units=1) LogoutPage(self.browser).visit() LmsAutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id, staff=True).visit() modified_name = "Updated name" self.update_and_publish_block_display_name(modified_name) LogoutPage(self.browser).visit() LmsAutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id).visit() self.courseware_page.visit() self._navigate_to_bookmarks_list() self._verify_breadcrumbs(num_units=1, modified_name=modified_name)
def test_entrance_exam_section_2(self): """ Scenario: Any course that is enabled for an entrance exam, should have entrance exam chapter at course page. Given that I am on the course page When I view the course that has an entrance exam Then there should be an "Entrance Exam" chapter.' """ courseware_page = CoursewarePage(self.browser, self.course_id) entrance_exam_link_selector = '.accordion .course-navigation .chapter .group-heading' # visit course page and make sure there is not entrance exam chapter. courseware_page.visit() courseware_page.wait_for_page() self.assertFalse( element_has_text(page=courseware_page, css_selector=entrance_exam_link_selector, text='Entrance Exam')) # Logout and login as a staff. LogoutPage(self.browser).visit() AutoAuthPage(self.browser, course_id=self.course_id, staff=True).visit() # visit course settings page and set/enabled entrance exam for that course. self.settings_page.visit() self.settings_page.require_entrance_exam() self.settings_page.save_changes() # Logout and login as a student. LogoutPage(self.browser).visit() AutoAuthPage(self.browser, course_id=self.course_id, staff=False).visit() # visit course info page and make sure there is an "Entrance Exam" section. courseware_page.visit() courseware_page.wait_for_page() self.assertTrue( element_has_text(page=courseware_page, css_selector=entrance_exam_link_selector, text='Entrance Exam'))
def test_can_create_proctored_exam_in_studio(self): """ Given that I am a staff member When I visit the course outline page in studio. And open the subsection edit dialog Then I can view all settings related to Proctored and timed exams """ LogoutPage(self.browser).visit() self._auto_auth("STAFF_TESTER", "*****@*****.**", True) self.course_outline.visit() self.course_outline.open_subsection_settings_dialog() self.assertTrue(self.course_outline.proctoring_items_are_displayed())
def test_proctored_exam_flow(self): """ Given that I am a staff member on the exam settings section select advanced settings tab When I Make the exam proctored. And I login as a verified student. And visit the courseware as a verified student. Then I can see an option to take the exam as a proctored exam. """ LogoutPage(self.browser).visit() self._auto_auth("STAFF_TESTER", "*****@*****.**", True) self.course_outline.visit() self.course_outline.open_subsection_settings_dialog() self.course_outline.select_advanced_tab() self.course_outline.make_exam_proctored() LogoutPage(self.browser).visit() self._login_as_a_verified_user() self.courseware_page.visit() self.assertTrue(self.courseware_page.can_start_proctored_exam)
def _setup_and_take_timed_exam(self, hide_after_due=False): """ Helper to perform the common action "set up a timed exam as staff, then take it as student" """ LogoutPage(self.browser).visit() self._auto_auth("STAFF_TESTER", "*****@*****.**", True) self.course_outline.visit() self.course_outline.open_subsection_settings_dialog() self.course_outline.select_advanced_tab() self.course_outline.make_exam_timed(hide_after_due=hide_after_due) LogoutPage(self.browser).visit() self._login_as_a_verified_user() self.courseware_page.visit() self.courseware_page.start_timed_exam() self.assertTrue(self.courseware_page.is_timer_bar_present) self.courseware_page.stop_timed_exam() self.assertTrue(self.courseware_page.has_submitted_exam_message()) LogoutPage(self.browser).visit()
def _create_unique_user(self): """ Create a new user with a unique name and email. """ username = "******".format(uuid=self.unique_id[0:6]) email = "{user}@example.com".format(user=username) password = "******" # Create the user (automatically logs us in) AutoAuthPage(self.browser, username=username, email=email, password=password).visit() # Log out LogoutPage(self.browser).visit() return (email, password)
def test_masquerade_visibility_override(self): """ Given that a timed exam problem exists in the course And a student has taken that exam And that exam is hidden to the student And I am a staff user masquerading as the student Then I should be able to see the exam content """ self._setup_and_take_timed_exam() LogoutPage(self.browser).visit() self._auto_auth("STAFF_TESTER", "*****@*****.**", True) self.courseware_page.visit() staff_page = StaffPage(self.browser, self.course_id) self.assertEqual(staff_page.staff_view_mode, 'Staff') staff_page.set_staff_view_mode_specific_student(self.USERNAME) self.assertFalse(self.courseware_page.has_submitted_exam_message())
def initialize_different_user(self, privacy=None, birth_year=None): """ Initialize the profile page for a different test user """ username, user_id = self.log_in_as_unique_user() # Set the privacy for the new user if privacy is None: privacy = self.PRIVACY_PUBLIC self.visit_profile_page(username, privacy=privacy) # Set the user's year of birth if birth_year: self.set_birth_year(birth_year) # Log the user out LogoutPage(self.browser).visit() return username, user_id
def test_third_party_login(self): """ Test that we can login using third party credentials, and that the third party account gets linked to the edX account. """ # Create a user account email, password = self._create_unique_user() # Navigate to the login page self.login_page.visit() # Baseline screen-shots are different for chrome and firefox. #self.assertScreenshot('#login .login-providers', 'login-providers-{}'.format(self.browser.name), .25) #The line above is commented out temporarily see SOL-1937 # Try to log in using "Dummy" provider self.login_page.click_third_party_dummy_provider() # The user will be redirected somewhere and then back to the login page: msg_text = self.login_page.wait_for_auth_status_message() self.assertIn("You have successfully signed into Dummy", msg_text) self.assertIn( u"To link your accounts, sign in now using your édX password", msg_text ) # Now login with username and password: self.login_page.login(email=email, password=password) # Expect that we reach the dashboard and we're auto-enrolled in the course course_names = self.dashboard_page.wait_for_page().available_courses self.assertIn(self.course_info["display_name"], course_names) try: # Now logout and check that we can log back in instantly (because the account is linked): LogoutPage(self.browser).visit() self.login_page.visit() self.login_page.click_third_party_dummy_provider() self.dashboard_page.wait_for_page() finally: self._unlink_dummy_account()