def test_registered_user_payment_succeeds(self): print(" + test_registered_user_payment_succeeds \n".upper()) data = perform_registration(self.driver) perform_login(self.driver, data['username']) self.driver.find_element_by_xpath(TRY_FREE_XPATH).click() send_card_details(self.driver) wait = WebDriverWait(self.driver, 30) try: wait.until( EC.presence_of_element_located( (By.XPATH, "//div[@class='alert alert-success']"))) with self.subTest(name="test_user_roles_changes_role_on_payment"): print(" + test_user_roles_changes_role_on_payment \n".upper()) self.driver.get(self.url) try: cli = self.driver.find_element_by_xpath( "//div[@class='col-md-3 col-sm-4 col-xs-12'][2]/ul/li[1]/a" ) self.driver.execute_script("arguments[0].click();", cli) self.assertNotIn( "No Access", self.driver.find_elements_by_xpath( "//div[@class='level-right']")) except NoSuchElementException as e: raise AssertionError( "Could not navigate to course: \n {}".format(e)) except Exception as e: print(e) raise AssertionError("Payment did not succeed")
def test_work_experience_page_is_active(self): print(" + test_work_experience_page_is_active \n".upper()) self.driver.find_element_by_link_text("Work Experience").click() self.assertIn("Work", self.driver.title) with self.subTest(name="test_price_is_not_visible_to_guests"): try: self.driver.find_element_by_xpath( "//div[@class='col-12 col-md-5 col-sec-1']/div[@class='abouttext4']/h4[@id='marg']" ) except NoSuchElementException: return True else: raise AssertionError("Price was visible to guest user") # todo Fix when user redirection is fixed with self.subTest("test_price_is_visible_to_authenticated_user"): print(" + test_price_is_visible_to_authenticated_user \n".upper()) perform_login(self.driver) self.driver.find_element_by_link_text("Work Experience") try: self.driver.find_element_by_xpath( "//div[@class='col-12 col-md-5 col-sec-1']/div[@class='abouttext4']/h4[@id='marg']" ) except NoSuchElementException: raise AssertionError( "Authenticated user unable to see WE price") with self.subTest( "test_aurhenticated_user_on_click_entry_level_terms_and_condition_page_is_displayed" ): print( " + test_aurhenticated_user_on_click_entry_level_terms_and_condition_page_is_displayed \n" .upper()) self.driver.find_element_by_xpath(ENTRY_LEVEL_XPATH).click() # todo Figure out if uest should see terms and confitions self.driver.find_element_by_link_text("I AGREE").click() self.assertIn("Log in", self.driver.title.upper())
def test_authenticated_user_senior_level_placement_form_zero_experience_redirects_to_entry_level_application( self): print( " + test_authenticated_user_senior_level_placement_form_zero_experience_redirects_to_entry_level_application \n" .upper()) try: d = perform_registration(self.driver) perform_login(self.driver, d['username']) self.driver.find_element_by_link_text( "Job Placement Program").click() self.driver.find_element_by_xpath(GET_STARTED_SENOIR_XPATH).click() self.driver.find_element_by_xpath( '//*[@id="id_education"]').send_keys( parser.get('jp_s', 'id_education')) self.driver.find_element_by_xpath( '//*[@id="id_resume"]').send_keys(BASE_DIR + docpath) self.driver.find_element_by_xpath( '//*[@id="id_career"]').send_keys( parser.get('jp_s', 'id_career')) # self.driver.find_element_by_xpath('//*[@id="id_certificates"]').send_keys( # BASE_DIR + "\documents\\test_resume.pdf")[2:] # ) self.driver.find_element_by_xpath( '//*[@id="id_is_certified"]').send_keys( parser.get('jp_e', 'id_is_certified')) self.driver.find_element_by_xpath( '//*[@id="app"]/div[11]/input').click() self.assertIn( "not meet", self.driver.find_element_by_xpath( "//*[@class='alert alert-danger']").text.lower()) except Exception as e: print(e) raise AssertionError("Test failed")
def test_authenticated_user_subscription_success(self): d = perform_registration(self.driver) perform_login(self.driver, d['username']) self.driver.find_element_by_link_text("Projects").click() x = self.driver.find_elements_by_xpath(PROJECT_XPATH) # self.driver.find_elements_by_xpath(PROJECT_XPATH).click() x[-1].click() self.driver.find_element_by_link_text("Start Project").click() try: # self.driver.find_element_by_xpath("//button[@class='stripe-button-el']/span") send_card_details(self.driver) wait = WebDriverWait(self.driver, 20) wait.until( EC.presence_of_element_located( (By.XPATH, "//div[@class='alert alert-success']"))) self.assertEqual( "Congratulations, you have successfully subscribed for our Standard Plan package.", self.driver.find_element_by_xpath( "//div[@class='alert alert-success']").text) # todo on subscription, return to the item paid for with self.subTest( name= "test_authenticated_user_redirect_on_subscription_success" ): pass except: raise AssertionError("Failed")
def test_authenticated_user_can_access_account_settings_page(self): text = "" username = parser.get("authentication", 'username') password = parser.get("authentication", 'password') perform_login(self.driver, username, password,after_signup=False) self.driver.get(self.url.rstrip("/") + "/user/account/settings") try: text = self.driver.find_element_by_xpath("//h3[@class='hblue']").text except NoSuchElementException as e: print(e) self.assertTrue("Credentials" in text) # Todo self.assertTrue("Account" in self.driver.title) with self.subTest(name="authenticated_user_can_play_the_video"): self.driver.switch_to.frame( self.driver.find_element_by_xpath('//iframe[starts-with(@src, "https://www.youtube.com/embed")]')) try: WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable((By.XPATH, '//button[@aria-label="Play"]'))).click() self.driver.switch_to.default_content() except Exception as e: print(e) raise AssertionError("Could not play video") with self.subTest(name="authenticated_user_invalid_file_upload_fails"): self.driver.find_element_by_id("upload-file").send_keys(BASE_DIR + "/documents/non_csv.png") self.driver.find_element_by_xpath(UPLOAD_XPATH).click() self.assertIn("csv files only", self.driver.find_element_by_xpath("//div[@class='alert alert-danger']/p").text) with self.subTest(name="authenticated_user_invalid_csv_upload_fails"): self.driver.find_element_by_id("upload-file").send_keys(BASE_DIR + "/documents/invalid_key.csv") self.driver.find_element_by_xpath(UPLOAD_XPATH).click() self.assertIn("error while validating credentials", self.driver.find_element_by_xpath( "//div[@class='alert alert-danger']/p").text) with self.subTest(name="authenticated_user_cannot_start_machine_with_invalid_csv"): self.assertEqual("Invalid", self.driver.find_element_by_xpath( "//div[@class='col-xs-12 col-sm-12 col-lg-6 mgb50'][1]/p[@class='hred rnd-back2']").text) with self.subTest(name="authenticated_user_valid_csv_upload_succeeds"): self.driver.find_element_by_id("upload-file").send_keys(BASE_DIR + "/documents/valid_key.csv") self.driver.find_element_by_xpath(UPLOAD_XPATH).click() self.assertIn("Valid", self.driver.find_element_by_xpath( "//div[@class='col-xs-12 col-sm-12 col-lg-6 mgb50'][1]/p").text) with self.subTest(name="authenticated_user_can_start_machine_with_valid_csv"): pass
def test_authenticated_user_can_submit_job_junior_level_placement_form_no_certificate( self): print( " + test_authenticated_user_can_submit_job_junior_level_placement_form_no_certificate \n" .upper()) self.driver.find_element_by_xpath(GET_STARTED_ENTRY_XPATH).click() data = perform_registration(self.driver, True) perform_login(self.driver, data['username']) # todo check the title instead try: # todo fix redirection to page self.driver.find_element_by_link_text( "Job Placement Program").click() self.driver.find_element_by_xpath(GET_STARTED_ENTRY_XPATH).click() self.driver.find_element_by_xpath( '//*[@id="id_education"]').send_keys( parser.get('jp_e', 'id_education')) self.driver.find_element_by_xpath( '//*[@id="id_resume"]').send_keys(BASE_DIR + docpath) self.driver.find_element_by_xpath( '//*[@id="id_career"]').send_keys( parser.get('jp_e', 'id_career')) self.driver.find_element_by_xpath( '//*[@id="id_is_certified"]').send_keys( parser.get('jp_e', 'id_is_certified')) self.driver.find_element_by_xpath( '//*[@id="app"]/div[11]/input').click() with self.subTest( name= "test_entry_level_applicant_with_no_certificate_redirected_to_the_certification_page" ): print( " + test_entry_level_applicant_with_no_certificate_redirected_to_the_certification_page \n" .upper()) text = "" try: text = self.driver.find_element_by_tag_name( "h2").text.lower() except NoSuchElementException: pass # raise AssertionError("Not taken to certification page") self.assertIn("not met", text) # todo fix mail sending. # with self.subTest(name="test_notification_email_is_sent_on_success"): # self.assertIn("PLACEMENT", # get_mail_content(*data['email'].split("@"))) except Exception as e: raise AssertionError("Form not submitted")
def login(self, request, redirect_url=None): ret = perform_login(request, self.user, redirect_url=redirect_url) if self.cleaned_data["remember"]: request.session.set_expiry(60 * 60 * 24 * 7 * 3) else: request.session.set_expiry(0) return ret
def test_unauthorized_user_login_failed(self): print(" + test_unauthorized_user_login_failed \n".upper()) self.logger.info("test_unauthorized_user_login_failed") username = parser.get('authentication', 'fakeuser') password = parser.get('authentication', 'fakepassword') perform_login(self.driver, username, password) elem = "" try: elem = self.driver.find_element_by_xpath( "//li[@class='has-dropdown sub-menu profile']/a[@class='b-n']" ).text except Exception: pass self.assertFalse(username in elem, "Unauthorized user was granted access" + username)
def test_guest_user_is_directed_to_senoir_placement_page_on_authentication( self): print( " + test_guest_user_is_directed_to_senoir_placement_page_on_authentication \n" .upper()) self.driver.find_element_by_xpath(GET_STARTED_SENOIR_XPATH).click() data = perform_registration(self.driver, True) perform_login(self.driver, data['username']) # todo check the title instead try: # todo fix redirection to page self.driver.find_element_by_xpath(FORM_HEADER_XPATH) self.assertIn("Application Form", self.driver.find_element_by_xpath(FORM_HEADER_XPATH)) except NoSuchElementException: raise AssertionError("Not directed to placement form")
def test_authorized_user_login_success(self): print(" + test_authorized_user_login_success \n".upper()) self.logger.info("test_authorized_user_login_success") username = parser.get('authentication', 'username') password = parser.get('authentication', 'password') first_name = parser.get('authentication', 'firstname') perform_login(self.driver, username, password) self.driver.get(self.url) elem = "" try: elem = self.driver.find_element_by_xpath( "//li[@class='has-dropdown sub-menu profile']/a[@class='b-n']" ).text except Exception: pass self.assertTrue(first_name.upper() in elem, "Login failed for " + username)
def test_aurhenticated_user_on_click_entry_level_terms_and_condition_page_is_displayed( self): print( " + test_aurhenticated_user_on_click_entry_level_terms_and_condition_page_is_displayed \n" .upper()) d = perform_registration(self.driver) perform_login(self.driver, d['username']) self.driver.find_element_by_link_text("Work Experience").click() self.driver.find_element_by_xpath(ENTRY_LEVEL_XPATH).click() # todo Figure out if uest should see terms and confitions try: self.assertTrue(self.driver.find_element_by_link_text("I AGREE")) with self.subTest( name="test_terms_and_condition_entry_leads_to_payment_page" ): self.driver.find_element_by_link_text("I AGREE").click() self.assertIn("Pay", self.driver.title) except NoSuchElementException: raise AssertionError("Agreement page not reached")
def test_logged_in_user_can_open_the_profile_page(self): return text = "" perform_login(self.driver) # Todo Javascript action fails in selenium headless # self.driver.execute_script("arguments[0].click();", # self.driver.find_element_by_xpath("//div[@class='container text-1 ']/div[@class='col-md-4 col-sm-6'][1]/ul/li[1]/a")) self.driver.get(self.url.rstrip("/") + "/courses/labprofile") try: w = WebDriverWait(self.driver, 10) w.until( EC.text_to_be_present_in_element_value( (By.XPATH, "//div[@class='display-tc animate-box h1-bg']/h1"), "Lab Profile")) text = self.driver.find_element_by_xpath( "//div[@class='display-tc animate-box h1-bg']/h1").text except NoSuchElementException as e: print("Ex: {}".format(e)) screenshot(self.driver, "test_logged_in_user_can_open_the_profile_page") self.assertTrue("Profile" in text, "Profile Page not reached")
def test_authenticated_user_can_view_all_orders(self): perform_login(self.driver) # self.driver.execute_script("argument[0].click;",self.driver.find_element_by_xpath( # "//div[@class='container text-1 ']/div[@class='col-md-4 col-sm-6'][2]/ul/li/a")) self.assertIn("Order", self.driver.title)
def test_authenticated_user_can_submit_job_senoir_level_placement_form( self): print( " + test_authenticated_user_can_submit_job_senoir_level_placement_form \n" .upper()) self.driver.find_element_by_xpath(GET_STARTED_SENOIR_XPATH).click() data = perform_registration(self.driver, True) perform_login(self.driver, data['username']) # todo check the title instead try: # todo fix redirection to page self.driver.find_element_by_link_text( "Job Placement Program").click() self.driver.find_element_by_xpath(GET_STARTED_SENOIR_XPATH).click() self.driver.find_element_by_xpath( '//*[@id="id_education"]').send_keys( parser.get('jp_s', 'id_education')) self.driver.find_element_by_xpath( '//*[@id="id_resume"]').send_keys(BASE_DIR + docpath) self.driver.find_element_by_xpath( '//*[@id="id_career"]').send_keys( parser.get('jp_s', 'id_career')) self.driver.find_element_by_xpath( '//*[@id="id_experience"]').send_keys( parser.get('jp_s', 'id_experience')) self.driver.find_element_by_xpath( '//*[@id="id_certificates"]').send_keys(BASE_DIR + docpath) self.driver.find_element_by_xpath( '//*[@id="id_is_certified"]').send_keys( parser.get('jp_s', 'id_is_certified')) self.driver.find_element_by_xpath( '//*[@id="app"]/div[11]/input').click() with self.subTest( name= "test_senoir_level_applicant_with_certificate_not_redirected_to_the_certification_page" ): print( " + test_senoir_level_applicant_with_certificate_not_redirected_to_the_certification_page \n" .upper()) text = "" try: text = self.driver.find_element_by_tag_name( "h2").text.lower() except NoSuchElementException as e: print(e) raise AssertionError("Error") self.assertIn("requirements met", text) with self.subTest( name="test_proceed_on_senoir_leads_to_agreement"): print( " + test_proceed_on_senoir_leads_to_agreement \n".upper()) self.driver.find_element_by_link_text("Proceed").click() self.assertIn("leif", self.driver.title.lower()) # todo fix mail sending. with self.subTest( name="test_notification_email_is_sent_on_success"): print( " + test_notification_email_is_sent_on_success \n".upper()) self.assertIn("AGREEMENT", get_mail_content(*data['email'].split("@"))) except Exception as e: print(e) raise AssertionError("Form not submitted")
def login(self, request): perform_login(request, self.user) if self.cleaned_data["remember"]: request.session.set_expiry(60 * 60 * 24 * 7 * 3) else: request.session.set_expiry(0)
def test_payment_succeeds_for_professional__level(self): print(" + test_payment_succeeds_for_professional__level \n".upper()) d = perform_registration(self.driver) perform_login(self.driver, d['username']) self.driver.find_element_by_link_text("Work Experience").click() self.driver.find_element_by_xpath(PROFESSIONAL_LEVEL_XPATH).click() c = self.driver.find_element_by_link_text("I AGREE") self.driver.execute_script("arguments[0].click();", c) send_card_details( self.driver, "//form[@id='stripejsfilemain']/button[@class='stripe-button-el']") wait = WebDriverWait(self.driver, 10) try: wait.until(EC.presence_of_element_located((By.XPATH, REQ_XPATH))) with self.subTest( name= "test_authenticated_user_can_access_contract_page_on_professional_payment" ): print( " + test_authenticated_user_can_access_contract_page_on_professional_payment \n" .upper()) self.driver.find_element_by_xpath(PROCEED_XPATH).click() self.assertIn( "Income Share Agreement", self.driver.find_element_by_xpath( "//div[@class='el-card__body']/div[@class='row'][2]/div[@class='col-lg-12']/h4" ).text) with self.subTest( name="test_user_is_forced_to_fill_unfilled_form_on_login"): print( " + test_user_is_forced_to_fill_unfilled_form_on_login \n". upper()) self.driver.get(self.url.rstrip('/') + "/logout") self.driver.get(self.url) perform_login(self.driver, d['username']) self.assertIn( "Work Experience", self.driver.find_element_by_xpath( "//h2[@class='title-4']").text) with self.subTest(name="test_profile_form_fill_success"): print(" + test_profile_form_fill_success \n".upper()) self.driver.find_element_by_name('types').send_keys( parser.get("we", 'types')) self.driver.find_element_by_name('current_position').send_keys( parser.get("we", 'current_position')) self.driver.find_element_by_name('state').send_keys( parser.get("we", 'state')) self.driver.find_element_by_name('income').send_keys( parser.get("we", 'income')) self.driver.find_element_by_name('date').send_keys( parser.get("we", 'date')) self.driver.find_element_by_xpath( "//*[@type='submit']").click() try: wait.until( EC.visibility_of_element_located(( By.XPATH, "//div[@class='jobtype'][1]/p[@class='jobtypeh'][1]" ))) except: raise AssertionError("Form submit failed") # todo fix mail notification not sending with self.subTest( name= "test_notification_is_sent__professional_successful_payment" ): print( " + test_notification_is_sent__professional_successful_payment \n" .upper()) try: self.assertIn("EXPERIENCE", get_mail_content(*d['email'].split("@"))) except NoSuchElementException: raise AssertionError("Mail not sent") except Exception as e: print(e) raise AssertionError("Failed")
def login(self, request, user): # nasty hack to get get_user to work in Django user.backend = "django.contrib.auth.backends.ModelBackend" perform_login(request, user)
def test_invalid_password_entered(self): self.logger.info("test_invalid_password_entered") self.driver.find_element_by_link_text("Log In").click() username = parser.get('authentication', 'username') password = parser.get('authentication', 'fakepassword') perform_login(self.driver, username, password)
def test_user_login_opens_the_current_course(self): d = perform_registration(self.driver) perform_login(self.driver, d['username'])
def test_authenticated_user_redirected_to_selected_project(self): self.driver.find_element_by_xpath(PROJECT_XPATH).click() previous_url = self.driver.current_url self.driver.find_element_by_link_text("Start Project").click() perform_login(self.driver, after_signup=False) self.assertEqual(previous_url, self.driver.current_url)