Update test case script with improvements
- Introduce pytest framework to consolidate test cases into a single file. - Directly test the login functionality for newly created Teaching Assistants (TA's).Bug460-Malango
							parent
							
								
									f29f2d5212
								
							
						
					
					
						commit
						f3f7e0ccfd
					
				|  | @ -1,27 +0,0 @@ | |||
| import time | ||||
| 
 | ||||
| from selenium import webdriver | ||||
| from selenium.webdriver.common.by import By | ||||
| 
 | ||||
| driver_open = webdriver.Chrome() | ||||
| 
 | ||||
| # Open the website | ||||
| driver_open.get("http://localhost/lrr/") | ||||
| try: | ||||
|     username_input = driver_open.find_element('name', "user") | ||||
| 
 | ||||
|     password_input = driver_open.find_element('name', "password") | ||||
| 
 | ||||
|     login_button = driver_open.find_element('id', "login_btn") | ||||
|     # login as the new TA | ||||
|     username_input.send_keys("lanhuitest@test.com")        # login with credentials of the created TA | ||||
|     password_input.send_keys("lanhui12345678") | ||||
|     # Click the login button | ||||
|     login_button.click() | ||||
|     my_course = driver_open.find_element(By.CLASS_NAME, "display-6") | ||||
| 
 | ||||
|     print(" WELCOME TA YOU ARE IN") | ||||
|     time.sleep(20) | ||||
| 
 | ||||
| finally: | ||||
|     driver_open.quit() | ||||
|  | @ -1,71 +0,0 @@ | |||
| import time | ||||
| 
 | ||||
| from selenium import webdriver | ||||
| from selenium.webdriver.common.by import By | ||||
| from selenium.webdriver.support.wait import WebDriverWait | ||||
| from selenium.webdriver.support import expected_conditions as EC | ||||
| 
 | ||||
| 
 | ||||
| driver_open = webdriver.Chrome() | ||||
| 
 | ||||
| # Open the website | ||||
| driver_open.get("http://localhost/lrr/") | ||||
| 
 | ||||
| username_input = driver_open.find_element('name', "user") | ||||
| 
 | ||||
| password_input = driver_open.find_element('name', "password") | ||||
| 
 | ||||
| login_button = driver_open.find_element('id', "login_btn") | ||||
| 
 | ||||
| # login as a TA | ||||
| username_input.send_keys("lanhui@qq.com") | ||||
| password_input.send_keys("nil1234H@") | ||||
| # Click the login button | ||||
| login_button.click() | ||||
| admin_tab = driver_open.find_element('id', 'admin_tab') | ||||
| admin_tab.click() | ||||
| print("login sucessfully") | ||||
| cte_instructor = driver_open.find_element('id', 'tab_ins_accounts') | ||||
| cte_instructor.click() | ||||
| print(" everything is ok here ") | ||||
| t = time.localtime() | ||||
| current_time = time.strftime("%H:%M:%S", t) | ||||
| time.sleep(25) | ||||
| def createTA(driver, TA_name, emails, password): | ||||
|     full_name = driver.find_element('name', 'fullname') | ||||
|     full_name.send_keys(TA_name) | ||||
|     email= driver.find_element('name', 'email') | ||||
|     email.send_keys(emails) | ||||
|     pas=driver.find_element('name', 'password') | ||||
|     pas.send_keys(password) | ||||
|     usr_type=driver.find_element('name', 'type') | ||||
|     usr_type.click() | ||||
|     click_create =driver.find_element('name', 'create_btn') | ||||
|     click_create.click() | ||||
| 
 | ||||
| 
 | ||||
| try: | ||||
|     createTA(driver_open,"lanhuitest","lanhuitest@test.com","lanhui12345678")  # CREATE A TA  WITH FULLNAME lanhuitest email lanhuitest@test.com  password lanhui12345678 | ||||
| 
 | ||||
|     get_output = WebDriverWait(driver_open, 25).until( | ||||
|         EC.element_to_be_clickable((By.ID, "tab_ins_accounts")) | ||||
|          ) | ||||
|     get_output.click() | ||||
| 
 | ||||
|     get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning") | ||||
|     txt_alert = get_output_msg.text | ||||
|     print(f" alert message is : {txt_alert}") | ||||
| 
 | ||||
|     try: | ||||
|         with open('TEST_CREATING_TA.txt', 'a') as test_output: | ||||
|             test_output.write(f"\n {current_time} check this message  : {txt_alert}") | ||||
|     except Exception as e: | ||||
|         print(f"unexpected error: {e}") | ||||
| 
 | ||||
|     time.sleep(10) | ||||
| 
 | ||||
| finally: | ||||
|     driver_open.quit() | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  | @ -1,2 +0,0 @@ | |||
| 
 | ||||
|  14:27:01 check this message  : TA user created successfully. Use email lanhuitest@test.com as account name and lanhui12345678 as password. | ||||
|  | @ -1,68 +0,0 @@ | |||
| import time | ||||
| 
 | ||||
| from selenium import webdriver | ||||
| from selenium.webdriver.common.by import By | ||||
| from selenium.webdriver.support.wait import WebDriverWait | ||||
| from selenium.webdriver.support import expected_conditions as EC | ||||
| 
 | ||||
| 
 | ||||
| driver_open = webdriver.Chrome() | ||||
| 
 | ||||
| # Open the website | ||||
| driver_open.get("http://localhost/lrr/") | ||||
| 
 | ||||
| username_input = driver_open.find_element('name', "user") | ||||
| 
 | ||||
| password_input = driver_open.find_element('name', "password") | ||||
| 
 | ||||
| login_button = driver_open.find_element('id', "login_btn") | ||||
| 
 | ||||
| # login as a TA | ||||
| username_input.send_keys("lanhui@qq.com") | ||||
| password_input.send_keys("nil1234H@") | ||||
| # Click the login button | ||||
| login_button.click() | ||||
| admin_tab = driver_open.find_element('id', 'admin_tab') | ||||
| admin_tab.click() | ||||
| print("login sucessfully") | ||||
| cte_instructor = driver_open.find_element('id', 'tab_ins_accounts') | ||||
| cte_instructor.click() | ||||
| print(" everything is ok here ") | ||||
| t = time.localtime() | ||||
| current_time = time.strftime("%H:%M:%S", t) | ||||
| time.sleep(25) | ||||
| def createTA(driver, TA_name, emails, password): | ||||
|     full_name = driver.find_element('name', 'fullname') | ||||
|     full_name.send_keys(TA_name) | ||||
|     email= driver.find_element('name', 'email') | ||||
|     email.send_keys(emails) | ||||
|     pas=driver.find_element('name', 'password') | ||||
|     pas.send_keys(password) | ||||
|     usr_type=driver.find_element('name', 'type') | ||||
|     usr_type.click() | ||||
|     click_create =driver.find_element('name', 'create_btn') | ||||
|     click_create.click() | ||||
| 
 | ||||
| 
 | ||||
| try: | ||||
|     createTA(driver_open,"testneil","test@test.com","")  # create a TA  with fullname testneil email test@test.com  password empty to see if it generates a password. | ||||
|     print("Test case to check the generated password") | ||||
|     get_output = WebDriverWait(driver_open, 25).until( | ||||
|         EC.element_to_be_clickable((By.ID, "tab_ins_accounts")) | ||||
|     ) | ||||
|     get_output.click() | ||||
| 
 | ||||
|     get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning") | ||||
|     txt_alert = get_output_msg.text | ||||
|     print(f" alert message is : {txt_alert}") | ||||
| 
 | ||||
|     try: | ||||
|         with open('TEST_GENERATING_PASSWORD.txt', 'a') as test_output: | ||||
|             test_output.write(f"\n {current_time} check this message: {txt_alert}") | ||||
|     except Exception as e: | ||||
|         print(f"unexpected error: {e}") | ||||
| 
 | ||||
|     time.sleep(20) | ||||
| 
 | ||||
| finally: | ||||
|     driver_open.quit() | ||||
|  | @ -1,3 +0,0 @@ | |||
| 
 | ||||
|  14:23:33 check this message: TA user created successfully. Use email test@test.com as account name and msevSHBV)BXk as password. | ||||
|  14:25:35 check this message: Email address : test@test.com is already in use. | ||||
|  | @ -0,0 +1,206 @@ | |||
| import re | ||||
| import time | ||||
| import pytest | ||||
| 
 | ||||
| from selenium import webdriver | ||||
| from selenium.webdriver.common.by import By | ||||
| from selenium.webdriver.support.wait import WebDriverWait | ||||
| from selenium.webdriver.support import expected_conditions as EC | ||||
| 
 | ||||
| @pytest.mark.generate_password_1 | ||||
| def test_createTA(): | ||||
| 
 | ||||
|     driver_open = webdriver.Chrome() | ||||
|     driver_open.maximize_window() | ||||
| 
 | ||||
|     # Open the website | ||||
|     driver_open.get("http://localhost/lrr/") | ||||
| 
 | ||||
|     username_input = driver_open.find_element('name', "user") | ||||
| 
 | ||||
|     password_input = driver_open.find_element('name', "password") | ||||
| 
 | ||||
|     login_button = driver_open.find_element('id', "login_btn") | ||||
| 
 | ||||
|     # login as a TA | ||||
|     username_input.send_keys("lanhui@qq.com") | ||||
|     password_input.send_keys("nil1234H@") | ||||
|     # Click the login button | ||||
|     login_button.click() | ||||
|     admin_tab = driver_open.find_element('id', 'admin_tab') | ||||
|     admin_tab.click() | ||||
|     print("login sucessfully") | ||||
|     cte_instructor = driver_open.find_element('id', 'tab_ins_accounts') | ||||
|     cte_instructor.click() | ||||
|     print(" everything is ok here ") | ||||
|     t = time.localtime() | ||||
|     current_time = time.strftime("%H:%M:%S", t) | ||||
|     time.sleep(25) | ||||
|     def createTA(driver, TA_name, emails, password): | ||||
|         full_name = driver.find_element('name', 'fullname') | ||||
|         full_name.send_keys(TA_name) | ||||
|         email= driver.find_element('name', 'email') | ||||
|         email.send_keys(emails) | ||||
|         pas=driver.find_element('name', 'password') | ||||
|         pas.send_keys(password) | ||||
|         usr_type=driver.find_element('name', 'type') | ||||
|         usr_type.click() | ||||
|         click_create =driver.find_element('name', 'create_btn') | ||||
|         click_create.click() | ||||
| 
 | ||||
| 
 | ||||
|     try: | ||||
|         fullname = "testname" | ||||
|         email = "labtest0@fgy.com" | ||||
|         password = "newpasasr12345678" | ||||
|         createTA(driver_open,fullname,email,password)   # CREATE A TA  WITH FULLNAME lanhuitest email lanhuitest@test.com  password lanhui12345678 | ||||
| 
 | ||||
|         get_output = WebDriverWait(driver_open, 10).until( | ||||
|             EC.element_to_be_clickable((By.ID, "tab_ins_accounts")) | ||||
|              ) | ||||
|         get_output.click() | ||||
|         get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning") | ||||
|         txt_alert = get_output_msg.text | ||||
|         time.sleep(15) | ||||
| 
 | ||||
|         if txt_alert.find("TA user created successfully")==0: | ||||
| 
 | ||||
|             logout_button = driver_open.find_element(By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]") | ||||
|             logout_button.click() | ||||
|             time.sleep(15) | ||||
|             username_input = driver_open.find_element('name', "user") | ||||
|             password_input = driver_open.find_element('name', "password") | ||||
|             login_button = driver_open.find_element('id', "login_btn") | ||||
|             # login as the new TA | ||||
|             username_input.send_keys(email)  # login with credentials of the created TA | ||||
|             password_input.send_keys(password) | ||||
|             # Click the login button | ||||
|             time.sleep(20) | ||||
| 
 | ||||
|             login_button.click() | ||||
| 
 | ||||
|             time.sleep(15) | ||||
|             my_course = driver_open.find_element(By.CLASS_NAME, "display-6") | ||||
|             email_pattern = r"Use email (\S+) as account name" | ||||
|             password_pattern = r"as password (\S+)\." | ||||
|             email_match = re.search(email_pattern, txt_alert) | ||||
|             password_match = re.search(password_pattern, txt_alert) | ||||
|             print(f"Email: {email}") | ||||
|             print(f"Password: {password}") | ||||
|             print(" WELCOME TA YOU ARE IN") | ||||
| 
 | ||||
|         elif txt_alert.find("Email address ")==0: | ||||
|             print(" EMAIL ALREADY EXIST ") | ||||
|         else: | ||||
|             driver_open.quit() | ||||
|         try: | ||||
|             with open('TEST_CREATING_TA.txt', 'a') as test_output: | ||||
|                 test_output.write(f"\n {current_time} check this message  : {txt_alert}") | ||||
|         except Exception as e: | ||||
|             print(f"unexpected error: {e}") | ||||
| 
 | ||||
|         time.sleep(10) | ||||
| 
 | ||||
|     finally: | ||||
|         driver_open.quit() | ||||
| @pytest.mark.generate_password_2() | ||||
| def test_generate_password(): | ||||
|     driver_open = webdriver.Chrome() | ||||
| 
 | ||||
|     # Open the website | ||||
|     driver_open.get("http://localhost/lrr/") | ||||
|     driver_open.maximize_window() | ||||
| 
 | ||||
|     username_input = driver_open.find_element('name', "user") | ||||
| 
 | ||||
|     password_input = driver_open.find_element('name', "password") | ||||
| 
 | ||||
|     login_button = driver_open.find_element('id', "login_btn") | ||||
| 
 | ||||
|     # login as a TA | ||||
|     username_input.send_keys("lanhui@qq.com") | ||||
|     password_input.send_keys("nil1234H@") | ||||
|     # Click the login button | ||||
|     login_button.click() | ||||
|     admin_tab = driver_open.find_element('id', 'admin_tab') | ||||
|     admin_tab.click() | ||||
|     print("login sucessfully") | ||||
|     cte_instructor = driver_open.find_element('id', 'tab_ins_accounts') | ||||
|     cte_instructor.click() | ||||
|     print(" everything is ok here ") | ||||
|     t = time.localtime() | ||||
|     current_time = time.strftime("%H:%M:%S", t) | ||||
|     time.sleep(25) | ||||
| 
 | ||||
|     def createTA(driver, TA_name, emails, password): | ||||
|         full_name = driver.find_element('name', 'fullname') | ||||
|         full_name.send_keys(TA_name) | ||||
|         email = driver.find_element('name', 'email') | ||||
|         email.send_keys(emails) | ||||
|         pas = driver.find_element('name', 'password') | ||||
|         pas.send_keys(password) | ||||
|         usr_type = driver.find_element('name', 'type') | ||||
|         usr_type.click() | ||||
|         click_create = driver.find_element('name', 'create_btn') | ||||
|         click_create.click() | ||||
| 
 | ||||
|     try: | ||||
|         fullname = "tesame" | ||||
|         email = "generat@pass.com" | ||||
|         password = "" | ||||
|         createTA(driver_open, fullname, email, | ||||
|                  password)  # CREATE A TA  WITH FULLNAME lanhuitest email lanhuitest@test.com  password lanhui12345678 | ||||
| 
 | ||||
|         get_output = WebDriverWait(driver_open, 5).until( | ||||
|             EC.element_to_be_clickable((By.ID, "tab_ins_accounts")) | ||||
|         ) | ||||
|         get_output.click() | ||||
|         get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning") | ||||
|         txt_alert = get_output_msg.text | ||||
|         time.sleep(20) | ||||
| 
 | ||||
|         if txt_alert.find("TA user created successfully") == 0: | ||||
|             time.sleep(20) | ||||
|             email_pattern = r"Use email (\S+) as account name" | ||||
|             password_pattern = r" (\S+)\ as password." | ||||
|             email_match = re.search(email_pattern, txt_alert) | ||||
|             password_match = re.search(password_pattern, txt_alert) | ||||
|             if email_match and password_match: | ||||
|                 # Extract email and password from the matches | ||||
|                 email = email_match.group(1) | ||||
|                 password = password_match.group(1) | ||||
|             logout_button = driver_open.find_element(By.XPATH, | ||||
|                                                      "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]") | ||||
|             logout_button.click() | ||||
|             time.sleep(15) | ||||
|             username_input = driver_open.find_element('name', "user") | ||||
|             password_input = driver_open.find_element('name', "password") | ||||
|             login_button = driver_open.find_element('id', "login_btn") | ||||
|             # login as the new TA | ||||
|             username_input.send_keys(email)  # login with credentials of the created TA | ||||
|             password_input.send_keys(password) | ||||
|             # Click the login button | ||||
|             time.sleep(20) | ||||
| 
 | ||||
|             login_button.click() | ||||
| 
 | ||||
|             time.sleep(20) | ||||
|             my_course = driver_open.find_element(By.CLASS_NAME, "display-6") | ||||
| 
 | ||||
|             print(f"WELCOME {fullname} YOU ARE IN") | ||||
| 
 | ||||
|         elif txt_alert.find("Email address ") == 0: | ||||
|             print(" EMAIL ALREADY EXIST ") | ||||
|         else: | ||||
|             driver_open.quit() | ||||
|         try: | ||||
|             with open('TEST_CREATING_TA.txt', 'a') as test_output: | ||||
|                 test_output.write(f"\n {current_time} check this message  : {txt_alert}") | ||||
|         except Exception as e: | ||||
|             print(f"unexpected error: {e}") | ||||
| 
 | ||||
|         time.sleep(10) | ||||
| 
 | ||||
|     finally: | ||||
|         driver_open.quit() | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue