def setUp(self): super(CoursewareTest, self).setUp() self.courseware_page = CoursewarePage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) self.course_outline = CourseOutlinePage(self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run']) # Install a course with sections/problems, tabs, updates, and handouts self.course_fix = CourseFixture(self.course_info['org'], self.course_info['number'], self.course_info['run'], self.course_info['display_name']) self.course_fix.add_children( XBlockFixtureDesc('chapter', 'Test Section 1').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 1').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 1'))), XBlockFixtureDesc('chapter', 'Test Section 2').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 2').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 2')))).install() # Auto-auth register for the course. self._auto_auth(self.USERNAME, self.EMAIL, False)
def setUp(self): super(CertificateProgressPageTest, self).setUp() # set same course number as we have in fixture json self.course_info['number'] = "3355358979513794782079645765720179311111" test_certificate_config = { 'id': 1, 'name': 'Certificate name', 'description': 'Certificate description', 'course_title': 'Course title override', 'signatories': [], 'version': 1, 'is_active': True } course_settings = {'certificates': test_certificate_config} self.course_fixture = CourseFixture( self.course_info["org"], self.course_info["number"], self.course_info["run"], self.course_info["display_name"], settings=course_settings ) self.course_fixture.add_advanced_settings({ "cert_html_view_enabled": {"value": "true"} }) self.course_fixture.add_update( CourseUpdateDesc(date='January 29, 2014', content='Test course update1') ) self.course_fixture.add_children( XBlockFixtureDesc('static_tab', 'Test Static Tab'), XBlockFixtureDesc('chapter', 'Test Section').add_children( XBlockFixtureDesc('sequential', 'Test Subsection', grader_type='Final Exam').add_children( XBlockFixtureDesc('problem', 'Test Problem 1', data=load_data_str('multiple_choice.xml')), XBlockFixtureDesc('html', 'Test HTML'), ) ), XBlockFixtureDesc('chapter', 'Test Section 2').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 2', grader_type='Midterm Exam').add_children( XBlockFixtureDesc('problem', 'Test Problem 2', data=load_data_str('formula_problem.xml')), ) ) ) self.course_fixture.install() self.user_id = "99" # we have created a user with this id in fixture self.cert_fixture = CertificateConfigFixture(self.course_id, test_certificate_config) self.course_info_page = CourseInfoPage(self.browser, self.course_id) self.progress_page = ProgressPage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) self.tab_nav = TabNavPage(self.browser)
def setUp(self): """ Initialization of pages and course fixture for video tests """ super(VideoBaseTest, self).setUp() self.video = VideoPage(self.browser) self.tab_nav = TabNavPage(self.browser) self.course_nav = CourseNavPage(self.browser) self.courseware = CoursewarePage(self.browser, self.course_id) self.course_info_page = CourseInfoPage(self.browser, self.course_id) self.auth_page = AutoAuthPage(self.browser, course_id=self.course_id) self.course_fixture = CourseFixture( self.course_info['org'], self.course_info['number'], self.course_info['run'], self.course_info['display_name'] ) self.metadata = None self.assets = [] self.contents_of_verticals = None self.youtube_configuration = {} self.user_info = {} # reset youtube stub server self.addCleanup(YouTubeStubConfig.reset)
def setUp(self): super(CoursewareTest, self).setUp() self.courseware_page = CoursewarePage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) self.course_outline = CourseOutlinePage( self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run'] ) # Install a course with sections/problems, tabs, updates, and handouts self.course_fix = CourseFixture( self.course_info['org'], self.course_info['number'], self.course_info['run'], self.course_info['display_name'] ) self.course_fix.add_children( XBlockFixtureDesc('chapter', 'Test Section 1').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 1').add_children( XBlockFixtureDesc('problem', 'Test Problem 1') ) ), XBlockFixtureDesc('chapter', 'Test Section 2').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 2').add_children( XBlockFixtureDesc('problem', 'Test Problem 2') ) ) ).install() # Auto-auth register for the course. self._auto_auth(self.USERNAME, self.EMAIL, False)
def setUp(self): super(CertificateProgressPageTest, self).setUp() # set same course number as we have in fixture json self.course_info["number"] = "3355358979513794782079645765720179311111" test_certificate_config = { "id": 1, "name": "Certificate name", "description": "Certificate description", "course_title": "Course title override", "signatories": [], "version": 1, "is_active": True, } course_settings = {"certificates": test_certificate_config} self.course_fixture = CourseFixture( self.course_info["org"], self.course_info["number"], self.course_info["run"], self.course_info["display_name"], settings=course_settings, ) self.course_fixture.add_advanced_settings({"cert_html_view_enabled": {"value": "true"}}) self.course_fixture.add_update(CourseUpdateDesc(date="January 29, 2014", content="Test course update1")) self.course_fixture.add_children( XBlockFixtureDesc("static_tab", "Test Static Tab"), XBlockFixtureDesc("chapter", "Test Section").add_children( XBlockFixtureDesc("sequential", "Test Subsection", grader_type="Final Exam").add_children( XBlockFixtureDesc("problem", "Test Problem 1", data=load_data_str("multiple_choice.xml")), XBlockFixtureDesc("html", "Test HTML"), ) ), XBlockFixtureDesc("chapter", "Test Section 2").add_children( XBlockFixtureDesc("sequential", "Test Subsection 2", grader_type="Midterm Exam").add_children( XBlockFixtureDesc("problem", "Test Problem 2", data=load_data_str("formula_problem.xml")) ) ), ) self.course_fixture.install() self.user_id = "99" # we have created a user with this id in fixture self.cert_fixture = CertificateConfigFixture(self.course_id, test_certificate_config) self.course_info_page = CourseInfoPage(self.browser, self.course_id) self.progress_page = ProgressPage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) self.tab_nav = TabNavPage(self.browser)
def setUp(self): """ Initialize test setup. """ super(BookmarksTest, self).setUp() self.course_outline_page = CourseOutlinePage( self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run']) self.courseware_page = CoursewarePage(self.browser, self.course_id) self.bookmarks_page = BookmarksPage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) # Get session to be used for bookmarking units self.session = requests.Session() params = { 'username': self.USERNAME, 'email': self.EMAIL, 'course_id': self.course_id } response = self.session.get(BASE_URL + "/auto_auth", params=params) self.assertTrue(response.ok, "Failed to get session")
def setUp(self): super(CoursewareMultipleVerticalsTest, self).setUp() self.courseware_page = CoursewarePage(self.browser, self.course_id) self.course_outline = CourseOutlinePage( self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run'] ) # Install a course with sections/problems, tabs, updates, and handouts course_fix = CourseFixture( self.course_info['org'], self.course_info['number'], self.course_info['run'], self.course_info['display_name'] ) course_fix.add_children( XBlockFixtureDesc('chapter', 'Test Section 1').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 1,1').add_children( XBlockFixtureDesc('problem', 'Test Problem 1', data='<problem>problem 1 dummy body</problem>'), XBlockFixtureDesc('html', 'html 1', data="<html>html 1 dummy body</html>"), XBlockFixtureDesc('problem', 'Test Problem 2', data="<problem>problem 2 dummy body</problem>"), XBlockFixtureDesc('html', 'html 2', data="<html>html 2 dummy body</html>"), ), XBlockFixtureDesc('sequential', 'Test Subsection 1,2').add_children( XBlockFixtureDesc('problem', 'Test Problem 3', data='<problem>problem 3 dummy body</problem>'), ), XBlockFixtureDesc( 'sequential', 'Test HIDDEN Subsection', metadata={'visible_to_staff_only': True} ).add_children( XBlockFixtureDesc('problem', 'Test HIDDEN Problem', data='<problem>hidden problem</problem>'), ), ), XBlockFixtureDesc('chapter', 'Test Section 2').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 2,1').add_children( XBlockFixtureDesc('problem', 'Test Problem 4', data='<problem>problem 4 dummy body</problem>'), ), ), XBlockFixtureDesc('chapter', 'Test HIDDEN Section', metadata={'visible_to_staff_only': True}).add_children( XBlockFixtureDesc('sequential', 'Test HIDDEN Subsection'), ), ).install() # Auto-auth register for the course. AutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id, staff=False).visit() self.courseware_page.visit() self.course_nav = CourseNavPage(self.browser)
def setUp(self, is_staff=True): """ Create search page and course content to search """ # create test file in which index for this test will live with open(self.TEST_INDEX_FILENAME, "w+") as index_file: json.dump({}, index_file) self.addCleanup(remove_file, self.TEST_INDEX_FILENAME) super(SplitTestCoursewareSearchTest, self).setUp(is_staff=is_staff) self.staff_user = self.user self.courseware_search_page = CoursewareSearchPage( self.browser, self.course_id) self.course_navigation_page = CourseNavPage(self.browser) self.course_outline = CourseOutlinePage(self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run']) self._create_group_configuration() self._studio_reindex()
def setUp(self): """ Initialize test setup. """ super(BookmarksTest, self).setUp() self.course_outline_page = CourseOutlinePage( self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run'] ) self.courseware_page = CoursewarePage(self.browser, self.course_id) self.bookmarks_page = BookmarksPage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) # Get session to be used for bookmarking units self.session = requests.Session() params = {'username': self.USERNAME, 'email': self.EMAIL, 'course_id': self.course_id} response = self.session.get(BASE_URL + "/auto_auth", params=params) self.assertTrue(response.ok, "Failed to get session")
class CoursewareMultipleVerticalsTest(UniqueCourseTest, EventsTestMixin): """ Test courseware with multiple verticals """ USERNAME = "******" EMAIL = "*****@*****.**" def setUp(self): super(CoursewareMultipleVerticalsTest, self).setUp() self.courseware_page = CoursewarePage(self.browser, self.course_id) self.course_outline = CourseOutlinePage( self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run'] ) # Install a course with sections/problems, tabs, updates, and handouts course_fix = CourseFixture( self.course_info['org'], self.course_info['number'], self.course_info['run'], self.course_info['display_name'] ) course_fix.add_children( XBlockFixtureDesc('chapter', 'Test Section 1').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 1,1').add_children( XBlockFixtureDesc('problem', 'Test Problem 1', data='<problem>problem 1 dummy body</problem>'), XBlockFixtureDesc('html', 'html 1', data="<html>html 1 dummy body</html>"), XBlockFixtureDesc('problem', 'Test Problem 2', data="<problem>problem 2 dummy body</problem>"), XBlockFixtureDesc('html', 'html 2', data="<html>html 2 dummy body</html>"), ), XBlockFixtureDesc('sequential', 'Test Subsection 1,2').add_children( XBlockFixtureDesc('problem', 'Test Problem 3', data='<problem>problem 3 dummy body</problem>'), ), XBlockFixtureDesc( 'sequential', 'Test HIDDEN Subsection', metadata={'visible_to_staff_only': True} ).add_children( XBlockFixtureDesc('problem', 'Test HIDDEN Problem', data='<problem>hidden problem</problem>'), ), ), XBlockFixtureDesc('chapter', 'Test Section 2').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 2,1').add_children( XBlockFixtureDesc('problem', 'Test Problem 4', data='<problem>problem 4 dummy body</problem>'), ), ), XBlockFixtureDesc('chapter', 'Test HIDDEN Section', metadata={'visible_to_staff_only': True}).add_children( XBlockFixtureDesc('sequential', 'Test HIDDEN Subsection'), ), ).install() # Auto-auth register for the course. AutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id, staff=False).visit() self.courseware_page.visit() self.course_nav = CourseNavPage(self.browser) def test_navigation_buttons(self): # start in first section self.assert_navigation_state('Test Section 1', 'Test Subsection 1,1', 0, next_enabled=True, prev_enabled=False) # next takes us to next tab in sequential self.courseware_page.click_next_button_on_top() self.assert_navigation_state('Test Section 1', 'Test Subsection 1,1', 1, next_enabled=True, prev_enabled=True) # go to last sequential position self.courseware_page.go_to_sequential_position(4) self.assert_navigation_state('Test Section 1', 'Test Subsection 1,1', 3, next_enabled=True, prev_enabled=True) # next takes us to next sequential self.courseware_page.click_next_button_on_bottom() self.assert_navigation_state('Test Section 1', 'Test Subsection 1,2', 0, next_enabled=True, prev_enabled=True) # next takes us to next chapter self.courseware_page.click_next_button_on_top() self.assert_navigation_state('Test Section 2', 'Test Subsection 2,1', 0, next_enabled=False, prev_enabled=True) # previous takes us to previous chapter self.courseware_page.click_previous_button_on_top() self.assert_navigation_state('Test Section 1', 'Test Subsection 1,2', 0, next_enabled=True, prev_enabled=True) # previous takes us to last tab in previous sequential self.courseware_page.click_previous_button_on_bottom() self.assert_navigation_state('Test Section 1', 'Test Subsection 1,1', 3, next_enabled=True, prev_enabled=True) # previous takes us to previous tab in sequential self.courseware_page.click_previous_button_on_bottom() self.assert_navigation_state('Test Section 1', 'Test Subsection 1,1', 2, next_enabled=True, prev_enabled=True) # test UI events emitted by navigation filter_sequence_ui_event = lambda event: event.get('name', '').startswith('edx.ui.lms.sequence.') sequence_ui_events = self.wait_for_events(event_filter=filter_sequence_ui_event, timeout=2) legacy_events = [ev for ev in sequence_ui_events if ev['event_type'] in {'seq_next', 'seq_prev', 'seq_goto'}] nonlegacy_events = [ev for ev in sequence_ui_events if ev not in legacy_events] self.assertTrue(all('old' in json.loads(ev['event']) for ev in legacy_events)) self.assertTrue(all('new' in json.loads(ev['event']) for ev in legacy_events)) self.assertFalse(any('old' in json.loads(ev['event']) for ev in nonlegacy_events)) self.assertFalse(any('new' in json.loads(ev['event']) for ev in nonlegacy_events)) self.assert_events_match( [ { 'event_type': 'seq_next', 'event': { 'old': 1, 'new': 2, 'current_tab': 1, 'tab_count': 4, 'widget_placement': 'top', } }, { 'event_type': 'seq_goto', 'event': { 'old': 2, 'new': 4, 'current_tab': 2, 'target_tab': 4, 'tab_count': 4, 'widget_placement': 'top', } }, { 'event_type': 'edx.ui.lms.sequence.next_selected', 'event': { 'current_tab': 4, 'tab_count': 4, 'widget_placement': 'bottom', } }, { 'event_type': 'edx.ui.lms.sequence.next_selected', 'event': { 'current_tab': 1, 'tab_count': 1, 'widget_placement': 'top', } }, { 'event_type': 'edx.ui.lms.sequence.previous_selected', 'event': { 'current_tab': 1, 'tab_count': 1, 'widget_placement': 'top', } }, { 'event_type': 'edx.ui.lms.sequence.previous_selected', 'event': { 'current_tab': 1, 'tab_count': 1, 'widget_placement': 'bottom', } }, { 'event_type': 'seq_prev', 'event': { 'old': 4, 'new': 3, 'current_tab': 4, 'tab_count': 4, 'widget_placement': 'bottom', } }, ], sequence_ui_events ) def test_outline_selected_events(self): self.course_nav.go_to_section('Test Section 1', 'Test Subsection 1,2') self.course_nav.go_to_section('Test Section 2', 'Test Subsection 2,1') # test UI events emitted by navigating via the course outline filter_selected_events = lambda event: event.get('name', '') == 'edx.ui.lms.outline.selected' selected_events = self.wait_for_events(event_filter=filter_selected_events, timeout=2) # note: target_url is tested in unit tests, as the url changes here with every test (it includes GUIDs). self.assert_events_match( [ { 'event_type': 'edx.ui.lms.outline.selected', 'name': 'edx.ui.lms.outline.selected', 'event': { 'target_name': 'Test Subsection 1,2 ', 'widget_placement': 'accordion', } }, { 'event_type': 'edx.ui.lms.outline.selected', 'name': 'edx.ui.lms.outline.selected', 'event': { 'target_name': 'Test Subsection 2,1 ', 'widget_placement': 'accordion', } }, ], selected_events ) def test_link_clicked_events(self): """ Given that I am a user in the courseware When I navigate via the left-hand nav Then a link clicked event is logged """ self.course_nav.go_to_section('Test Section 1', 'Test Subsection 1,2') self.course_nav.go_to_section('Test Section 2', 'Test Subsection 2,1') filter_link_clicked = lambda event: event.get('name', '') == 'edx.ui.lms.link_clicked' link_clicked_events = self.wait_for_events(event_filter=filter_link_clicked, timeout=2) self.assertEqual(len(link_clicked_events), 2) def assert_navigation_state( self, section_title, subsection_title, subsection_position, next_enabled, prev_enabled ): """ Verifies that the navigation state is as expected. """ self.assertTrue(self.course_nav.is_on_section(section_title, subsection_title)) self.assertEquals(self.courseware_page.sequential_position, subsection_position) self.assertEquals(self.courseware_page.is_next_button_enabled, next_enabled) self.assertEquals(self.courseware_page.is_previous_button_enabled, prev_enabled) def test_tab_position(self): # test that using the position in the url direct to correct tab in courseware self.course_nav.go_to_section('Test Section 1', 'Test Subsection 1,1') subsection_url = self.course_nav.active_subsection_url url_part_list = subsection_url.split('/') self.assertEqual(len(url_part_list), 9) course_id = url_part_list[4] chapter_id = url_part_list[-3] subsection_id = url_part_list[-2] problem1_page = CoursewareSequentialTabPage( self.browser, course_id=course_id, chapter=chapter_id, subsection=subsection_id, position=1 ).visit() self.assertIn('problem 1 dummy body', problem1_page.get_selected_tab_content()) html1_page = CoursewareSequentialTabPage( self.browser, course_id=course_id, chapter=chapter_id, subsection=subsection_id, position=2 ).visit() self.assertIn('html 1 dummy body', html1_page.get_selected_tab_content()) problem2_page = CoursewareSequentialTabPage( self.browser, course_id=course_id, chapter=chapter_id, subsection=subsection_id, position=3 ).visit() self.assertIn('problem 2 dummy body', problem2_page.get_selected_tab_content()) html2_page = CoursewareSequentialTabPage( self.browser, course_id=course_id, chapter=chapter_id, subsection=subsection_id, position=4 ).visit() self.assertIn('html 2 dummy body', html2_page.get_selected_tab_content()) @attr('a11y') def test_courseware_a11y(self): """ Run accessibility audit for the problem type. """ self.course_nav.go_to_section('Test Section 1', 'Test Subsection 1,1') # Set the scope to the sequence navigation self.courseware_page.a11y_audit.config.set_scope( include=['div.sequence-nav']) self.courseware_page.a11y_audit.check_for_accessibility_errors()
class BookmarksTest(BookmarksTestMixin): """ Tests to verify bookmarks functionality. """ def setUp(self): """ Initialize test setup. """ super(BookmarksTest, self).setUp() self.course_outline_page = CourseOutlinePage( self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run'] ) self.courseware_page = CoursewarePage(self.browser, self.course_id) self.bookmarks_page = BookmarksPage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) # Get session to be used for bookmarking units self.session = requests.Session() params = {'username': self.USERNAME, 'email': self.EMAIL, 'course_id': self.course_id} response = self.session.get(BASE_URL + "/auto_auth", params=params) self.assertTrue(response.ok, "Failed to get session") def _test_setup(self, num_chapters=2): """ Setup test settings. Arguments: num_chapters: number of chapters to create in course """ self.create_course_fixture(num_chapters) # Auto-auth register for the course. LmsAutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id).visit() self.courseware_page.visit() def _bookmark_unit(self, location): """ Bookmark a unit Arguments: location (str): unit location """ _headers = { 'Content-type': 'application/json', 'X-CSRFToken': self.session.cookies['csrftoken'], } params = {'course_id': self.course_id} data = json.dumps({'usage_id': location}) response = self.session.post( BASE_URL + '/api/bookmarks/v1/bookmarks/', data=data, params=params, headers=_headers ) self.assertTrue(response.ok, "Failed to bookmark unit") def _bookmark_units(self, num_units): """ Bookmark first `num_units` units Arguments: num_units(int): Number of units to bookmarks """ xblocks = self.course_fixture.get_nested_xblocks(category="vertical") for index in range(num_units): self._bookmark_unit(xblocks[index].locator) def _breadcrumb(self, num_units, modified_name=None): """ Creates breadcrumbs for the first `num_units` Arguments: num_units(int): Number of units for which we want to create breadcrumbs Returns: list of breadcrumbs """ breadcrumbs = [] for index in range(num_units): breadcrumbs.append( [ 'TestSection{}'.format(index), 'TestSubsection{}'.format(index), modified_name if modified_name else 'TestVertical{}'.format(index) ] ) return breadcrumbs def _delete_section(self, index): """ Delete a section at index `index` """ # Logout and login as staff LogoutPage(self.browser).visit() StudioAutoAuthPage( self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id, staff=True ).visit() # Visit course outline page in studio. self.course_outline_page.visit() self.course_outline_page.wait_for_page() self.course_outline_page.section_at(index).delete() # Logout and login as a student. LogoutPage(self.browser).visit() LmsAutoAuthPage(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 _toggle_bookmark_and_verify(self, bookmark_icon_state, bookmark_button_state, bookmarked_count): """ Bookmark/Un-Bookmark a unit and then verify """ self.assertTrue(self.courseware_page.bookmark_button_visible) self.courseware_page.click_bookmark_unit_button() self.assertEqual(self.courseware_page.bookmark_icon_visible, bookmark_icon_state) self.assertEqual(self.courseware_page.bookmark_button_state, bookmark_button_state) self.bookmarks_page.click_bookmarks_button() self.assertEqual(self.bookmarks_page.count(), bookmarked_count) def _verify_pagination_info( self, bookmark_count_on_current_page, header_text, previous_button_enabled, next_button_enabled, current_page_number, total_pages ): """ Verify pagination info """ self.assertEqual(self.bookmarks_page.count(), bookmark_count_on_current_page) self.assertEqual(self.bookmarks_page.get_pagination_header_text(), header_text) self.assertEqual(self.bookmarks_page.is_previous_page_button_enabled(), previous_button_enabled) self.assertEqual(self.bookmarks_page.is_next_page_button_enabled(), next_button_enabled) self.assertEqual(self.bookmarks_page.get_current_page_number(), current_page_number) self.assertEqual(self.bookmarks_page.get_total_pages, total_pages) def _navigate_to_bookmarks_list(self): """ Navigates and verifies the bookmarks list page. """ self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self.assertEqual(self.bookmarks_page.results_header_text(), 'My Bookmarks') def _verify_breadcrumbs(self, num_units, modified_name=None): """ Verifies the breadcrumb trail. """ bookmarked_breadcrumbs = self.bookmarks_page.breadcrumbs() # Verify bookmarked breadcrumbs. breadcrumbs = self._breadcrumb(num_units=num_units, modified_name=modified_name) breadcrumbs.reverse() self.assertEqual(bookmarked_breadcrumbs, breadcrumbs) def update_and_publish_block_display_name(self, modified_name): """ Update and publish the block/unit display name. """ self.course_outline_page.visit() self.course_outline_page.wait_for_page() self.course_outline_page.expand_all_subsections() section = self.course_outline_page.section_at(0) container_page = section.subsection_at(0).unit_at(0).go_to() self.course_fixture._update_xblock(container_page.locator, { # pylint: disable=protected-access "metadata": { "display_name": modified_name } }) container_page.visit() container_page.wait_for_page() self.assertEqual(container_page.name, modified_name) container_page.publish_action.click() def test_bookmark_button(self): """ Scenario: Bookmark unit button toggles correctly Given that I am a registered user And I visit my courseware page For first 2 units I visit the unit And I can see the Bookmark button When I click on Bookmark button Then unit should be bookmarked Then I click again on the bookmark button And I should see a unit un-bookmarked """ self._test_setup() for index in range(2): self.course_nav.go_to_section('TestSection{}'.format(index), 'TestSubsection{}'.format(index)) self._toggle_bookmark_and_verify(True, 'bookmarked', 1) self.bookmarks_page.click_bookmarks_button(False) self._toggle_bookmark_and_verify(False, '', 0) def test_empty_bookmarks_list(self): """ Scenario: An empty bookmarks list is shown if there are no bookmarked units. Given that I am a registered user And I visit my courseware page And I can see the Bookmarks button When I click on Bookmarks button Then I should see an empty bookmarks list And empty bookmarks list content is correct """ self._test_setup() self.assertTrue(self.bookmarks_page.bookmarks_button_visible()) self.bookmarks_page.click_bookmarks_button() self.assertEqual(self.bookmarks_page.results_header_text(), 'My Bookmarks') self.assertEqual(self.bookmarks_page.empty_header_text(), 'You have not bookmarked any courseware pages yet.') empty_list_text = ("Use bookmarks to help you easily return to courseware pages. To bookmark a page, " "select Bookmark in the upper right corner of that page. To see a list of all your " "bookmarks, select Bookmarks in the upper left corner of any courseware page.") self.assertEqual(self.bookmarks_page.empty_list_text(), empty_list_text) def test_bookmarks_list(self): """ Scenario: A bookmarks list is shown if there are bookmarked units. Given that I am a registered user And I visit my courseware page And I have bookmarked 2 units When I click on Bookmarks button Then I should see a bookmarked list with 2 bookmark links And breadcrumb trail is correct for a bookmark When I click on bookmarked link Then I can navigate to correct bookmarked unit """ self._test_setup() self._bookmark_units(2) self._navigate_to_bookmarks_list() self._verify_breadcrumbs(num_units=2) self._verify_pagination_info( bookmark_count_on_current_page=2, header_text='Showing 1-2 out of 2 total', previous_button_enabled=False, next_button_enabled=False, current_page_number=1, total_pages=1 ) # get usage ids for units xblocks = self.course_fixture.get_nested_xblocks(category="vertical") xblock_usage_ids = [xblock.locator for xblock in xblocks] # Verify link navigation for index in range(2): self.bookmarks_page.click_bookmarked_block(index) self.courseware_page.wait_for_page() self.assertIn(self.courseware_page.active_usage_id(), xblock_usage_ids) self.courseware_page.visit().wait_for_page() self.bookmarks_page.click_bookmarks_button() 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_unreachable_bookmark(self): """ Scenario: We should get a HTTP 404 for an unreachable bookmark. Given that I am a registered user And I visit my courseware page And I have bookmarked 2 units Then I delete a bookmarked unit Then I click on Bookmarks button And I should see a bookmarked list When I click on deleted bookmark Then I should navigated to 404 page """ self._test_setup(num_chapters=1) self._bookmark_units(1) self._delete_section(0) self._navigate_to_bookmarks_list() self._verify_pagination_info( bookmark_count_on_current_page=1, header_text='Showing 1 out of 1 total', previous_button_enabled=False, next_button_enabled=False, current_page_number=1, total_pages=1 ) self.bookmarks_page.click_bookmarked_block(0) self.assertTrue(is_404_page(self.browser)) def test_page_size_limit(self): """ Scenario: We can't get bookmarks more than default page size. Given that I am a registered user And I visit my courseware page And I have bookmarked all the 11 units available Then I click on Bookmarks button And I should see a bookmarked list And bookmark list contains 10 bookmarked items """ self._test_setup(11) self._bookmark_units(11) self._navigate_to_bookmarks_list() self._verify_pagination_info( bookmark_count_on_current_page=10, header_text='Showing 1-10 out of 11 total', previous_button_enabled=False, next_button_enabled=True, current_page_number=1, total_pages=2 ) def test_pagination_with_single_page(self): """ Scenario: Bookmarks list pagination is working as expected for single page Given that I am a registered user And I visit my courseware page And I have bookmarked all the 2 units available Then I click on Bookmarks button And I should see a bookmarked list with 2 bookmarked items And I should see paging header and footer with correct data And previous and next buttons are disabled """ self._test_setup(num_chapters=2) self._bookmark_units(num_units=2) self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self._verify_pagination_info( bookmark_count_on_current_page=2, header_text='Showing 1-2 out of 2 total', previous_button_enabled=False, next_button_enabled=False, current_page_number=1, total_pages=1 ) def test_next_page_button(self): """ Scenario: Next button is working as expected for bookmarks list pagination Given that I am a registered user And I visit my courseware page And I have bookmarked all the 12 units available Then I click on Bookmarks button And I should see a bookmarked list of 10 items And I should see paging header and footer with correct info Then I click on next page button in footer And I should be navigated to second page And I should see a bookmarked list with 2 items And I should see paging header and footer with correct info """ self._test_setup(num_chapters=12) self._bookmark_units(num_units=12) self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self._verify_pagination_info( bookmark_count_on_current_page=10, header_text='Showing 1-10 out of 12 total', previous_button_enabled=False, next_button_enabled=True, current_page_number=1, total_pages=2 ) self.bookmarks_page.press_next_page_button() self._verify_pagination_info( bookmark_count_on_current_page=2, header_text='Showing 11-12 out of 12 total', previous_button_enabled=True, next_button_enabled=False, current_page_number=2, total_pages=2 ) def test_previous_page_button(self): """ Scenario: Previous button is working as expected for bookmarks list pagination Given that I am a registered user And I visit my courseware page And I have bookmarked all the 12 units available And I click on Bookmarks button Then I click on next page button in footer And I should be navigated to second page And I should see a bookmarked list with 2 items And I should see paging header and footer with correct info Then I click on previous page button And I should be navigated to first page And I should see paging header and footer with correct info """ self._test_setup(num_chapters=12) self._bookmark_units(num_units=12) self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self.bookmarks_page.press_next_page_button() self._verify_pagination_info( bookmark_count_on_current_page=2, header_text='Showing 11-12 out of 12 total', previous_button_enabled=True, next_button_enabled=False, current_page_number=2, total_pages=2 ) self.bookmarks_page.press_previous_page_button() self._verify_pagination_info( bookmark_count_on_current_page=10, header_text='Showing 1-10 out of 12 total', previous_button_enabled=False, next_button_enabled=True, current_page_number=1, total_pages=2 ) def test_pagination_with_valid_page_number(self): """ Scenario: Bookmarks list pagination works as expected for valid page number Given that I am a registered user And I visit my courseware page And I have bookmarked all the 12 units available Then I click on Bookmarks button And I should see a bookmarked list And I should see total page value is 2 Then I enter 2 in the page number input And I should be navigated to page 2 """ self._test_setup(num_chapters=11) self._bookmark_units(num_units=11) self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self.assertEqual(self.bookmarks_page.get_total_pages, 2) self.bookmarks_page.go_to_page(2) self._verify_pagination_info( bookmark_count_on_current_page=1, header_text='Showing 11-11 out of 11 total', previous_button_enabled=True, next_button_enabled=False, current_page_number=2, total_pages=2 ) def test_pagination_with_invalid_page_number(self): """ Scenario: Bookmarks list pagination works as expected for invalid page number Given that I am a registered user And I visit my courseware page And I have bookmarked all the 11 units available Then I click on Bookmarks button And I should see a bookmarked list And I should see total page value is 2 Then I enter 3 in the page number input And I should stay at page 1 """ self._test_setup(num_chapters=11) self._bookmark_units(num_units=11) self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self.assertEqual(self.bookmarks_page.get_total_pages, 2) self.bookmarks_page.go_to_page(3) self._verify_pagination_info( bookmark_count_on_current_page=10, header_text='Showing 1-10 out of 11 total', previous_button_enabled=False, next_button_enabled=True, current_page_number=1, total_pages=2 ) def test_bookmarked_unit_accessed_event(self): """ Scenario: Bookmark events are emitted with correct data when we access/visit a bookmarked unit. Given that I am a registered user And I visit my courseware page And I have bookmarked a unit When I click on bookmarked unit Then `edx.course.bookmark.accessed` event is emitted """ self._test_setup(num_chapters=1) self.reset_event_tracking() # create expected event data xblocks = self.course_fixture.get_nested_xblocks(category="vertical") event_data = [ { 'event': { 'bookmark_id': '{},{}'.format(self.USERNAME, xblocks[0].locator), 'component_type': xblocks[0].category, 'component_usage_id': xblocks[0].locator, } } ] self._bookmark_units(num_units=1) self.bookmarks_page.click_bookmarks_button() self._verify_pagination_info( bookmark_count_on_current_page=1, header_text='Showing 1 out of 1 total', previous_button_enabled=False, next_button_enabled=False, current_page_number=1, total_pages=1 ) self.bookmarks_page.click_bookmarked_block(0) self.verify_event_data('edx.bookmark.accessed', event_data)
def setUp(self): super(CoursewareMultipleVerticalsTest, self).setUp() self.courseware_page = CoursewarePage(self.browser, self.course_id) self.course_outline = CourseOutlinePage(self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run']) # Install a course with sections/problems, tabs, updates, and handouts course_fix = CourseFixture(self.course_info['org'], self.course_info['number'], self.course_info['run'], self.course_info['display_name']) course_fix.add_children( XBlockFixtureDesc('chapter', 'Test Section 1').add_children( XBlockFixtureDesc( 'sequential', 'Test Subsection 1,1').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 1', data='<problem>problem 1 dummy body</problem>'), XBlockFixtureDesc( 'html', 'html 1', data="<html>html 1 dummy body</html>"), XBlockFixtureDesc( 'problem', 'Test Problem 2', data="<problem>problem 2 dummy body</problem>"), XBlockFixtureDesc( 'html', 'html 2', data="<html>html 2 dummy body</html>"), ), XBlockFixtureDesc( 'sequential', 'Test Subsection 1,2').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 3', data='<problem>problem 3 dummy body</problem>'), ), XBlockFixtureDesc( 'sequential', 'Test HIDDEN Subsection', metadata={ 'visible_to_staff_only': True }).add_children( XBlockFixtureDesc( 'problem', 'Test HIDDEN Problem', data='<problem>hidden problem</problem>'), ), ), XBlockFixtureDesc('chapter', 'Test Section 2').add_children( XBlockFixtureDesc( 'sequential', 'Test Subsection 2,1').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 4', data='<problem>problem 4 dummy body</problem>'), ), ), XBlockFixtureDesc( 'chapter', 'Test HIDDEN Section', metadata={ 'visible_to_staff_only': True }).add_children( XBlockFixtureDesc('sequential', 'Test HIDDEN Subsection'), ), ).install() # Auto-auth register for the course. AutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id, staff=False).visit() self.courseware_page.visit() self.course_nav = CourseNavPage(self.browser)
class CertificateProgressPageTest(UniqueCourseTest): """ Tests for verifying Certificate info on Progress tab of course page. """ def setUp(self): super(CertificateProgressPageTest, self).setUp() # set same course number as we have in fixture json self.course_info['number'] = "3355358979513794782079645765720179311111" test_certificate_config = { 'id': 1, 'name': 'Certificate name', 'description': 'Certificate description', 'course_title': 'Course title override', 'signatories': [], 'version': 1, 'is_active': True } course_settings = {'certificates': test_certificate_config} self.course_fixture = CourseFixture(self.course_info["org"], self.course_info["number"], self.course_info["run"], self.course_info["display_name"], settings=course_settings) self.course_fixture.add_advanced_settings( {"cert_html_view_enabled": { "value": "true" }}) self.course_fixture.add_update( CourseUpdateDesc(date='January 29, 2014', content='Test course update1')) self.course_fixture.add_children( XBlockFixtureDesc('static_tab', 'Test Static Tab'), XBlockFixtureDesc('chapter', 'Test Section').add_children( XBlockFixtureDesc( 'sequential', 'Test Subsection', grader_type='Final Exam').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 1', data=load_data_str('multiple_choice.xml')), XBlockFixtureDesc('html', 'Test HTML'), )), XBlockFixtureDesc('chapter', 'Test Section 2').add_children( XBlockFixtureDesc( 'sequential', 'Test Subsection 2', grader_type='Midterm Exam').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 2', data=load_data_str('formula_problem.xml')), ))) self.course_fixture.install() self.user_id = "99" # we have created a user with this id in fixture self.cert_fixture = CertificateConfigFixture(self.course_id, test_certificate_config) self.course_info_page = CourseInfoPage(self.browser, self.course_id) self.progress_page = ProgressPage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) self.tab_nav = TabNavPage(self.browser) def log_in_as_unique_user(self): """ Log in as a valid lms user. """ AutoAuthPage(self.browser, username="******", email="*****@*****.**", password="******", course_id=self.course_id).visit() def test_progress_page_has_view_certificate_button(self): """ Scenario: View Certificate option should be present on Course Progress menu if the user is awarded a certificate. And their should be no padding around the box containing certificate info. (See SOL-1196 for details on this) As a Student Given there is a course with certificate configuration And I have passed the course and certificate is generated When I go on the Progress tab for the course Then I should see a 'View Certificate' button And their should be no padding around Certificate info box. """ self.cert_fixture.install() self.log_in_as_unique_user() self.complete_course_problems() self.course_info_page.visit() self.tab_nav.go_to_tab('Progress') self.assertTrue( self.progress_page.q(css='.auto-cert-message').first.visible) actual_padding = get_element_padding(self.progress_page, '.wrapper-msg.wrapper-auto-cert') actual_padding = [ int(padding) for padding in actual_padding.itervalues() ] expected_padding = [0, 0, 0, 0] # Verify that their is no padding around the box containing certificate info. self.assertEqual(actual_padding, expected_padding) def complete_course_problems(self): """ Complete Course Problems. Problems were added in the setUp """ self.course_info_page.visit() self.tab_nav.go_to_tab('Course') # Navigate to Test Subsection in Test Section Section self.course_nav.go_to_section('Test Section', 'Test Subsection') # Navigate to Test Problem 1 self.course_nav.go_to_vertical('Test Problem 1') # Select correct value for from select menu self.course_nav.q( css='select option[value="{}"]'.format('blue')).first.click() # Select correct radio button for the answer self.course_nav.q( css='fieldset div.field:nth-child(3) input').nth(0).click() # Select correct radio buttons for the answer self.course_nav.q( css='fieldset div.field:nth-child(1) input').nth(1).click() self.course_nav.q( css='fieldset div.field:nth-child(3) input').nth(1).click() # Submit the answer self.course_nav.q(css='button.check.Check').click() self.course_nav.wait_for_ajax() # Navigate to the 'Test Subsection 2' of 'Test Section 2' self.course_nav.go_to_section('Test Section 2', 'Test Subsection 2') # Navigate to Test Problem 2 self.course_nav.go_to_vertical('Test Problem 2') # Fill in the answer of the problem self.course_nav.q( css='input[id^=input_][id$=_2_1]').fill('A*x^2 + sqrt(y)') # Submit the answer self.course_nav.q(css='button.check.Check').click() self.course_nav.wait_for_ajax()
class CoursewareMultipleVerticalsTest(UniqueCourseTest, EventsTestMixin): """ Test courseware with multiple verticals """ USERNAME = "******" EMAIL = "*****@*****.**" def setUp(self): super(CoursewareMultipleVerticalsTest, self).setUp() self.courseware_page = CoursewarePage(self.browser, self.course_id) self.course_outline = CourseOutlinePage(self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run']) # Install a course with sections/problems, tabs, updates, and handouts course_fix = CourseFixture(self.course_info['org'], self.course_info['number'], self.course_info['run'], self.course_info['display_name']) course_fix.add_children( XBlockFixtureDesc('chapter', 'Test Section 1').add_children( XBlockFixtureDesc( 'sequential', 'Test Subsection 1,1').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 1', data='<problem>problem 1 dummy body</problem>'), XBlockFixtureDesc( 'html', 'html 1', data="<html>html 1 dummy body</html>"), XBlockFixtureDesc( 'problem', 'Test Problem 2', data="<problem>problem 2 dummy body</problem>"), XBlockFixtureDesc( 'html', 'html 2', data="<html>html 2 dummy body</html>"), ), XBlockFixtureDesc( 'sequential', 'Test Subsection 1,2').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 3', data='<problem>problem 3 dummy body</problem>'), ), XBlockFixtureDesc( 'sequential', 'Test HIDDEN Subsection', metadata={ 'visible_to_staff_only': True }).add_children( XBlockFixtureDesc( 'problem', 'Test HIDDEN Problem', data='<problem>hidden problem</problem>'), ), ), XBlockFixtureDesc('chapter', 'Test Section 2').add_children( XBlockFixtureDesc( 'sequential', 'Test Subsection 2,1').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 4', data='<problem>problem 4 dummy body</problem>'), ), ), XBlockFixtureDesc( 'chapter', 'Test HIDDEN Section', metadata={ 'visible_to_staff_only': True }).add_children( XBlockFixtureDesc('sequential', 'Test HIDDEN Subsection'), ), ).install() # Auto-auth register for the course. AutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id, staff=False).visit() self.courseware_page.visit() self.course_nav = CourseNavPage(self.browser) def test_navigation_buttons(self): # start in first section self.assert_navigation_state('Test Section 1', 'Test Subsection 1,1', 0, next_enabled=True, prev_enabled=False) # next takes us to next tab in sequential self.courseware_page.click_next_button_on_top() self.assert_navigation_state('Test Section 1', 'Test Subsection 1,1', 1, next_enabled=True, prev_enabled=True) # go to last sequential position self.courseware_page.go_to_sequential_position(4) self.assert_navigation_state('Test Section 1', 'Test Subsection 1,1', 3, next_enabled=True, prev_enabled=True) # next takes us to next sequential self.courseware_page.click_next_button_on_bottom() self.assert_navigation_state('Test Section 1', 'Test Subsection 1,2', 0, next_enabled=True, prev_enabled=True) # next takes us to next chapter self.courseware_page.click_next_button_on_top() self.assert_navigation_state('Test Section 2', 'Test Subsection 2,1', 0, next_enabled=False, prev_enabled=True) # previous takes us to previous chapter self.courseware_page.click_previous_button_on_top() self.assert_navigation_state('Test Section 1', 'Test Subsection 1,2', 0, next_enabled=True, prev_enabled=True) # previous takes us to last tab in previous sequential self.courseware_page.click_previous_button_on_bottom() self.assert_navigation_state('Test Section 1', 'Test Subsection 1,1', 3, next_enabled=True, prev_enabled=True) # previous takes us to previous tab in sequential self.courseware_page.click_previous_button_on_bottom() self.assert_navigation_state('Test Section 1', 'Test Subsection 1,1', 2, next_enabled=True, prev_enabled=True) # test UI events emitted by navigation filter_sequence_ui_event = lambda event: event.get( 'name', '').startswith('edx.ui.lms.sequence.') sequence_ui_events = self.wait_for_events( event_filter=filter_sequence_ui_event, timeout=2) legacy_events = [ ev for ev in sequence_ui_events if ev['event_type'] in {'seq_next', 'seq_prev', 'seq_goto'} ] nonlegacy_events = [ ev for ev in sequence_ui_events if ev not in legacy_events ] self.assertTrue( all('old' in json.loads(ev['event']) for ev in legacy_events)) self.assertTrue( all('new' in json.loads(ev['event']) for ev in legacy_events)) self.assertFalse( any('old' in json.loads(ev['event']) for ev in nonlegacy_events)) self.assertFalse( any('new' in json.loads(ev['event']) for ev in nonlegacy_events)) self.assert_events_match([ { 'event_type': 'seq_next', 'event': { 'old': 1, 'new': 2, 'current_tab': 1, 'tab_count': 4, 'widget_placement': 'top', } }, { 'event_type': 'seq_goto', 'event': { 'old': 2, 'new': 4, 'current_tab': 2, 'target_tab': 4, 'tab_count': 4, 'widget_placement': 'top', } }, { 'event_type': 'edx.ui.lms.sequence.next_selected', 'event': { 'current_tab': 4, 'tab_count': 4, 'widget_placement': 'bottom', } }, { 'event_type': 'edx.ui.lms.sequence.next_selected', 'event': { 'current_tab': 1, 'tab_count': 1, 'widget_placement': 'top', } }, { 'event_type': 'edx.ui.lms.sequence.previous_selected', 'event': { 'current_tab': 1, 'tab_count': 1, 'widget_placement': 'top', } }, { 'event_type': 'edx.ui.lms.sequence.previous_selected', 'event': { 'current_tab': 1, 'tab_count': 1, 'widget_placement': 'bottom', } }, { 'event_type': 'seq_prev', 'event': { 'old': 4, 'new': 3, 'current_tab': 4, 'tab_count': 4, 'widget_placement': 'bottom', } }, ], sequence_ui_events) def test_outline_selected_events(self): self.course_nav.go_to_section('Test Section 1', 'Test Subsection 1,2') self.course_nav.go_to_section('Test Section 2', 'Test Subsection 2,1') # test UI events emitted by navigating via the course outline filter_selected_events = lambda event: event.get( 'name', '') == 'edx.ui.lms.outline.selected' selected_events = self.wait_for_events( event_filter=filter_selected_events, timeout=2) # note: target_url is tested in unit tests, as the url changes here with every test (it includes GUIDs). self.assert_events_match([ { 'event_type': 'edx.ui.lms.outline.selected', 'name': 'edx.ui.lms.outline.selected', 'event': { 'target_name': 'Test Subsection 1,2 ', 'widget_placement': 'accordion', } }, { 'event_type': 'edx.ui.lms.outline.selected', 'name': 'edx.ui.lms.outline.selected', 'event': { 'target_name': 'Test Subsection 2,1 ', 'widget_placement': 'accordion', } }, ], selected_events) def test_link_clicked_events(self): """ Given that I am a user in the courseware When I navigate via the left-hand nav Then a link clicked event is logged """ self.course_nav.go_to_section('Test Section 1', 'Test Subsection 1,2') self.course_nav.go_to_section('Test Section 2', 'Test Subsection 2,1') filter_link_clicked = lambda event: event.get( 'name', '') == 'edx.ui.lms.link_clicked' link_clicked_events = self.wait_for_events( event_filter=filter_link_clicked, timeout=2) self.assertEqual(len(link_clicked_events), 2) def assert_navigation_state(self, section_title, subsection_title, subsection_position, next_enabled, prev_enabled): """ Verifies that the navigation state is as expected. """ self.assertTrue( self.course_nav.is_on_section(section_title, subsection_title)) self.assertEquals(self.courseware_page.sequential_position, subsection_position) self.assertEquals(self.courseware_page.is_next_button_enabled, next_enabled) self.assertEquals(self.courseware_page.is_previous_button_enabled, prev_enabled) def test_tab_position(self): # test that using the position in the url direct to correct tab in courseware self.course_nav.go_to_section('Test Section 1', 'Test Subsection 1,1') subsection_url = self.course_nav.active_subsection_url url_part_list = subsection_url.split('/') self.assertEqual(len(url_part_list), 9) course_id = url_part_list[4] chapter_id = url_part_list[-3] subsection_id = url_part_list[-2] problem1_page = CoursewareSequentialTabPage(self.browser, course_id=course_id, chapter=chapter_id, subsection=subsection_id, position=1).visit() self.assertIn('problem 1 dummy body', problem1_page.get_selected_tab_content()) html1_page = CoursewareSequentialTabPage(self.browser, course_id=course_id, chapter=chapter_id, subsection=subsection_id, position=2).visit() self.assertIn('html 1 dummy body', html1_page.get_selected_tab_content()) problem2_page = CoursewareSequentialTabPage(self.browser, course_id=course_id, chapter=chapter_id, subsection=subsection_id, position=3).visit() self.assertIn('problem 2 dummy body', problem2_page.get_selected_tab_content()) html2_page = CoursewareSequentialTabPage(self.browser, course_id=course_id, chapter=chapter_id, subsection=subsection_id, position=4).visit() self.assertIn('html 2 dummy body', html2_page.get_selected_tab_content()) @attr('a11y') def test_courseware_a11y(self): """ Run accessibility audit for the problem type. """ self.course_nav.go_to_section('Test Section 1', 'Test Subsection 1,1') # Set the scope to the sequence navigation self.courseware_page.a11y_audit.config.set_scope( include=['div.sequence-nav']) self.courseware_page.a11y_audit.check_for_accessibility_errors()
class CertificateProgressPageTest(UniqueCourseTest): """ Tests for verifying Certificate info on Progress tab of course page. """ def setUp(self): super(CertificateProgressPageTest, self).setUp() # set same course number as we have in fixture json self.course_info["number"] = "3355358979513794782079645765720179311111" test_certificate_config = { "id": 1, "name": "Certificate name", "description": "Certificate description", "course_title": "Course title override", "signatories": [], "version": 1, "is_active": True, } course_settings = {"certificates": test_certificate_config} self.course_fixture = CourseFixture( self.course_info["org"], self.course_info["number"], self.course_info["run"], self.course_info["display_name"], settings=course_settings, ) self.course_fixture.add_advanced_settings({"cert_html_view_enabled": {"value": "true"}}) self.course_fixture.add_update(CourseUpdateDesc(date="January 29, 2014", content="Test course update1")) self.course_fixture.add_children( XBlockFixtureDesc("static_tab", "Test Static Tab"), XBlockFixtureDesc("chapter", "Test Section").add_children( XBlockFixtureDesc("sequential", "Test Subsection", grader_type="Final Exam").add_children( XBlockFixtureDesc("problem", "Test Problem 1", data=load_data_str("multiple_choice.xml")), XBlockFixtureDesc("html", "Test HTML"), ) ), XBlockFixtureDesc("chapter", "Test Section 2").add_children( XBlockFixtureDesc("sequential", "Test Subsection 2", grader_type="Midterm Exam").add_children( XBlockFixtureDesc("problem", "Test Problem 2", data=load_data_str("formula_problem.xml")) ) ), ) self.course_fixture.install() self.user_id = "99" # we have created a user with this id in fixture self.cert_fixture = CertificateConfigFixture(self.course_id, test_certificate_config) self.course_info_page = CourseInfoPage(self.browser, self.course_id) self.progress_page = ProgressPage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) self.tab_nav = TabNavPage(self.browser) def log_in_as_unique_user(self): """ Log in as a valid lms user. """ AutoAuthPage( self.browser, username="******", email="*****@*****.**", password="******", course_id=self.course_id, ).visit() def test_progress_page_has_view_certificate_button(self): """ Scenario: View Certificate option should be present on Course Progress menu if the user is awarded a certificate. And their should be no padding around the box containing certificate info. (See SOL-1196 for details on this) As a Student Given there is a course with certificate configuration And I have passed the course and certificate is generated When I go on the Progress tab for the course Then I should see a 'View Certificate' button And their should be no padding around Certificate info box. """ self.cert_fixture.install() self.log_in_as_unique_user() self.complete_course_problems() self.course_info_page.visit() self.tab_nav.go_to_tab("Progress") self.assertTrue(self.progress_page.q(css=".auto-cert-message").first.visible) actual_padding = get_element_padding(self.progress_page, ".wrapper-msg.wrapper-auto-cert") actual_padding = [int(padding) for padding in actual_padding.itervalues()] expected_padding = [0, 0, 0, 0] # Verify that their is no padding around the box containing certificate info. self.assertEqual(actual_padding, expected_padding) def complete_course_problems(self): """ Complete Course Problems. Problems were added in the setUp """ self.course_info_page.visit() self.tab_nav.go_to_tab("Course") # Navigate to Test Subsection in Test Section Section self.course_nav.go_to_section("Test Section", "Test Subsection") # Navigate to Test Problem 1 self.course_nav.go_to_vertical("Test Problem 1") # Select correct value for from select menu self.course_nav.q(css='select option[value="{}"]'.format("blue")).first.click() # Select correct radio button for the answer self.course_nav.q(css="fieldset div.field:nth-child(3) input").nth(0).click() # Select correct radio buttons for the answer self.course_nav.q(css="fieldset div.field:nth-child(1) input").nth(1).click() self.course_nav.q(css="fieldset div.field:nth-child(3) input").nth(1).click() # Submit the answer self.course_nav.q(css="button.check.Check").click() self.course_nav.wait_for_ajax() # Navigate to the 'Test Subsection 2' of 'Test Section 2' self.course_nav.go_to_section("Test Section 2", "Test Subsection 2") # Navigate to Test Problem 2 self.course_nav.go_to_vertical("Test Problem 2") # Fill in the answer of the problem self.course_nav.q(css="input[id^=input_][id$=_2_1]").fill("A*x^2 + sqrt(y)") # Submit the answer self.course_nav.q(css="button.check.Check").click() self.course_nav.wait_for_ajax()
class CoursewareTest(UniqueCourseTest): """ Test courseware. """ USERNAME = "******" EMAIL = "*****@*****.**" def setUp(self): super(CoursewareTest, self).setUp() self.courseware_page = CoursewarePage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) self.course_outline = CourseOutlinePage(self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run']) # Install a course with sections/problems, tabs, updates, and handouts self.course_fix = CourseFixture(self.course_info['org'], self.course_info['number'], self.course_info['run'], self.course_info['display_name']) self.course_fix.add_children( XBlockFixtureDesc('chapter', 'Test Section 1').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 1').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 1'))), XBlockFixtureDesc('chapter', 'Test Section 2').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 2').add_children( XBlockFixtureDesc( 'problem', 'Test Problem 2')))).install() # Auto-auth register for the course. self._auto_auth(self.USERNAME, self.EMAIL, False) def _goto_problem_page(self): """ Open problem page with assertion. """ self.courseware_page.visit() self.problem_page = ProblemPage(self.browser) # pylint: disable=attribute-defined-outside-init self.assertEqual(self.problem_page.problem_name, 'Test Problem 1') def _create_breadcrumb(self, index): """ Create breadcrumb """ return [ 'Test Section {}'.format(index), 'Test Subsection {}'.format(index), 'Test Problem {}'.format(index) ] def _auto_auth(self, username, email, staff): """ Logout and login with given credentials. """ AutoAuthPage(self.browser, username=username, email=email, course_id=self.course_id, staff=staff).visit() 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 test_course_tree_breadcrumb(self): """ Scenario: Correct course tree breadcrumb is shown. Given that I am a registered user And I visit my courseware page Then I should see correct course tree breadcrumb """ self.courseware_page.visit() xblocks = self.course_fix.get_nested_xblocks(category="problem") for index in range(1, len(xblocks) + 1): self.course_nav.go_to_section('Test Section {}'.format(index), 'Test Subsection {}'.format(index)) courseware_page_breadcrumb = self.courseware_page.breadcrumb expected_breadcrumb = self._create_breadcrumb(index) # pylint: disable=no-member self.assertEqual(courseware_page_breadcrumb, expected_breadcrumb)
class BookmarksTest(BookmarksTestMixin): """ Tests to verify bookmarks functionality. """ def setUp(self): """ Initialize test setup. """ super(BookmarksTest, self).setUp() self.course_outline_page = CourseOutlinePage( self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run']) self.courseware_page = CoursewarePage(self.browser, self.course_id) self.bookmarks_page = BookmarksPage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) # Get session to be used for bookmarking units self.session = requests.Session() params = { 'username': self.USERNAME, 'email': self.EMAIL, 'course_id': self.course_id } response = self.session.get(BASE_URL + "/auto_auth", params=params) self.assertTrue(response.ok, "Failed to get session") def _test_setup(self, num_chapters=2): """ Setup test settings. Arguments: num_chapters: number of chapters to create in course """ self.create_course_fixture(num_chapters) # Auto-auth register for the course. LmsAutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id).visit() self.courseware_page.visit() def _bookmark_unit(self, location): """ Bookmark a unit Arguments: location (str): unit location """ _headers = { 'Content-type': 'application/json', 'X-CSRFToken': self.session.cookies['csrftoken'], } params = {'course_id': self.course_id} data = json.dumps({'usage_id': location}) response = self.session.post(BASE_URL + '/api/bookmarks/v1/bookmarks/', data=data, params=params, headers=_headers) self.assertTrue(response.ok, "Failed to bookmark unit") def _bookmark_units(self, num_units): """ Bookmark first `num_units` units Arguments: num_units(int): Number of units to bookmarks """ xblocks = self.course_fixture.get_nested_xblocks(category="vertical") for index in range(num_units): self._bookmark_unit(xblocks[index].locator) def _breadcrumb(self, num_units, modified_name=None): """ Creates breadcrumbs for the first `num_units` Arguments: num_units(int): Number of units for which we want to create breadcrumbs Returns: list of breadcrumbs """ breadcrumbs = [] for index in range(num_units): breadcrumbs.append([ 'TestSection{}'.format(index), 'TestSubsection{}'.format(index), modified_name if modified_name else 'TestVertical{}'.format(index) ]) return breadcrumbs def _delete_section(self, index): """ Delete a section at index `index` """ # Logout and login as staff LogoutPage(self.browser).visit() StudioAutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL, course_id=self.course_id, staff=True).visit() # Visit course outline page in studio. self.course_outline_page.visit() self.course_outline_page.wait_for_page() self.course_outline_page.section_at(index).delete() # Logout and login as a student. LogoutPage(self.browser).visit() LmsAutoAuthPage(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 _toggle_bookmark_and_verify(self, bookmark_icon_state, bookmark_button_state, bookmarked_count): """ Bookmark/Un-Bookmark a unit and then verify """ self.assertTrue(self.courseware_page.bookmark_button_visible) self.courseware_page.click_bookmark_unit_button() self.assertEqual(self.courseware_page.bookmark_icon_visible, bookmark_icon_state) self.assertEqual(self.courseware_page.bookmark_button_state, bookmark_button_state) self.bookmarks_page.click_bookmarks_button() self.assertEqual(self.bookmarks_page.count(), bookmarked_count) def _verify_pagination_info(self, bookmark_count_on_current_page, header_text, previous_button_enabled, next_button_enabled, current_page_number, total_pages): """ Verify pagination info """ self.assertEqual(self.bookmarks_page.count(), bookmark_count_on_current_page) self.assertEqual(self.bookmarks_page.get_pagination_header_text(), header_text) self.assertEqual(self.bookmarks_page.is_previous_page_button_enabled(), previous_button_enabled) self.assertEqual(self.bookmarks_page.is_next_page_button_enabled(), next_button_enabled) self.assertEqual(self.bookmarks_page.get_current_page_number(), current_page_number) self.assertEqual(self.bookmarks_page.get_total_pages, total_pages) def _navigate_to_bookmarks_list(self): """ Navigates and verifies the bookmarks list page. """ self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self.assertEqual(self.bookmarks_page.results_header_text(), 'My Bookmarks') def _verify_breadcrumbs(self, num_units, modified_name=None): """ Verifies the breadcrumb trail. """ bookmarked_breadcrumbs = self.bookmarks_page.breadcrumbs() # Verify bookmarked breadcrumbs. breadcrumbs = self._breadcrumb(num_units=num_units, modified_name=modified_name) breadcrumbs.reverse() self.assertEqual(bookmarked_breadcrumbs, breadcrumbs) def update_and_publish_block_display_name(self, modified_name): """ Update and publish the block/unit display name. """ self.course_outline_page.visit() self.course_outline_page.wait_for_page() self.course_outline_page.expand_all_subsections() section = self.course_outline_page.section_at(0) container_page = section.subsection_at(0).unit_at(0).go_to() self.course_fixture._update_xblock( container_page.locator, { # pylint: disable=protected-access "metadata": { "display_name": modified_name } }) container_page.visit() container_page.wait_for_page() self.assertEqual(container_page.name, modified_name) container_page.publish_action.click() def test_bookmark_button(self): """ Scenario: Bookmark unit button toggles correctly Given that I am a registered user And I visit my courseware page For first 2 units I visit the unit And I can see the Bookmark button When I click on Bookmark button Then unit should be bookmarked Then I click again on the bookmark button And I should see a unit un-bookmarked """ self._test_setup() for index in range(2): self.course_nav.go_to_section('TestSection{}'.format(index), 'TestSubsection{}'.format(index)) self._toggle_bookmark_and_verify(True, 'bookmarked', 1) self.bookmarks_page.click_bookmarks_button(False) self._toggle_bookmark_and_verify(False, '', 0) def test_empty_bookmarks_list(self): """ Scenario: An empty bookmarks list is shown if there are no bookmarked units. Given that I am a registered user And I visit my courseware page And I can see the Bookmarks button When I click on Bookmarks button Then I should see an empty bookmarks list And empty bookmarks list content is correct """ self._test_setup() self.assertTrue(self.bookmarks_page.bookmarks_button_visible()) self.bookmarks_page.click_bookmarks_button() self.assertEqual(self.bookmarks_page.results_header_text(), 'My Bookmarks') self.assertEqual(self.bookmarks_page.empty_header_text(), 'You have not bookmarked any courseware pages yet.') empty_list_text = ( "Use bookmarks to help you easily return to courseware pages. To bookmark a page, " "select Bookmark in the upper right corner of that page. To see a list of all your " "bookmarks, select Bookmarks in the upper left corner of any courseware page." ) self.assertEqual(self.bookmarks_page.empty_list_text(), empty_list_text) def test_bookmarks_list(self): """ Scenario: A bookmarks list is shown if there are bookmarked units. Given that I am a registered user And I visit my courseware page And I have bookmarked 2 units When I click on Bookmarks button Then I should see a bookmarked list with 2 bookmark links And breadcrumb trail is correct for a bookmark When I click on bookmarked link Then I can navigate to correct bookmarked unit """ self._test_setup() self._bookmark_units(2) self._navigate_to_bookmarks_list() self._verify_breadcrumbs(num_units=2) self._verify_pagination_info(bookmark_count_on_current_page=2, header_text='Showing 1-2 out of 2 total', previous_button_enabled=False, next_button_enabled=False, current_page_number=1, total_pages=1) # get usage ids for units xblocks = self.course_fixture.get_nested_xblocks(category="vertical") xblock_usage_ids = [xblock.locator for xblock in xblocks] # Verify link navigation for index in range(2): self.bookmarks_page.click_bookmarked_block(index) self.courseware_page.wait_for_page() self.assertIn(self.courseware_page.active_usage_id(), xblock_usage_ids) self.courseware_page.visit().wait_for_page() self.bookmarks_page.click_bookmarks_button() 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_unreachable_bookmark(self): """ Scenario: We should get a HTTP 404 for an unreachable bookmark. Given that I am a registered user And I visit my courseware page And I have bookmarked 2 units Then I delete a bookmarked unit Then I click on Bookmarks button And I should see a bookmarked list When I click on deleted bookmark Then I should navigated to 404 page """ self._test_setup(num_chapters=1) self._bookmark_units(1) self._delete_section(0) self._navigate_to_bookmarks_list() self._verify_pagination_info(bookmark_count_on_current_page=1, header_text='Showing 1 out of 1 total', previous_button_enabled=False, next_button_enabled=False, current_page_number=1, total_pages=1) self.bookmarks_page.click_bookmarked_block(0) self.assertTrue(is_404_page(self.browser)) def test_page_size_limit(self): """ Scenario: We can't get bookmarks more than default page size. Given that I am a registered user And I visit my courseware page And I have bookmarked all the 11 units available Then I click on Bookmarks button And I should see a bookmarked list And bookmark list contains 10 bookmarked items """ self._test_setup(11) self._bookmark_units(11) self._navigate_to_bookmarks_list() self._verify_pagination_info( bookmark_count_on_current_page=10, header_text='Showing 1-10 out of 11 total', previous_button_enabled=False, next_button_enabled=True, current_page_number=1, total_pages=2) def test_pagination_with_single_page(self): """ Scenario: Bookmarks list pagination is working as expected for single page Given that I am a registered user And I visit my courseware page And I have bookmarked all the 2 units available Then I click on Bookmarks button And I should see a bookmarked list with 2 bookmarked items And I should see paging header and footer with correct data And previous and next buttons are disabled """ self._test_setup(num_chapters=2) self._bookmark_units(num_units=2) self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self._verify_pagination_info(bookmark_count_on_current_page=2, header_text='Showing 1-2 out of 2 total', previous_button_enabled=False, next_button_enabled=False, current_page_number=1, total_pages=1) def test_next_page_button(self): """ Scenario: Next button is working as expected for bookmarks list pagination Given that I am a registered user And I visit my courseware page And I have bookmarked all the 12 units available Then I click on Bookmarks button And I should see a bookmarked list of 10 items And I should see paging header and footer with correct info Then I click on next page button in footer And I should be navigated to second page And I should see a bookmarked list with 2 items And I should see paging header and footer with correct info """ self._test_setup(num_chapters=12) self._bookmark_units(num_units=12) self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self._verify_pagination_info( bookmark_count_on_current_page=10, header_text='Showing 1-10 out of 12 total', previous_button_enabled=False, next_button_enabled=True, current_page_number=1, total_pages=2) self.bookmarks_page.press_next_page_button() self._verify_pagination_info( bookmark_count_on_current_page=2, header_text='Showing 11-12 out of 12 total', previous_button_enabled=True, next_button_enabled=False, current_page_number=2, total_pages=2) def test_previous_page_button(self): """ Scenario: Previous button is working as expected for bookmarks list pagination Given that I am a registered user And I visit my courseware page And I have bookmarked all the 12 units available And I click on Bookmarks button Then I click on next page button in footer And I should be navigated to second page And I should see a bookmarked list with 2 items And I should see paging header and footer with correct info Then I click on previous page button And I should be navigated to first page And I should see paging header and footer with correct info """ self._test_setup(num_chapters=12) self._bookmark_units(num_units=12) self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self.bookmarks_page.press_next_page_button() self._verify_pagination_info( bookmark_count_on_current_page=2, header_text='Showing 11-12 out of 12 total', previous_button_enabled=True, next_button_enabled=False, current_page_number=2, total_pages=2) self.bookmarks_page.press_previous_page_button() self._verify_pagination_info( bookmark_count_on_current_page=10, header_text='Showing 1-10 out of 12 total', previous_button_enabled=False, next_button_enabled=True, current_page_number=1, total_pages=2) def test_pagination_with_valid_page_number(self): """ Scenario: Bookmarks list pagination works as expected for valid page number Given that I am a registered user And I visit my courseware page And I have bookmarked all the 12 units available Then I click on Bookmarks button And I should see a bookmarked list And I should see total page value is 2 Then I enter 2 in the page number input And I should be navigated to page 2 """ self._test_setup(num_chapters=11) self._bookmark_units(num_units=11) self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self.assertEqual(self.bookmarks_page.get_total_pages, 2) self.bookmarks_page.go_to_page(2) self._verify_pagination_info( bookmark_count_on_current_page=1, header_text='Showing 11-11 out of 11 total', previous_button_enabled=True, next_button_enabled=False, current_page_number=2, total_pages=2) def test_pagination_with_invalid_page_number(self): """ Scenario: Bookmarks list pagination works as expected for invalid page number Given that I am a registered user And I visit my courseware page And I have bookmarked all the 11 units available Then I click on Bookmarks button And I should see a bookmarked list And I should see total page value is 2 Then I enter 3 in the page number input And I should stay at page 1 """ self._test_setup(num_chapters=11) self._bookmark_units(num_units=11) self.bookmarks_page.click_bookmarks_button() self.assertTrue(self.bookmarks_page.results_present()) self.assertEqual(self.bookmarks_page.get_total_pages, 2) self.bookmarks_page.go_to_page(3) self._verify_pagination_info( bookmark_count_on_current_page=10, header_text='Showing 1-10 out of 11 total', previous_button_enabled=False, next_button_enabled=True, current_page_number=1, total_pages=2) def test_bookmarked_unit_accessed_event(self): """ Scenario: Bookmark events are emitted with correct data when we access/visit a bookmarked unit. Given that I am a registered user And I visit my courseware page And I have bookmarked a unit When I click on bookmarked unit Then `edx.course.bookmark.accessed` event is emitted """ self._test_setup(num_chapters=1) self.reset_event_tracking() # create expected event data xblocks = self.course_fixture.get_nested_xblocks(category="vertical") event_data = [{ 'event': { 'bookmark_id': '{},{}'.format(self.USERNAME, xblocks[0].locator), 'component_type': xblocks[0].category, 'component_usage_id': xblocks[0].locator, } }] self._bookmark_units(num_units=1) self.bookmarks_page.click_bookmarks_button() self._verify_pagination_info(bookmark_count_on_current_page=1, header_text='Showing 1 out of 1 total', previous_button_enabled=False, next_button_enabled=False, current_page_number=1, total_pages=1) self.bookmarks_page.click_bookmarked_block(0) self.verify_event_data('edx.bookmark.accessed', event_data)
class CoursewareTest(UniqueCourseTest): """ Test courseware. """ USERNAME = "******" EMAIL = "*****@*****.**" def setUp(self): super(CoursewareTest, self).setUp() self.courseware_page = CoursewarePage(self.browser, self.course_id) self.course_nav = CourseNavPage(self.browser) self.course_outline = CourseOutlinePage( self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run'] ) # Install a course with sections/problems, tabs, updates, and handouts self.course_fix = CourseFixture( self.course_info['org'], self.course_info['number'], self.course_info['run'], self.course_info['display_name'] ) self.course_fix.add_children( XBlockFixtureDesc('chapter', 'Test Section 1').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 1').add_children( XBlockFixtureDesc('problem', 'Test Problem 1') ) ), XBlockFixtureDesc('chapter', 'Test Section 2').add_children( XBlockFixtureDesc('sequential', 'Test Subsection 2').add_children( XBlockFixtureDesc('problem', 'Test Problem 2') ) ) ).install() # Auto-auth register for the course. self._auto_auth(self.USERNAME, self.EMAIL, False) def _goto_problem_page(self): """ Open problem page with assertion. """ self.courseware_page.visit() self.problem_page = ProblemPage(self.browser) # pylint: disable=attribute-defined-outside-init self.assertEqual(self.problem_page.problem_name, 'Test Problem 1') def _create_breadcrumb(self, index): """ Create breadcrumb """ return ['Test Section {}'.format(index), 'Test Subsection {}'.format(index), 'Test Problem {}'.format(index)] def _auto_auth(self, username, email, staff): """ Logout and login with given credentials. """ AutoAuthPage(self.browser, username=username, email=email, course_id=self.course_id, staff=staff).visit() 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 test_course_tree_breadcrumb(self): """ Scenario: Correct course tree breadcrumb is shown. Given that I am a registered user And I visit my courseware page Then I should see correct course tree breadcrumb """ self.courseware_page.visit() xblocks = self.course_fix.get_nested_xblocks(category="problem") for index in range(1, len(xblocks) + 1): self.course_nav.go_to_section('Test Section {}'.format(index), 'Test Subsection {}'.format(index)) courseware_page_breadcrumb = self.courseware_page.breadcrumb expected_breadcrumb = self._create_breadcrumb(index) # pylint: disable=no-member self.assertEqual(courseware_page_breadcrumb, expected_breadcrumb)