Add two new regression tests: test_student_with_valid_student_number_can_sign_up, test_student_with_invalid_student_number_cannot_sign_up

Hui-Organize
Lan Hui 2024-09-27 10:16:01 +08:00
parent 39c14f7425
commit debd85e74d
3 changed files with 57 additions and 10 deletions

View File

@ -259,7 +259,8 @@ INSERT INTO `students_data` (`ID`, `Student_ID`, `Passport_Number`) VALUES
(1, '201825800054', 'LJ7951632'),
(2, '201825800050', 'P00581929'),
(3, '201632120150', 'FN524516'),
(4, '11', '11');
(4, '202400000001', 'NA');
-- --------------------------------------------------------

View File

@ -24,11 +24,6 @@ def login(driver, url, username, password):
EC.element_to_be_clickable((By.ID, "login_btn"))
)
login_button.click()
# Wait for the admin_tab to become clickable
admin_tab = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "admin_tab"))
)
except (NoSuchElementException, UnexpectedAlertPresentException) as e:
return f"Error: {str(e)}"

View File

@ -90,6 +90,7 @@ def test_lecturer_can_post_assignment(driver, url, restore_database):
assert 'Take-home quiz 1 (10 Marks, Individual)' in elem.text
elem = driver.find_element(By.CLASS_NAME, 'text-muted')
assert 'Deadline: 2024-12-30' in elem.text
driver.quit()
def test_lecturer_can_add_student_numbers(driver, url, restore_database):
@ -133,12 +134,62 @@ def test_lecturer_can_add_student_numbers(driver, url, restore_database):
added += 1
break
assert added == len(student_lst)
driver.quit()
@pytest.mark.skip()
def test_student_can_sign_up():
# Student with recognizable student number can sign up an account
assert True
def test_student_with_valid_student_number_can_sign_up(driver, url, restore_database):
# Student with recognizable student number 202400000001 can sign up an account
driver.get(url)
driver.maximize_window()
elem = driver.find_element(By.ID, 'signup_link')
elem.click()
elem = driver.find_element(By.NAME, 'fullname')
elem.send_keys('Good Student')
elem = driver.find_element(By.NAME, 'user_student_id')
elem.send_keys('202400000001')
elem = driver.find_element(By.NAME, 'email')
elem.send_keys('goodstudent@qq.com')
elem = driver.find_element(By.NAME, 'password')
elem.send_keys('[123Abc]')
elem = driver.find_element(By.NAME, 'confirmpassword')
elem.send_keys('[123Abc]')
elem = driver.find_element(By.ID, 'signup_btn')
elem.click()
logout(driver)
# Log in Student account
login(driver, url, '202400000001', '[123Abc]')
elems = driver.find_elements(By.CLASS_NAME, 'nav-link')
assert 'Student ID' in elems[0].text
assert 'Good Student' in elems[0].text
driver.quit()
def test_student_with_invalid_student_number_cannot_sign_up(driver, url, restore_database):
# Student with unrecognizable student number cannot sign up an account
driver.get(url)
driver.maximize_window()
elem = driver.find_element(By.ID, 'signup_link')
elem.click()
elem = driver.find_element(By.NAME, 'fullname')
elem.send_keys('Good Student')
elem = driver.find_element(By.NAME, 'user_student_id')
elem.send_keys('202400000002')
elem = driver.find_element(By.NAME, 'email')
elem.send_keys('goodstudent@qq.com')
elem = driver.find_element(By.NAME, 'password')
elem.send_keys('[123Abc]')
elem = driver.find_element(By.NAME, 'confirmpassword')
elem.send_keys('[123Abc]')
elem = driver.find_element(By.ID, 'signup_btn')
elem.click()
# Log in Student account
login(driver, url, '202400000002', '[123Abc]')
elems = driver.find_elements(By.CLASS_NAME, 'nav-link')
assert not 'Student ID' in elems[0].text
assert not 'Good Student' in elems[0].text
driver.quit()
@pytest.mark.skip()