From a34ab61916c26a77dfecb51aa0cc1331de756142 Mon Sep 17 00:00:00 2001 From: Lan Hui Date: Tue, 24 Sep 2024 09:09:54 +0800 Subject: [PATCH] Add a new regression test --- lrr_database.sql | 2 +- test/SeleniumHui/helper.py | 9 ++++++++ test/SeleniumHui/test_lrr.py | 40 ++++++++++++++++++++++++------------ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/lrr_database.sql b/lrr_database.sql index d156f5c..a2a4009 100644 --- a/lrr_database.sql +++ b/lrr_database.sql @@ -285,7 +285,7 @@ CREATE TABLE `users_table` ( INSERT INTO `users_table` (`User_ID`, `Email`, `Password`, `HashPassword`, `Full_Name`, `UserType`, `Student_ID`, `Passport_Number`, `Status`) VALUES (3, 'admin@qq.com', '$2y$10$8GCG6lTo1LFRD3bOkAyKYeOMOrFSBUgrTxaPLS5ynWN1bYDHf89pO', '', 'Kamal', 'Admin', '0', NULL, 'Active'), -(8, 'lanhui@qq.com', '1234', '', 'Lanhui', 'Lecturer', NULL, '123', 'Active'), +(8, 'lanhui@qq.com', '$2y$10$8GCG6lTo1LFRD3bOkAyKYeOMOrFSBUgrTxaPLS5ynWN1bYDHf89pO', '', 'Lanhui', 'Lecturer', NULL, '123', 'Active'), (9, 'mohamed@qq.com', '123', '', 'Mohamed', 'Student', '201825800050', 'P00581929', 'Active'), (10, 'mark@qq.com', '123', '', 'Mark ', 'TA', NULL, '123', 'Active'), (11, 'john@qq.com', '123', '', 'John', 'TA', NULL, '123', 'Active'), diff --git a/test/SeleniumHui/helper.py b/test/SeleniumHui/helper.py index bea59f9..d012d1b 100644 --- a/test/SeleniumHui/helper.py +++ b/test/SeleniumHui/helper.py @@ -31,3 +31,12 @@ def login(driver, url, username, password): ) except (NoSuchElementException, UnexpectedAlertPresentException) as e: return f"Error: {str(e)}" + + +def logout(driver): + logout_button = WebDriverWait(driver, 10).until( + EC.element_to_be_clickable( + (By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]") + ) + ) + logout_button.click() diff --git a/test/SeleniumHui/test_lrr.py b/test/SeleniumHui/test_lrr.py index 94c82d5..c1010fa 100644 --- a/test/SeleniumHui/test_lrr.py +++ b/test/SeleniumHui/test_lrr.py @@ -1,4 +1,4 @@ -from helper import login +from helper import login, logout import time from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait @@ -20,18 +20,13 @@ def test_admin_can_create_lecturer_account(driver, url, admin_username, admin_pa elem = driver.find_element(By.NAME, 'password') elem.send_keys('123Abc!!') radio_button = driver.find_element(By.NAME, 'type') - radio_button.click() + radio_button.click() button = driver.find_element(By.NAME, 'create_btn') button.click() # Log out Admin account - logout_button = WebDriverWait(driver, 10).until( - EC.element_to_be_clickable( - (By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]") - ) - ) - logout_button.click() - + logout(driver) + # Log in Lecturer account login(driver, url, 'mrlan@qq.com', '123Abc!!') elems = driver.find_elements(By.CLASS_NAME, 'nav-link') @@ -39,12 +34,31 @@ def test_admin_can_create_lecturer_account(driver, url, admin_username, admin_pa assert 'Mr Lan' in elems[0].text driver.quit() - -def test_lecturer_can_create_course(): - # Lecturer mrlan@qq.com logs in +def test_lecturer_can_create_course(driver, url, restore_database): + # Lecturer lanhui@qq.com logs in + driver.maximize_window() + login(driver, url, 'lanhui@qq.com', '123') + # Create a course called CSC1001 Advanced Software Engineering, 2024 - assert True + elem = driver.find_element(By.NAME, 'name') + elem.send_keys('Advanced Software Engineering') + elem = driver.find_element(By.NAME, 'code') + elem.send_keys('CSC1001') + elem = driver.find_element(By.NAME, 'academic') + elem.send_keys('2004') + elem = driver.find_element(By.NAME, 'faculty') + elem.send_keys('School of Computer Science and Technology') + elem = driver.find_element(By.CLASS_NAME, 'btn-primary') + elem.click() + elems = driver.find_elements(By.CLASS_NAME, 'btn-default') + last_elem = elems[-1] + assert 'Advanced Software Engineering' in last_elem.text + assert '(CSC1001)' in last_elem.text + + # Logout + logout(driver) + driver.quit() def test_lecturer_can_post_assignment():