def setUp(self): """ Initialize all page objects """ super(EnterpriseTestBase, self).setUp() self.browser.maximize_window() self.ent_portal_login = EnterprisePortalLogin(self.browser) self.ent_portal_home = EnterprisePortalHome(self.browser) self.ent_portal_course_start = \ EnterprisePortalCourseStart(self.browser) self.ent_portal_course_structure = \ EnterprisePortalCourseStructure(self.browser) self.ent_course_enrollment = \ EnterpriseCourseEnrollment(self.browser) self.ent_data_sharing_consent = \ EnterpriseDataSharingConsentPage(self.browser) self.ecommerce_courses_page = \ EcommerceCoursesPage(self.browser) self.lms_login = LmsLogin(self.browser) self.ent_edx_registration = EnterpriseEdxRegistration(self.browser) self.ent_edx_login = EnterpriseEdxLogin(self.browser) self.dashboard = DashboardPageExtended(self.browser) self.courses_page = CoursesPage(self.browser) self.course_about_page = CourseAboutPageExtended(self.browser) self.track_selection_page = TrackSelectionPage(self.browser) self.user_account = UserAccountSettings(self.browser) self.cyber_source_page = CyberSourcePage(self.browser) self.single_seat_basket = SingleSeatBasketPage(self.browser) self.receipt_page = ReceiptPage(self.browser) self.lms_api_client = LmsApiClient() self.login_api = LmsLoginApi() self.logout_api = LogoutApi()
def setUp(self): super(VouchersTest, self).setUp() self.ecommerce_api = EcommerceApiClient() # Initialize all objects self.home = HomePage(self.browser) self.redeem_coupon_error_page = RedeemCouponErrorPage(self.browser) self.single_seat_basket = SingleSeatBasketPage(self.browser) self.coupon = None
def setUp(self): super(CourseEnrollmentTest, self).setUp() self.lms_api_client = LmsApiClient() self.enrollment_api_client = EnrollmentApiClient() # Initialize all page objects self.cyber_source_page = CyberSourcePage(self.browser) self.courses_page = CoursesPage(self.browser) self.multi_seat_basket_page = MultiSeatBasketPage(self.browser) self.single_seat_basket_page = SingleSeatBasketPage(self.browser) self.receipt_page = ReceiptPage(self.browser) # Initialize all common variables self.course_id = '' self.course_title = '' self.course_price = 0.0 self.total_price = 0.0 self.full_cleanup = True
def test_enterprise_percentage_offer(self): """ Scenario: To verify that user sees the correct discount percentage info and detail on enterprise landing page, basket page and on receipt page. """ # Login user to LMS using staff credentials self.login_user_lms_using_api() # Get all enterprise offers data using api request offers_response = self.login_api.get_offer_request(self.target_url) # Get discount value from response against catalog UUID discount_value = extract_discount_value_from_response( ENT_CUSTOMER_CATALOG_UUID, offers_response ) discounted_course_price = self.course_price - \ (self.course_price * discount_value) / 100 self.logout_from_lms_using_api() self.ecommerce_courses_page.visit() self.register_and_go_to_course_enrollment_page() # Call the fixture to unlink existing account for the user self.addCleanup(self.unlink_account) # Get course original price and course discounted price price_details = \ self.ent_course_enrollment.get_course_price_details().split() # extract_numerical_value_from_price_string(price_details) self.assertEqual( self.course_price, extract_numerical_value_from_price_string(price_details[1]) ) self.assertEqual( discounted_course_price, extract_numerical_value_from_price_string(price_details[3]) ) self.assertIn( self.DISCOUNT_MSG + ENTERPRISE_NAME, self.ent_course_enrollment.get_course_price_details() ) self.ent_course_enrollment.go_to_data_consent_page() self.ent_data_sharing_consent.wait_for_page() # Verify that accepting data consent takes user to basket page self.ent_data_sharing_consent.accept_data_sharing_consent() SingleSeatBasketPage(self.browser).wait_for_page() self.verify_info_is_populated_on_basket( discounted_course_price ) self.verify_receipt_info_for_discounted_course()
def test_data_sharing_consent_acceptance(self): """ Scenario: To verify that user is taken to basket page on accepting data consent Given that a user is on data consent page When this user checks the data consent check box And Clicks on the Continue button Then this user is taken to basket page """ self.register_and_go_to_course_enrollment_page() self.assertDictEqual(self.ENT_COURSE_TITLE, self.ent_course_enrollment.get_course_title()) self.ent_course_enrollment.go_to_data_consent_page() self.ent_data_sharing_consent.wait_for_page() # Verify that accepting data consent takes user to basket page self.ent_data_sharing_consent.accept_data_sharing_consent() SingleSeatBasketPage(self.browser).wait_for_page()
class EnterpriseTestBase(WebAppTest): """ Test Enterprise Login """ def setUp(self): """ Initialize all page objects """ super(EnterpriseTestBase, self).setUp() self.browser.maximize_window() self.ent_portal_login = EnterprisePortalLogin(self.browser) self.ent_portal_home = EnterprisePortalHome(self.browser) self.ent_portal_course_start = \ EnterprisePortalCourseStart(self.browser) self.ent_portal_course_structure = \ EnterprisePortalCourseStructure(self.browser) self.ent_course_enrollment = \ EnterpriseCourseEnrollment(self.browser) self.ent_data_sharing_consent = \ EnterpriseDataSharingConsentPage(self.browser) self.ecommerce_courses_page = \ EcommerceCoursesPage(self.browser) self.lms_login = LmsLogin(self.browser) self.ent_edx_registration = EnterpriseEdxRegistration(self.browser) self.ent_edx_login = EnterpriseEdxLogin(self.browser) self.dashboard = DashboardPageExtended(self.browser) self.courses_page = CoursesPage(self.browser) self.course_about_page = CourseAboutPageExtended(self.browser) self.track_selection_page = TrackSelectionPage(self.browser) self.user_account = UserAccountSettings(self.browser) self.cyber_source_page = CyberSourcePage(self.browser) self.single_seat_basket = SingleSeatBasketPage(self.browser) self.receipt_page = ReceiptPage(self.browser) self.lms_api_client = LmsApiClient() self.login_api = LmsLoginApi() self.logout_api = LogoutApi() def unlink_account(self): """ Unlink IDP Account This serves as a fixture for unlinked user test case, it unlinks the user after running the tests to make sure that the precondition of test is true """ # Visit account setting page self.user_account.visit() self.user_account.switch_account_settings_tabs('accounts-tab') # If linked account is found, unlink it if self.user_account.is_idp_account_linked(IDP_CSS_ID): self.user_account.unlink_idp_account(IDP_CSS_ID) # Logout using api self.logout_from_lms_using_api() def login_to_ent_portal(self, ent_portal_username, ent_portal_password): """ Login to enterprise portal and find the course and click on it """ # Open portal self.ent_portal_login.visit() # Login self.ent_portal_login.login_to_portal(ent_portal_username, ent_portal_password) self.ent_portal_home.wait_for_page() def access_course(self): """ Access the course from portal """ # Open the course pop up and look for the desired course self.ent_portal_home.open_courses_popup() course_titles = self.ent_portal_home.fetch_course_titles_list() self.assert_(ENT_COURSE_TITLE in course_title for course_title in course_titles) # Go to course page and then use the link there to go to edX self.ent_portal_home.open_enterprise_course_page(ENT_COURSE_TITLE) self.ent_portal_course_start.wait_for_page() self.ent_portal_course_start.start_or_continue_course() self.ent_portal_course_structure.wait_for_page() self.ent_portal_course_structure.open_course_on_edx() # Get handle of newly opened edx window and switch control to it edx_window = self.driver.window_handles[1] self.driver.switch_to_window(edx_window) def login_ent_edx_user(self): """ Login the user using edX customized logistration page """ # edx credentials self.ent_edx_login.wait_for_page() self.assertEqual(ENTERPRISE_NAME, self.ent_edx_login.get_enterprise_name()) self.ent_edx_login.login(LOGIN_EMAIL, LOGIN_PASSWORD) def register_ent_edx_user(self): """ Register the enterprise user using edX customized logistration page """ __, email = get_random_credentials() self.ent_edx_registration.visit() self.assertEqual(ENTERPRISE_NAME, self.ent_edx_registration.get_enterprise_name()) self.ent_edx_registration.register(email=email, full_name='Enterprise Test User', country="US") def logout_from_lms_using_api(self): """ Get cookies from browser and send these cookie to python request to logout using api """ self.logout_api.logout_url = '{}://{}/{}'.format( LMS_PROTOCOL, LMS_BASE_URL, 'logout') self.logout_api.cookies = self.browser.get_cookies() self.logout_api.logout() def login_user_lms_using_api(self): """ Login user to LMS using login API """ self.login_api.authenticate(self.browser) def login_and_go_to_course_enrollment_page(self): """ Flow which covers the user login on enterprise portal, selecting the course and then login to edx course enrollment page """ # The edX site is visited just to make sure that when user jumps to # edX from portal we don't have to handle authentication popup self.lms_login.visit() # Enterprise portal flow self.login_to_ent_portal(ENT_PORTAL_USERNAME, ENT_PORTAL_PASSWORD) self.access_course() self.login_ent_edx_user() # Verify that user is on course enrollment page self.ent_course_enrollment.wait_for_page() def register_and_go_to_course_enrollment_page(self): """ Flow which covers the user login on enterprise portal, selecting the course and then register to edx course enrollment page """ # The edX site is visited just to make sure that when user jumps to # edX from portal we don't have to handle authentication popup self.lms_login.visit() # Enterprise portal flow self.login_to_ent_portal(ENT_PORTAL_USERNAME, ENT_PORTAL_PASSWORD) self.access_course() self.ent_edx_login.wait_for_page() self.register_ent_edx_user() # Verify that user is on course enrollment page self.ent_course_enrollment.wait_for_page() def payment_using_cyber_source(self): """ Make payment for course by providing Billing Info and Payment details in respected areas. """ self.cyber_source_page.set_card_holder_info(CARD_HOLDER_INFO) self.cyber_source_page.set_billing_info(BILLING_INFO) self.cyber_source_page.click_payment_button() self.receipt_page.wait_for_page() def register_edx_user(self): """ Register the user using edX registration page """ username, email = get_random_credentials() self.ent_edx_registration.visit() self.ent_edx_registration.register(email=email, full_name='Test User', username=username, password='******', country="US") self.dashboard.wait_for_page() def verify_info_is_populated_on_basket(self, discounted_price): """ After User accept data sharing consent from landing pag verify that following information is displayed correctly on basket page: i) Enterprise offer is applied ii) Discounted amount Arguments: discounted_price(float): Discounted price of the course. """ self.assertTrue(self.single_seat_basket.is_offer_applied()) self.assertEqual(self.single_seat_basket.total_price_after_discount, discounted_price) self.payment_using_cyber_source() def verify_receipt_info_for_discounted_course(self): """ Verify that info on receipt page is correct. Verify i) Course title. ii) Order date """ self.assertIn(ENT_COURSE_TITLE, self.receipt_page.order_desc) self.assertEqual(datetime.utcnow().strftime("%Y-%m-%d"), self.receipt_page.order_date)
class CourseEnrollmentTest(WhiteLabelTestsBaseClass): """ Class for tests with enrollment capability """ def setUp(self): super(CourseEnrollmentTest, self).setUp() self.lms_api_client = LmsApiClient() self.enrollment_api_client = EnrollmentApiClient() # Initialize all page objects self.cyber_source_page = CyberSourcePage(self.browser) self.courses_page = CoursesPage(self.browser) self.multi_seat_basket_page = MultiSeatBasketPage(self.browser) self.single_seat_basket_page = SingleSeatBasketPage(self.browser) self.receipt_page = ReceiptPage(self.browser) # Initialize all common variables self.course_id = '' self.course_title = '' self.course_price = 0.0 self.total_price = 0.0 self.full_cleanup = True def go_to_basket(self, bulk_purchase=False): """ Perform all the steps from dashboard to reaching the basket page. If bulk_purchase is set to 'True' then go to multi seat basket, otherwise go to single seat basket. Arguments: bulk_purchase(bool): Indicates type of the purchase. """ course_about_page = CourseAboutPage(self.browser, self.course_id) # Check that course is not already present on dashboard and use find # course link to go to courses page self.assertFalse(self.dashboard_page.is_course_present(self.course_id)) self.dashboard_page.click_courses_button() self.courses_page.wait_for_page() # find the target course and click on it to go to about page self.courses_page.click_on_the_course(self.course_id) course_about_page.wait_for_page() # Verify that course price is correct on course about page self.assertEqual(self.course_price, course_about_page.course_price) if bulk_purchase: # go to multi seat basket page course_about_page.click_on_multi_seat_basket() self.multi_seat_basket_page.wait_for_page() else: # go to single seat basket page course_about_page.click_on_single_seat_basket() self.single_seat_basket_page.wait_for_page() # Verify course name, course price and total price on basket page # self.verify_course_name_on_basket() self.verify_price_on_basket() def verify_course_name_on_basket(self): """ Verify that course name is displayed correctly on basket page. """ self.assertIn(self.course_title, self.basket_page.course_name) def verify_price_on_basket(self): """ Verify that course price and total price are displayed correctly on basket page. """ self.assertEqual( [self.basket_page.course_price, self.basket_page.total_price], [self.course_price, self.total_price]) def assert_enrollment_and_logout_of_ecommerce(self): """ Verify that course is added to user dashboard and user can access the course. After that, logout from application. """ self.assert_course_added_to_dashboard() self.logout_user_from_ecommerce() def assert_course_added_to_dashboard(self): """ Waits for course to appear on dashboard. """ def check_course(): """ Checks if course is present on dashboard and revisits the page if it is not there. Returns: True: If course present False: Otherwise """ if self.dashboard_page.is_course_present(self.course_id): return True self.dashboard_page.visit() return False EmptyPromise(check_course, 'Course is present on dashboard').fulfill() def otto_payment_using_cyber_source(self): """ Make payment for course by providing Billing Info and Payment details in respected areas. """ self.cyber_source_page.set_card_holder_info(CARD_HOLDER_INFO) self.cyber_source_page.set_billing_info(BILLING_INFO) self.cyber_source_page.click_payment_button() self.receipt_page.wait_for_page() def unenroll_using_api(self, user_email, course_id): """ Un-enroll user from a course. Arguments: user_email(str): User's email course_id(str): The id of course in which user is enrolled. """ # Login to lms and get username self.lms_api_client.create_login_session(user_email, PASSWORD) username = self.lms_api_client.user_name # Verify that user is enrolled in the course using enrollment api. # If enrolled, then un-enroll user using api. is_enrolled = self.enrollment_api_client.is_user_enrolled( username, course_id) if is_enrolled: self.lms_api_client.change_enrollment(course_id, 'unenroll') def verify_info_is_populated_on_basket(self, discounted_price): """ After discount redeem url is used verify that following information is displayed correctly on basket page: i) Coupon is applied ii) Discounted amount Arguments: discounted_price(float): Discounted price of the course. """ self.assertTrue(self.single_seat_basket.is_voucher_applied()) self.assertEqual(self.single_seat_basket.total_price_after_discount, discounted_price) def unenroll_using_ui(self): """ Un-enroll student from the course. """ if not self.dashboard_page.is_browser_on_page(): self.dashboard_page.visit() if self.dashboard_page.is_course_present(self.course_id): self.dashboard_page.unenroll_course(self.course_id) def assert_enrollment_and_unenroll(self): """ Asserts that course is added to user dashboard and user can access the course. After that un-enroll from the course. """ self.assert_course_added_to_dashboard() self.unenroll_using_ui() def pay_with_cybersource(self): """ Make payment using cybersource. """ # Fill out all the billing and payment details and submit the form self.otto_payment_using_cyber_source() # Application should take user to the receipt page # Verify on receipt page that information like course title, # course price, total price order date and billing to is # displayed correctly self.verify_receipt_info() self.receipt_page.click_in_nav_to_go_to_dashboard() def verify_receipt_info(self): """ Verify that Course title, Course Price, total price and order date on receipt page is correct. """ self.assertIn(self.course_title, self.receipt_page.order_desc) self.assertEqual( # Slight chance that this will fail if the test execution crosses # the boundary of midnight text_type(datetime.datetime.utcnow().date()), self.receipt_page.order_date) self.assertEqual( [self.receipt_page.order_amount, self.receipt_page.total_amount], [self.course_price, self.total_price])
class EnterpriseTestBase(WebAppTest): """ Test Enterprise Login """ def setUp(self): """ Initialize all page objects """ super(EnterpriseTestBase, self).setUp() self.browser.maximize_window() self.ent_portal_login = EnterprisePortalLogin(self.browser) self.ent_portal_home = EnterprisePortalHome(self.browser) self.ent_portal_course_start = \ EnterprisePortalCourseStart(self.browser) self.ent_portal_course_structure = \ EnterprisePortalCourseStructure(self.browser) self.ent_course_enrollment = \ EnterpriseCourseEnrollment(self.browser) self.ent_data_sharing_consent = \ EnterpriseDataSharingConsentPage(self.browser) self.ecommerce_courses_page = \ EcommerceCoursesPage(self.browser) self.lms_login = LmsLogin(self.browser) self.ent_edx_registration = EnterpriseEdxRegistration(self.browser) self.ent_edx_login = EnterpriseEdxLogin(self.browser) self.dashboard = DashboardPageExtended(self.browser) self.courses_page = CoursesPage(self.browser) self.course_about_page = CourseAboutPageExtended(self.browser) self.track_selection_page = TrackSelectionPage(self.browser) self.user_account = UserAccountSettings(self.browser) self.cyber_source_page = CyberSourcePage(self.browser) self.single_seat_basket = SingleSeatBasketPage(self.browser) self.receipt_page = ReceiptPage(self.browser) self.lms_api_client = LmsApiClient() self.login_api = LmsLoginApi() self.logout_api = LogoutApi() def unlink_account(self): """ Unlink IDP Account This serves as a fixture for unlinked user test case, it unlinks the user after running the tests to make sure that the precondition of test is true """ # Visit account setting page self.user_account.visit() self.user_account.switch_account_settings_tabs('accounts-tab') # If linked account is found, unlink it if self.user_account.is_idp_account_linked(IDP_CSS_ID): self.user_account.unlink_idp_account(IDP_CSS_ID) # Logout using api self.logout_from_lms_using_api() def add_recovery_email(self, email): """ Add secondary email address for enterprise learner """ self.user_account.visit() self.user_account.fill_secondary_email_field(email) def login_to_ent_portal(self, ent_portal_username, ent_portal_password): """ Login to enterprise portal and find the course and click on it """ # Open portal self.ent_portal_login.visit() # Login self.ent_portal_login.login_to_portal( ent_portal_username, ent_portal_password) self.ent_portal_home.wait_for_page() def access_course(self): """ Access the course from portal """ # Open the course pop up and look for the desired course self.ent_portal_home.open_courses_popup() course_titles = self.ent_portal_home.fetch_course_titles_list() self.assert_( ENT_COURSE_TITLE in course_title for course_title in course_titles ) # Go to course page and then use the link there to go to edX self.ent_portal_home.open_enterprise_course_page( ENT_COURSE_TITLE ) self.ent_portal_course_start.wait_for_page() self.ent_portal_course_start.start_or_continue_course() self.ent_portal_course_structure.wait_for_page() self.ent_portal_course_structure.open_course_on_edx() # Get handle of newly opened edx window and switch control to it edx_window = self.driver.window_handles[1] self.driver.switch_to_window(edx_window) def login_ent_edx_user(self): """ Login the user using edX customized logistration page """ # edx credentials self.ent_edx_login.wait_for_page() self.assertEqual( ENTERPRISE_NAME, self.ent_edx_login.get_enterprise_name() ) self.ent_edx_login.login( LOGIN_EMAIL, LOGIN_PASSWORD ) def register_ent_edx_user(self): """ Register the enterprise user using edX customized logistration page """ __, email = get_random_credentials() self.ent_edx_registration.visit() self.assertEqual( ENTERPRISE_NAME, self.ent_edx_registration.get_enterprise_name() ) self.ent_edx_registration.register( email=email, full_name='Enterprise Test User', country="US" ) def logout_from_lms_using_api(self): """ Get cookies from browser and send these cookie to python request to logout using api """ self.logout_api.logout_url = '{}://{}/{}'.format( LMS_PROTOCOL, LMS_BASE_URL, 'logout' ) self.logout_api.cookies = self.browser.get_cookies() self.logout_api.logout() def login_user_lms_using_api(self): """ Login user to LMS using login API """ self.login_api.authenticate(self.browser) def login_and_go_to_course_enrollment_page(self): """ Flow which covers the user login on enterprise portal, selecting the course and then login to edx course enrollment page """ # The edX site is visited just to make sure that when user jumps to # edX from portal we don't have to handle authentication popup self.lms_login.visit() # Enterprise portal flow self.login_to_ent_portal( ENT_PORTAL_USERNAME, ENT_PORTAL_PASSWORD) self.access_course() self.login_ent_edx_user() # Verify that user is on course enrollment page self.ent_course_enrollment.wait_for_page() def register_and_go_to_course_enrollment_page(self): """ Flow which covers the user login on enterprise portal, selecting the course and then register to edx course enrollment page """ # The edX site is visited just to make sure that when user jumps to # edX from portal we don't have to handle authentication popup self.lms_login.visit() # Enterprise portal flow self.login_to_ent_portal( ENT_PORTAL_USERNAME, ENT_PORTAL_PASSWORD) self.access_course() self.ent_edx_login.wait_for_page() self.register_ent_edx_user() # Verify that user is on course enrollment page self.ent_course_enrollment.wait_for_page() def payment_using_cyber_source(self): """ Make payment for course by providing Billing Info and Payment details in respected areas. """ self.cyber_source_page.set_card_holder_info(CARD_HOLDER_INFO) self.cyber_source_page.set_billing_info(BILLING_INFO) self.cyber_source_page.click_payment_button() self.receipt_page.wait_for_page() def register_edx_user(self): """ Register the user using edX registration page """ username, email = get_random_credentials() self.ent_edx_registration.visit() self.ent_edx_registration.register( email=email, full_name='Test User', username=username, password='******', country="US" ) self.dashboard.wait_for_page() def verify_info_is_populated_on_basket(self, discounted_price): """ After User accept data sharing consent from landing pag verify that following information is displayed correctly on basket page: i) Enterprise offer is applied ii) Discounted amount Arguments: discounted_price(float): Discounted price of the course. """ self.assertTrue(self.single_seat_basket.is_offer_applied()) self.assertEqual( self.single_seat_basket.total_price_after_discount, discounted_price ) self.payment_using_cyber_source() def verify_receipt_info_for_discounted_course(self): """ Verify that info on receipt page is correct. Verify i) Course title. ii) Order date """ self.assertIn(ENT_COURSE_TITLE, self.receipt_page.order_desc) self.assertEqual( datetime.utcnow().strftime("%Y-%m-%d"), self.receipt_page.order_date )
class CourseEnrollmentTest(WhiteLabelTestsBaseClass): """ Class for tests with enrollment capability """ def setUp(self): super(CourseEnrollmentTest, self).setUp() self.lms_api_client = LmsApiClient() self.enrollment_api_client = EnrollmentApiClient() # Initialize all page objects self.cyber_source_page = CyberSourcePage(self.browser) self.courses_page = CoursesPage(self.browser) self.multi_seat_basket_page = MultiSeatBasketPage(self.browser) self.single_seat_basket_page = SingleSeatBasketPage(self.browser) self.receipt_page = ReceiptPage(self.browser) # Initialize all common variables self.course_id = '' self.course_title = '' self.course_price = 0.0 self.total_price = 0.0 self.full_cleanup = True def go_to_basket(self, bulk_purchase=False): """ Perform all the steps from dashboard to reaching the basket page. If bulk_purchase is set to 'True' then go to multi seat basket, otherwise go to single seat basket. Arguments: bulk_purchase(bool): Indicates type of the purchase. """ course_about_page = CourseAboutPage(self.browser, self.course_id) # Check that course is not already present on dashboard and use find # course link to go to courses page self.assertFalse(self.dashboard_page.is_course_present(self.course_id)) self.dashboard_page.click_courses_button() self.courses_page.wait_for_page() # find the target course and click on it to go to about page self.courses_page.click_on_the_course(self.course_id) course_about_page.wait_for_page() # Verify that course price is correct on course about page self.assertEqual( self.course_price, course_about_page.course_price ) if bulk_purchase: # go to multi seat basket page course_about_page.click_on_multi_seat_basket() self.multi_seat_basket_page.wait_for_page() else: # go to single seat basket page course_about_page.click_on_single_seat_basket() self.single_seat_basket_page.wait_for_page() # Verify course name, course price and total price on basket page # self.verify_course_name_on_basket() self.verify_price_on_basket() def verify_course_name_on_basket(self): """ Verify that course name is displayed correctly on basket page. """ self.ecom_cookies = self.browser.get_cookies() self.assertIn(self.course_title, self.basket_page.course_name) def verify_price_on_basket(self): """ Verify that course price and total price are displayed correctly on basket page. """ self.assertEqual( [self.basket_page.course_price, self.basket_page.total_price], [self.course_price, self.total_price] ) def assert_enrollment_and_logout(self): """ Verify that course is added to user dashboard and user can access the course. After that, logout from application. """ self.assert_course_added_to_dashboard() self.logout_from_ecommerce_using_api() def assert_course_added_to_dashboard(self): """ Waits for course to appear on dashboard. """ def check_course(): """ Checks if course is present on dashboard and revisits the page if it is not there. Returns: True: If course present False: Otherwise """ if self.dashboard_page.is_course_present(self.course_id): return True self.dashboard_page.visit() return False EmptyPromise( check_course, 'Course is present on dashboard' ).fulfill() def otto_payment_using_cyber_source(self): """ Make payment for course by providing Billing Info and Payment details in respected areas. """ self.cyber_source_page.set_card_holder_info(CARD_HOLDER_INFO) self.cyber_source_page.set_billing_info(BILLING_INFO) self.cyber_source_page.click_payment_button() self.receipt_page.wait_for_page() def unenroll_using_api(self, user_email, course_id): """ Un-enroll user from a course. Arguments: user_email(str): User's email course_id(str): The id of course in which user is enrolled. """ # Login to lms and get username self.lms_api_client.create_login_session(user_email, PASSWORD) username = self.lms_api_client.user_name # Verify that user is enrolled in the course using enrollment api. # If enrolled, then un-enroll user using api. is_enrolled = self.enrollment_api_client.is_user_enrolled( username, course_id ) if is_enrolled: self.lms_api_client.change_enrollment(course_id, 'unenroll') def verify_info_is_populated_on_basket(self, discounted_price): """ After discount redeem url is used verify that following information is displayed correctly on basket page: i) Coupon is applied ii) Discounted amount Arguments: discounted_price(float): Discounted price of the course. """ self.assertTrue(self.single_seat_basket.is_voucher_applied()) self.assertEqual( self.single_seat_basket.total_price_after_discount, discounted_price ) def unenroll_using_ui(self): """ Un-enroll student from the course. """ if not self.dashboard_page.is_browser_on_page(): self.dashboard_page.visit() if self.dashboard_page.is_course_present(self.course_id): self.dashboard_page.unenroll_course(self.course_id) def assert_enrollment_and_unenroll(self): """ Asserts that course is added to user dashboard and user can access the course. After that un-enroll from the course. """ self.assert_course_added_to_dashboard() self.unenroll_using_ui() def pay_with_cybersource(self): """ Make payment using cybersource. """ # Fill out all the billing and payment details and submit the form self.otto_payment_using_cyber_source() # Application should take user to the receipt page # Verify on receipt page that information like course title, # course price, total price order date and billing to is # displayed correctly self.verify_receipt_info() self.receipt_page.click_in_nav_to_go_to_dashboard() def verify_receipt_info(self): """ Verify that Course title, Course Price, total price and order date on receipt page is correct. """ self.assertIn(self.course_title, self.receipt_page.order_desc) self.assertEqual( # Slight chance that this will fail if the test execution crosses # the boundary of midnight text_type(datetime.datetime.utcnow().date()), self.receipt_page.order_date ) self.assertEqual( [self.receipt_page.order_amount, self.receipt_page.total_amount], [self.course_price, self.total_price] )
class VouchersTest(CourseEnrollmentTest): """ Base class for tests related to vouchers(coupons) """ def setUp(self): super(VouchersTest, self).setUp() self.ecommerce_api = EcommerceApiClient() # Initialize all objects self.home = HomePage(self.browser) self.redeem_coupon_error_page = RedeemCouponErrorPage(self.browser) self.single_seat_basket = SingleSeatBasketPage(self.browser) self.coupon = None def enroll_using_discount_code(self, coupon_code): """ Use coupon code to enroll a user in a course. Arguments: coupon_code(unicode string): The coupon code to use for enrollment. """ self.ecom_cookies = self.browser.get_cookies() self.single_seat_basket.apply_coupon_code(coupon_code) self.verify_coupon_is_applied_on_basket() # Fill out all the billing and payment details and submit the form self.otto_payment_using_cyber_source() # Verify on receipt page that information like course title, # course price, total price # order date and billing to is displayed correctly self.verify_receipt_info_for_discounted_course() self.receipt_page.click_in_nav_to_go_to_dashboard() self.dashboard_page.wait_for_page() def enroll_using_enrollment_code(self, coupon_code): """ Enroll in the course after enrollment coupon is applied Note that for enrollment code we assume a 100% discount Arguments: coupon_code(unicode string): The coupon code to use for enrollment. """ self.ecom_cookies = self.browser.get_cookies() self.single_seat_basket.apply_coupon_code(coupon_code) self.verify_after_coupon_is_applied_on_basket() self.single_seat_basket.go_to_receipt_page() self.receipt_page.wait_for_page() # Verify on receipt page that information like course title, # course price, total price # order date and billing to is displayed correctly self.verify_receipt_info_for_discounted_course() self.receipt_page.click_in_nav_to_go_to_dashboard() self.dashboard_page.wait_for_page() def error_message_on_invalid_coupon_code(self, coupon_code): """ Apply the invalid coupon and get error message. Arguments: coupon_code(unicode string): Coupon code for enrollment. Returns: str: The error message after applying the coupon. """ self.ecom_cookies = self.browser.get_cookies() self.single_seat_basket.apply_coupon_code(coupon_code) return self.single_seat_basket.get_error_message_for_invalid_coupon() def verify_coupon_is_applied_on_basket(self): """ Verifies that coupon has been applied on the basket page. Specifically verify i) Coupon code is applied ii) Price after coupon application is correct """ self.assertTrue(self.single_seat_basket.is_voucher_applied()) self.assertEqual( self.basket_page.total_price, self.coupon.discounted_course_price ) def verify_receipt_info_for_discounted_course(self): """ Verify that info on receipt page is correct. Verify i) Course title. ii) Order date """ self.assertIn(self.course_title, self.receipt_page.order_desc) self.assertEqual( datetime.utcnow().strftime("%Y-%m-%d"), self.receipt_page.order_date ) def redeem_single_course_discount_coupon(self, coupon_url): """ Redeem single course discount coupon. Arguments: coupon_url: Url of the coupon. """ redeem_coupon_page = RedeemCouponPage(self.browser, coupon_url) redeem_coupon_page.visit() redeem_coupon_page.wait_for_course_tile() self.verify_course_info_on_coupon_redeem_page(redeem_coupon_page) redeem_coupon_page.click_checkout_button(self.course_id) def redeem_single_course_enrollment_coupon(self, coupon_url, target_page): """ Redeem single course enrollment coupon Args coupon_url: Url of the coupon. target_page: Destination page. """ redeem_coupon_page = RedeemCouponPage(self.browser, coupon_url).visit() redeem_coupon_page.wait_for_course_tile() self.verify_course_info_on_coupon_redeem_page(redeem_coupon_page) redeem_coupon_page.redeem_enrollment(target_page) def redeem_multi_course_enrollment_coupon( self, coupon_url, target_page, course_title): """ Redeem single course enrollment coupon Args coupon_url: Url of the coupon. target_page: Destination page. course_title: Title of the course. """ redeem_coupon_page = RedeemCouponPage(self.browser, coupon_url).visit() redeem_coupon_page.wait_for_course_tile() redeem_coupon_page.set_course_tile_index(course_title) self.verify_course_info_on_coupon_redeem_page(redeem_coupon_page) redeem_coupon_page.redeem_enrollment(target_page) def verify_course_info_on_coupon_redeem_page(self, redeem_coupon_page): """ Verify info on course tile of redeem coupons page. Verify i) Course Name ii) Course Organization iii) Discount Value iv) Discount type (Absolute or Percentage) v) Discounted Price Arguments: redeem_coupon_page: The redeem coupon page. """ course_info = redeem_coupon_page.get_course_info() course_discount_info = redeem_coupon_page.get_course_discount_info() self.assertEqual( [ course_info['course_name'], course_info['course_org'], course_discount_info['benefit_value'], course_discount_info['benefit_type'], course_discount_info['discounted_price'] ], [ self.course_title, ORG, self.coupon.benefit_value, self.coupon.benefit_type, self.coupon.discounted_course_price ] ) def make_payment_after_discount(self): """ Payment by active user after discount redeem url was applied. """ self.verify_info_is_populated_on_basket( self.coupon.discounted_course_price ) # Fill out all the billing and payment details and submit the form self.otto_payment_using_cyber_source() # Application should take user to the receipt page # Verify on receipt page that information like course title, # course price, total price # order date and billing to are displayed correctly. self.verify_receipt_info_for_discounted_course() self.receipt_page.click_in_nav_to_go_to_dashboard() def verify_after_coupon_is_applied_on_basket(self): """ After coupon code is applied on basket page, verify Code is applied """ self.assertTrue(self.single_seat_basket.is_voucher_applied())