From 371c1df4f38e16db7495eb04bb4bb0a07bf8bf83 Mon Sep 17 00:00:00 2001 From: Agha Awais Date: Wed, 26 Sep 2018 08:54:35 +0000 Subject: [PATCH] Course registration bokchoy test --- .../test/acceptance/pages/lms/course_about.py | 7 +++ common/test/acceptance/pages/lms/dashboard.py | 18 ++++++ common/test/acceptance/pages/lms/discovery.py | 9 +++ common/test/acceptance/tests/lms/test_lms.py | 62 +++++++++++++++++++ .../courseware/features/registration.feature | 13 ---- 5 files changed, 96 insertions(+), 13 deletions(-) delete mode 100644 lms/djangoapps/courseware/features/registration.feature diff --git a/common/test/acceptance/pages/lms/course_about.py b/common/test/acceptance/pages/lms/course_about.py index a5482c7b77..61a6df1a4f 100644 --- a/common/test/acceptance/pages/lms/course_about.py +++ b/common/test/acceptance/pages/lms/course_about.py @@ -27,3 +27,10 @@ class CourseAboutPage(CoursePage): registration_page = RegisterPage(self.browser, self.course_id) registration_page.wait_for_page() return registration_page + + def enroll_in_course(self): + """ + Click on enroll button + """ + self.wait_for_element_visibility('.register', 'Enroll button is present') + self.q(css='.register').first.click() diff --git a/common/test/acceptance/pages/lms/dashboard.py b/common/test/acceptance/pages/lms/dashboard.py index 13bd7ec2fa..ac5edb6072 100644 --- a/common/test/acceptance/pages/lms/dashboard.py +++ b/common/test/acceptance/pages/lms/dashboard.py @@ -3,6 +3,7 @@ Student dashboard page. """ from bok_choy.page_object import PageObject +from opaque_keys.edx.keys import CourseKey from common.test.acceptance.pages.lms import BASE_URL @@ -246,3 +247,20 @@ class DashboardPage(PageObject): 'Language selector element is available' ) return self.q(css='#settings-language-value') + + def is_course_present(self, course_id): + """ + Checks whether course is present or not. + + Arguments: + course_id(str): The unique course id. + + Returns: + bool: True if the course is present. + """ + course_number = CourseKey.from_string(course_id).course + return self.q( + css='#actions-dropdown-link-0[data-course-number="{}"]'.format( + course_number + ) + ).present diff --git a/common/test/acceptance/pages/lms/discovery.py b/common/test/acceptance/pages/lms/discovery.py index 010fd2e03f..016b5f9c47 100644 --- a/common/test/acceptance/pages/lms/discovery.py +++ b/common/test/acceptance/pages/lms/discovery.py @@ -54,3 +54,12 @@ class CourseDiscoveryPage(PageObject): """ self.clear_button.click() self.wait_for_ajax() + + def click_course(self, course_id): + """ + Click on the course + + Args: + course_id(string): ID of the course which is to be clicked + """ + self.q(css='.courses-listing-item a').filter(lambda el: course_id in el.get_attribute('href')).click() diff --git a/common/test/acceptance/tests/lms/test_lms.py b/common/test/acceptance/tests/lms/test_lms.py index d2423293ff..727e5148c6 100644 --- a/common/test/acceptance/tests/lms/test_lms.py +++ b/common/test/acceptance/tests/lms/test_lms.py @@ -2,6 +2,8 @@ """ End-to-end tests for the LMS. """ +import json + from datetime import datetime, timedelta from textwrap import dedent @@ -29,6 +31,8 @@ from common.test.acceptance.pages.lms.problem import ProblemPage from common.test.acceptance.pages.lms.progress import ProgressPage from common.test.acceptance.pages.lms.tab_nav import TabNavPage from common.test.acceptance.pages.lms.video.video import VideoPage +from common.test.acceptance.pages.lms.discovery import CourseDiscoveryPage +from common.test.acceptance.pages.lms.course_about import CourseAboutPage from common.test.acceptance.pages.studio.settings import SettingsPage from common.test.acceptance.tests.helpers import ( EventsTestMixin, @@ -37,6 +41,7 @@ from common.test.acceptance.tests.helpers import ( get_selected_option_text, load_data_str, select_option_by_text, + remove_file ) from openedx.core.lib.tests import attr @@ -1140,3 +1145,60 @@ class LMSLanguageTest(UniqueCourseTest): get_selected_option_text(language_selector), u'English' ) + + +@attr(shard=19) +class RegisterCourseTests(EventsTestMixin, UniqueCourseTest): + """Test that learner can enroll into a course from courses page""" + + TEST_INDEX_FILENAME = "test_root/index_file.dat" + + def setUp(self): + """ + Initialize the test. + + Create the necessary page objects, create course page and courses to find. + """ + super(RegisterCourseTests, self).setUp() + + # 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) + + self.course_discovery = CourseDiscoveryPage(self.browser) + self.dashboard_page = DashboardPage(self.browser) + self.course_about = CourseAboutPage(self.browser, self.course_id) + + # Create a course + CourseFixture( + self.course_info['org'], + self.course_info['number'], + self.course_info['run'], + self.course_info['display_name'], + settings={'enrollment_start': datetime(1970, 1, 1).isoformat()} + ).install() + + # Create a user and log them in + AutoAuthPage(self.browser).visit() + + def test_register_for_course(self): + """ + Scenario: I can register for a course + Given The course "6.002x" exists + And I am logged in + And I visit the courses page + When I register for the course "6.002x" + Then I should see the course numbered "6.002x" in my dashboard + And a "edx.course.enrollment.activated" server event is emitted + """ + # Navigate to the dashboard + self.course_discovery.visit() + self.course_discovery.click_course(self.course_id) + self.course_about.wait_for_page() + self.course_about.enroll_in_course() + self.dashboard_page.wait_for_page() + self.assertTrue(self.dashboard_page.is_course_present(self.course_id)) + self.assert_matching_events_were_emitted( + event_filter={'name': u'edx.course.enrollment.activated', 'event_source': 'server'} + ) diff --git a/lms/djangoapps/courseware/features/registration.feature b/lms/djangoapps/courseware/features/registration.feature deleted file mode 100644 index 60b094de48..0000000000 --- a/lms/djangoapps/courseware/features/registration.feature +++ /dev/null @@ -1,13 +0,0 @@ -@shard_1 -Feature: LMS.Register for a course - As a registered user - In order to access my class content - I want to register for a class on the edX website - - Scenario: I can register for a course - Given The course "6.002x" exists - And I am logged in - And I visit the courses page - When I register for the course "6.002x" - Then I should see the course numbered "6.002x" in my dashboard - And a "edx.course.enrollment.activated" server event is emitted