From debd85e74d1c279dbd0ca6953d989d18160e902b Mon Sep 17 00:00:00 2001 From: Lan Hui Date: Fri, 27 Sep 2024 10:16:01 +0800 Subject: [PATCH] Add two new regression tests: test_student_with_valid_student_number_can_sign_up, test_student_with_invalid_student_number_cannot_sign_up --- lrr_database.sql | 3 +- test/SeleniumHui/helper.py | 5 --- test/SeleniumHui/test_lrr.py | 59 +++++++++++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/lrr_database.sql b/lrr_database.sql index a2a4009..efce39d 100644 --- a/lrr_database.sql +++ b/lrr_database.sql @@ -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'); + -- -------------------------------------------------------- diff --git a/test/SeleniumHui/helper.py b/test/SeleniumHui/helper.py index d012d1b..6220b3f 100644 --- a/test/SeleniumHui/helper.py +++ b/test/SeleniumHui/helper.py @@ -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)}" diff --git a/test/SeleniumHui/test_lrr.py b/test/SeleniumHui/test_lrr.py index da16a91..36c77cd 100644 --- a/test/SeleniumHui/test_lrr.py +++ b/test/SeleniumHui/test_lrr.py @@ -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()