Compare commits

...

22 Commits

Author SHA1 Message Date
Lan Hui 5bbd812189 Fix bug 430 2024-09-15 16:02:40 +08:00
Lan Hui 162de63b4d Merge branch 'Bug430-Eden' of http://118.25.96.118:3000/mrlan/LRR into Bug430-Eden 2024-09-15 15:45:20 +08:00
mrlan 88d20ed476 Merge pull request 'Bug486-Nartey' (#65) from Bug486-Nartey into Hui-Organize
Reviewed-on: #65
2024-09-15 15:34:57 +08:00
Lan Hui 5d0d0d91f7 Resolve merge conflict 2024-09-15 15:32:30 +08:00
mrlan fea32072c3 Merge pull request 'Bug352-Neil-Revised' (#69) from Bug352-Neil-Revised into Hui-Organize
Reviewed-on: #69
2024-09-15 14:23:42 +08:00
nartey 5639ce4c6b test script 2024-06-21 13:32:50 +08:00
nartey 8f3919d3bb TestScript 2024-06-21 13:16:11 +08:00
Lan Hui 23e192568f Merge branch 'Hui-Organize' of http://118.25.96.118:3000/mrlan/LRR into Bug352-Neil-Revised 2024-05-10 08:13:21 +08:00
Lan Hui dc3ff79b5d Rename test_cases.py to test_bug352_neil.py, and change some lines to use fixtures in conftest.py. 2024-05-10 08:13:04 +08:00
Lan Hui 690db8d5fe Merge branch 'BUG352-NEIL2' of http://118.25.96.118:3000/mrlan/LRR into Bug352-Neil-Revised 2024-05-10 07:34:56 +08:00
mrlan 1a01b4facd Merge pull request 'added my version of the test script' (#67) from Bug418-Yaaqob into Hui-Organize
Reviewed-on: #67
2024-05-10 07:19:52 +08:00
Lan Hui 4024a36021 (1) Move conftest.py to the top level test directory so that it applies to all test subfolders; (2) Move login() to helper.py so that it could be reused by other test scripts. 2024-05-10 07:17:56 +08:00
KOUONTCHOU NEIL ARMSTRONG f600f2bc24 this is the demo video link https://cloud.zjnu.edu.cn/share/5d5a595aa863203768489383cd a second live demonsatration would be made in class 2024-05-08 15:48:49 +01:00
KOUONTCHOU NEIL ARMSTRONG 8e200b647f udpdate that includes database restore make sure the original database link is ok in the case of error 2024-05-08 15:42:56 +01:00
KOUONTCHOU NEIL ARMSTRONG dcd0e522c7 updated code tha uses fixture to restore the database. make sure the link of the database sql file is set nomally. this is the demo video https://cloud.zjnu.edu.cn/share/5d5a595aa863203768489383cd 2024-05-07 12:45:03 +01:00
Lan Hui 4da1c5a641 Merge branch 'Hui-Organize' of http://118.25.96.118:3000/mrlan/LRR into Bug418-Yaaqob 2024-05-03 15:38:06 +08:00
Lan Hui f2aa60c994 Define extra fixtures (i.e., driver, url, admin_username, admin_password) in conftest.py and use them 2024-05-03 15:34:39 +08:00
Lan Hui 5b72461eda Make the password work 2024-05-02 20:45:06 +08:00
Lan Hui ff092f2a8e Merge branch 'Bug418-Yaaqob' of http://118.25.96.118:3000/mrlan/LRR into Bug418-Yaaqob 2024-05-02 19:11:42 +08:00
YAAQOB ABDULSATTAR HAMID ABDULQADER 622ed4350f added my version of the test script 2024-04-29 14:14:19 +08:00
Nartey Sylvester Amanor 9f03d380cd Fix Bug486 2023-12-31 19:43:47 +08:00
Nartey Sylvester Amanor c1f95ce017 Bug Fix 486 2023-12-31 18:20:22 +08:00
9 changed files with 356 additions and 73 deletions

View File

@ -72,7 +72,7 @@ if ($_SESSION['user_type'] != "Lecturer" && $_SESSION['user_type'] != "Admin") {
Email Email
<input type="text" name="email" placeholder="Email / Student Number" class="form-control" > <br> <input type="text" name="email" placeholder="Email / Student Number" class="form-control" > <br>
Initial password (Enter a strong password or leave it empty to let LRR generate one) Initial password (Enter a strong password or leave it empty to let LRR generate one)
<input type="password" class="form-control" name="password" minlength="8" placeholder="Initial password" > <br> <input type="password" class="form-control" name="password" minlength="8" placeholder="Initial password" > <br>
User type: User type:
<?php <?php

View File

@ -86,22 +86,22 @@ include 'Header.php';
<ul class="nav nav-tabs" id="myTab"> <ul class="nav nav-tabs" id="myTab">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" href="#menu1">New</a> <a class="nav-link <?php if (!isset($_GET['tab']) || $_GET['tab'] == 'New') echo 'active'; ?>" data-toggle="tab" href="#menu1">New</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="#menu2">Missed</a> <a class="nav-link <?php if ($_GET['tab'] == 'Missed') echo 'active'; ?>" data-toggle="tab" href="#menu2">Missed</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="#menu3">Submitted</a> <a class="nav-link <?php if ($_GET['tab'] == 'Submitted') echo 'active'; ?>" data-toggle="tab" href="#menu3">Submitted</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="#menu4">Marked</a> <a class="nav-link <?php if ($_GET['tab'] == 'Marked') echo 'active'; ?>" data-toggle="tab" href="#menu4">Marked</a>
</li> </li>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<div id="menu1" class="tab-pane active"> <div id="menu1" class="tab-pane <?php if (!isset($_GET['tab']) || $_GET['tab'] == 'New') echo 'active'; ?>">
<?php <?php
@ -185,7 +185,7 @@ include 'Header.php';
<div id="menu2" class="tab-pane"> <div id="menu2" class="tab-pane <?php if ($_GET['tab'] == 'Missed') echo 'active'; ?>">
<?php <?php
$group_id = $_SESSION['group_id']; $group_id = $_SESSION['group_id'];
@ -251,7 +251,7 @@ include 'Header.php';
<div id="menu3" class="tab-pane"> <div id="menu3" class="tab-pane <?php if ($_GET['tab'] == 'Submitted') echo 'active'; ?>">
<?php <?php
$group_id = $_SESSION['group_id']; $group_id = $_SESSION['group_id'];
@ -371,7 +371,7 @@ include 'Header.php';
?> ?>
<div id="menu4" class="tab-pane"> <div id="menu4" class="tab-pane <?php if ($_GET['tab'] == 'Marked') echo 'active'; ?>">
<?php <?php
$resultx = mysqli_query($con, "SELECT Submission_ID, Submission_Date, lab_reports_table.Lab_Report_ID, Student_id, Course_Group_id, Notes, lab_report_submissions.Marks, lab_report_submissions.Remarking_Reason, Status, lab_reports_table.Title Lab_Title, lab_reports_table.Marks Original_marks $resultx = mysqli_query($con, "SELECT Submission_ID, Submission_Date, lab_reports_table.Lab_Report_ID, Student_id, Course_Group_id, Notes, lab_report_submissions.Marks, lab_report_submissions.Remarking_Reason, Status, lab_reports_table.Title Lab_Title, lab_reports_table.Marks Original_marks
FROM lab_report_submissions FROM lab_report_submissions

View File

@ -119,7 +119,7 @@ if (!empty($_POST["form_signup"])) {
if (!empty($_POST["form_signup"])) { if (!empty($_POST["form_signup"])) {
$fullname = mysqli_real_escape_string($con, $_POST["fullname"]); $fullname = mysqli_real_escape_string($con, $_POST["fullname"]);
$student_id = mysqli_real_escape_string($con, $_POST["user_student_id"]); $student_id = mysqli_real_escape_string($con, $_POST["user_student_id"]);
<<<<<<< HEAD
$email = mysqli_real_escape_string($con, $_POST["email"]); $email = mysqli_real_escape_string($con, $_POST["email"]);
$password = mysqli_real_escape_string($con, $_POST["password"]); $password = mysqli_real_escape_string($con, $_POST["password"]);
$confirmpassword = mysqli_real_escape_string($con, $_POST["confirmpassword"]); $confirmpassword = mysqli_real_escape_string($con, $_POST["confirmpassword"]);
@ -168,13 +168,11 @@ if (!empty($_POST["form_signup"])) {
return; return;
} }
=======
$_SESSION['user_fullname'] = $fullname;
$_SESSION['user_type'] = "Student"; $_SESSION['user_type'] = "Student";
$_SESSION['user_email'] = $email; $_SESSION['user_email'] = $email;
$_SESSION['user_student_id'] = $student_id; $_SESSION['user_student_id'] = $student_id;
>>>>>>> fde44f76006082d6bda9431727d06cbd23a134be
// apply password_hash() // apply password_hash()
$password_hash = password_hash($password, PASSWORD_DEFAULT); $password_hash = password_hash($password, PASSWORD_DEFAULT);
$sql = "INSERT INTO `users_table`(`Email`, `Password`, `Full_Name`, `UserType`, `Student_ID`) VALUES " $sql = "INSERT INTO `users_table`(`Email`, `Password`, `Full_Name`, `UserType`, `Student_ID`) VALUES "
@ -793,8 +791,8 @@ if (!empty($_GET["remarking"])) {
if ($con->query($sql) === TRUE) { if ($con->query($sql) === TRUE) {
$_SESSION["info_general"] = "Remarking request sent"; $_SESSION["info_general"] = "Remarking Request Sent";
header("Location: Course.php?url=" . $url); header("Location: Course.php?url=" . $url . "&tab=Marked");
} else { } else {
echo "Error: " . $sql . "<br>" . $con->error; echo "Error: " . $sql . "<br>" . $con->error;
} }

View File

@ -284,7 +284,7 @@ CREATE TABLE `users_table` (
-- --
INSERT INTO `users_table` (`User_ID`, `Email`, `Password`, `HashPassword`, `Full_Name`, `UserType`, `Student_ID`, `Passport_Number`, `Status`) VALUES INSERT INTO `users_table` (`User_ID`, `Email`, `Password`, `HashPassword`, `Full_Name`, `UserType`, `Student_ID`, `Passport_Number`, `Status`) VALUES
(3, 'admin@qq.com', '123', '', 'Kamal', 'Admin', '0', NULL, 'Active'), (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', '1234', '', 'Lanhui', 'Lecturer', NULL, '123', 'Active'),
(9, 'mohamed@qq.com', '123', '', 'Mohamed', 'Student', '201825800050', 'P00581929', 'Active'), (9, 'mohamed@qq.com', '123', '', 'Mohamed', 'Student', '201825800050', 'P00581929', 'Active'),
(10, 'mark@qq.com', '123', '', 'Mark ', 'TA', NULL, '123', 'Active'), (10, 'mark@qq.com', '123', '', 'Mark ', 'TA', NULL, '123', 'Active'),

View File

@ -0,0 +1,33 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException, UnexpectedAlertPresentException
def login(driver, url, username, password):
try:
driver.get(url)
# Fill in the login form
user_input = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "user_name"))
)
user_input.send_keys(username)
password_input = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "user_password"))
)
password_input.send_keys(password)
# Click the login button
login_button = WebDriverWait(driver, 10).until(
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

@ -0,0 +1,122 @@
import pytest
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException, UnexpectedAlertPresentException
from helper import login
@pytest.mark.parametrize("course_id, course_name, ta_name", [(1, "Teecloudy - Ashly Course Testing", "Mark")])
def test_assign_a_new_ta_to_a_course(course_id, course_name, ta_name, driver, url, admin_username, admin_password, restore_database):
try:
driver.maximize_window()
login(driver, url, admin_username, admin_password)
admin_tab = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "admin_tab"))
)
admin_tab.click()
# Locate the form and select the TA
ta_form = WebDriverWait(driver, 15).until(
EC.presence_of_element_located((By.XPATH, f"//form[@id='drop_menu_form_{course_id}']"))
)
ta_dropdown = Select(ta_form.find_element(By.XPATH, ".//select[@name='ta']"))
ta_dropdown.select_by_visible_text(ta_name)
# Submit the form using JavaScript
driver.execute_script("arguments[0].submit();", ta_form)
# find table courses
table_courses = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, ".//*[@id='tab-existing-courses']/table"))
)
# find the row with matching course_name
course_row = table_courses.find_element(By.XPATH, f".//tr[td='{course_name}']")
# find the column with TA name
ta_column = course_row.find_element(By.XPATH, ".//td[4]")
# assert the TA name in the column
assert ta_name in ta_column.text, f"Error: TA name {ta_name} not found in the column {ta_column.text}"
except NoSuchElementException as e:
return f"Error: {str(e)}"
except UnexpectedAlertPresentException as e:
return f"Error: {str(e)}"
except AssertionError as e:
return f"Error: {str(e)}"
except Exception as e:
return f"Error: {str(e)}"
finally:
driver.quit()
@pytest.mark.parametrize("course_id, course_name, ta_name", [(1, "Teecloudy - Ashly Course Testing", "Mark")])
def test_assign_the_same_ta_to_the_same_course_twice(course_id, course_name, ta_name, driver, url, admin_username, admin_password, restore_database):
try:
driver.maximize_window()
login(driver, url, admin_username, admin_password)
admin_tab = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "admin_tab"))
)
admin_tab.click()
# Hui: assign the TA for the first time
# (1) Locate the form and select the TA
ta_form = WebDriverWait(driver, 15).until(
EC.presence_of_element_located((By.XPATH,
f"//form[@id='drop_menu_form_{course_id}']")) )
ta_dropdown = Select(ta_form.find_element(By.XPATH, ".//select[@name='ta']"))
ta_dropdown.select_by_visible_text(ta_name)
# (2) Submit the form using JavaScript
driver.execute_script("arguments[0].submit();", ta_form)
# (3) Find table courses
table_courses_before = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, ".//*[@id='tab-existing-courses']/table"))
)
# (4) Find the row with matching course_name
course_row_before = table_courses_before.find_element(By.XPATH, f".//tr[td='{course_name}']")
# (5) Find the column with TA name
old_cell_content = course_row_before.find_element(By.XPATH, ".//td[4]").text
# Hui: assign the same TA again
ta_form = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.XPATH, f"//form[@id='drop_menu_form_{course_id}']")))
ta_dropdown = Select(ta_form.find_element(By.XPATH, ".//select[@name='ta']"))
ta_dropdown.select_by_visible_text(ta_name)
driver.execute_script("arguments[0].submit();", ta_form)
# Wait for an expected alert and accept it
WebDriverWait(driver, 10).until(EC.alert_is_present())
alert = driver.switch_to.alert
alert_text = alert.text
alert.accept()
# find table courses
table_courses_after = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, ".//*[@id='tab-existing-courses']/table"))
)
# find the row with matching course_name
course_row_after = table_courses_after.find_element(By.XPATH, f".//tr[td='{course_name}']")
# find the column with TA name
new_cell_content = course_row_after.find_element(By.XPATH, ".//td[4]").text
# assert the TA name in the column
assert old_cell_content == new_cell_content, f"Error: TA name in the column has changed from {old_cell_content} to {new_cell_content}"
except NoSuchElementException as e:
return f"Error: {str(e)}"
except UnexpectedAlertPresentException as e:
return f"Error: {str(e)}"
except AssertionError as e:
return f"Error: {str(e)}"
except Exception as e:
return f"Error: {str(e)}"
finally:
driver.quit()

View File

@ -4,14 +4,17 @@
import re import re
import time import time
import pytest import pytest
from faker import Faker
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
faker = Faker()
@pytest.mark.skip(reason="function to be used in the test_scripts") def test_restore_database(restore_database):
assert restore_database is None
def createTA(driver, TA_name, emails, password): def createTA(driver, TA_name, emails, password):
full_name = driver.find_element('name', 'fullname') full_name = driver.find_element('name', 'fullname')
full_name.send_keys(TA_name) full_name.send_keys(TA_name)
@ -24,56 +27,58 @@ def createTA(driver, TA_name, emails, password):
click_create = driver.find_element('name', 'create_btn') click_create = driver.find_element('name', 'create_btn')
click_create.click() click_create.click()
def login_lecturer(drivers):
def login_lecturer(driver, url):
# Open the website # Open the website
drivers.get("http://localhost/lrr/") driver.get(url)
drivers.maximize_window() driver.maximize_window()
username_input = drivers.find_element('name', "user") username_input = driver.find_element('name', "user")
password_input = drivers.find_element('name', "password") password_input = driver.find_element('name', "password")
login_button = drivers.find_element('id', "login_btn") login_button = driver.find_element('id', "login_btn")
# login as a Lecturer # login as a Lecturer
username_input.send_keys("lanhui@qq.com") username_input.send_keys("admin@qq.com")
password_input.send_keys("nil1234H@") password_input.send_keys("123")
# Click the login button # Click the login button
time.sleep(5) time.sleep(2)
login_button.click() login_button.click()
admin_tab = drivers.find_element('id', 'admin_tab') admin_tab = driver.find_element('id', 'admin_tab')
admin_tab.click() admin_tab.click()
cte_instructor = drivers.find_element('id', 'tab_ins_accounts') cte_instructor = driver.find_element('id', 'tab_ins_accounts')
cte_instructor.click() cte_instructor.click()
time.sleep(25) time.sleep(2)
def test_createTA():
driver_open = webdriver.Chrome() def test_createTA(driver, url):
driver_open = driver
driver_open.maximize_window() driver_open.maximize_window()
login_lecturer(driver_open) login_lecturer(driver_open, url)
try: try:
fullname = faker.name() fullname = "lanhuitest1"
email = faker.email() email = "lanhuitest1@qq.com"
password = "new1452345678" password = "new1452345678"
createTA(driver_open, fullname, email,password) # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678 createTA(driver_open, fullname, email,password) # CREATE A TA WITH FULLNAME lanhuitest1 email lanhuitest1@qq.com password new1452345678
get_output = WebDriverWait(driver_open, 10).until( get_output = WebDriverWait(driver_open, 20).until(
EC.element_to_be_clickable((By.ID, "tab_ins_accounts")) EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
) )
get_output.click() get_output.click()
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning") get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
txt_alert = get_output_msg.text txt_alert = get_output_msg.text
time.sleep(20) time.sleep(2)
if txt_alert.find("TA user created successfully") == 0: if txt_alert.find("TA user created successfully") == 0:
logout_button = WebDriverWait(driver_open, 15).until( logout_button = WebDriverWait(driver_open, 20).until(
EC.element_to_be_clickable( EC.element_to_be_clickable(
(By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]")) (By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]"))
) )
time.sleep(5) time.sleep(2)
logout_button.click() logout_button.click()
time.sleep(10) time.sleep(2)
username_input = driver_open.find_element('name', "user") username_input = driver_open.find_element('name', "user")
password_input = driver_open.find_element('name', "password") password_input = driver_open.find_element('name', "password")
login_button = driver_open.find_element('id', "login_btn") login_button = driver_open.find_element('id', "login_btn")
@ -81,45 +86,45 @@ def test_createTA():
username_input.send_keys(email) # login with credentials of the created TA username_input.send_keys(email) # login with credentials of the created TA
password_input.send_keys(password) password_input.send_keys(password)
# Click the login button # Click the login button
time.sleep(20) time.sleep(2)
login_button.click() login_button.click()
time.sleep(20) time.sleep(2)
elif txt_alert.find("Email address ") == 0: elif txt_alert.find("Email address ") == 0:
time.sleep(22) time.sleep(2)
driver_open.quit() driver_open.quit()
else: else:
driver_open.quit() driver_open.quit()
time.sleep(5) time.sleep(2)
finally: finally:
driver_open.quit() driver_open.quit()
def test_generate_password(): def test_generate_password(driver, url):
driver_open = webdriver.Chrome() driver_open = driver
login_lecturer(driver_open) login_lecturer(driver_open, url)
try: try:
fullname = faker.name() fullname = "lanhuitest2"
email = faker.email() email = "lanhuitest2@qq.com"
password = "" password = ""
createTA(driver_open, fullname, email, createTA(driver_open, fullname, email,
password) # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678 password) # CREATE A TA WITH FULLNAME lanhuitest2 email lanhuitest2@qq.com password ""
get_output = WebDriverWait(driver_open, 5).until( get_output = WebDriverWait(driver_open, 20).until(
EC.element_to_be_clickable((By.ID, "tab_ins_accounts")) EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
) )
get_output.click() get_output.click()
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning") get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
txt_alert = get_output_msg.text txt_alert = get_output_msg.text
time.sleep(20) time.sleep(2)
if txt_alert.find("TA user created successfully") == 0: if txt_alert.find("TA user created successfully") == 0:
time.sleep(20) time.sleep(2)
email_pattern = r"Use email (\S+) as account name" email_pattern = r"Use email (\S+) as account name"
password_pattern = r" (\S+)\ as password." password_pattern = r" (\S+)\ as password."
email_match = re.search(email_pattern, txt_alert) email_match = re.search(email_pattern, txt_alert)
@ -128,12 +133,12 @@ def test_generate_password():
# Extract email and password from the matches # Extract email and password from the matches
email = email_match.group(1) email = email_match.group(1)
password = password_match.group(1) password = password_match.group(1)
logout_button = WebDriverWait(driver_open, 10).until( logout_button = WebDriverWait(driver_open, 20).until(
EC.element_to_be_clickable( EC.element_to_be_clickable(
(By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]")) (By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]"))
) )
logout_button.click() logout_button.click()
time.sleep(15) time.sleep(2)
username_input = driver_open.find_element('name', "user") username_input = driver_open.find_element('name', "user")
password_input = driver_open.find_element('name', "password") password_input = driver_open.find_element('name', "password")
login_button = driver_open.find_element('id', "login_btn") login_button = driver_open.find_element('id', "login_btn")
@ -141,54 +146,56 @@ def test_generate_password():
username_input.send_keys(email) # login with credentials of the created TA username_input.send_keys(email) # login with credentials of the created TA
password_input.send_keys(password) password_input.send_keys(password)
# Click the login button # Click the login button
time.sleep(20) time.sleep(2)
login_button.click() login_button.click()
time.sleep(20) time.sleep(2)
elif txt_alert.find("Email address ") == 0: elif txt_alert.find("Email address ") == 0:
time.sleep(22) time.sleep(2)
driver_open.quit() driver_open.quit()
else: else:
driver_open.quit() driver_open.quit()
time.sleep(5) time.sleep(2)
finally: finally:
driver_open.quit() driver_open.quit()
def test_existingTA():
driver_open = webdriver.Chrome() def test_existingTA(driver, url, restore_database):
login_lecturer(driver_open) driver_open = driver
login_lecturer(driver, url)
try: try:
# Use email nreyes@example.com as account name and new1452345678 as password. # Use email nreyes@example.com as account name and new1452345678 as password.
fullname = "Maria" fullname = "lanhuitest1"
email = "nreyes@example.com" email = "lanhuitest1@qq.com"
password = "new1452345678" password = "new1452345678"
createTA(driver_open, fullname, email, createTA(driver_open, fullname, email,
password) # CREATE A TA WITH FULLNAME lanhuitest email lanhuitest@test.com password lanhui12345678 password) # CREATE A TA WITH FULLNAME lanhuitest1 email lanhuitest1@qq.com password new1452345678
get_output = WebDriverWait(driver_open, 5).until( get_output = WebDriverWait(driver_open, 20).until(
EC.element_to_be_clickable((By.ID, "tab_ins_accounts")) EC.element_to_be_clickable((By.ID, "tab_ins_accounts"))
) )
get_output.click() get_output.click()
get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning") get_output_msg = driver_open.find_element(By.CLASS_NAME, "alert-warning")
txt_alert = get_output_msg.text txt_alert = get_output_msg.text
time.sleep(20) time.sleep(2)
if txt_alert.find("TA user created successfully") == 0: if txt_alert.find("TA user created successfully") == 0:
time.sleep(20) time.sleep(2)
elif txt_alert.find("Email address ") == 0: elif txt_alert.find("Email address ") == 0:
time.sleep(22) time.sleep(2)
driver_open.quit() driver_open.quit()
else: else:
driver_open.quit() driver_open.quit()
time.sleep(5)
time.sleep(2)
finally: finally:
driver_open.quit() driver_open.quit()

View File

@ -0,0 +1,77 @@
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException, TimeoutException
import time
import traceback
driver = webdriver.Chrome()
try:
# Navigate to the page with tabs
driver.get("http://localhost:8080/lrr/")
driver.maximize_window()
wait = WebDriverWait(driver, 10)
# Login as a Lecturer
username_input = wait.until(EC.presence_of_element_located((By.NAME, "user")))
password_input = driver.find_element(By.NAME, "password")
login_button = driver.find_element(By.ID, "login_btn")
username_input.send_keys("ashly@qq.com")
password_input.send_keys("admin123")
time.sleep(5)
login_button.click()
course_but= driver.find_element(By.XPATH, "(//div[@class='btn btn-default'])[1]") # Adjust this XPATH as needed
# Click on the alert
course_but.click()
time.sleep(5)
marked_tab = wait.until(
EC.element_to_be_clickable((By.XPATH, "//a[text()='Marked']"))
)
marked_tab.click()
# Wait for the Marked tab content to be present
marked_tab_content = wait.until(
EC.presence_of_element_located((By.XPATH, "//div[@id='menu4' and contains(@class, 'active')]"))
)
time.sleep(5)
remark_but = wait.until(
EC.presence_of_element_located((By.XPATH, "//button[normalize-space()='Request remarking']"))
)
remark_but.click()
time.sleep(2)
# Switch to the alert
alert = driver.switch_to.alert
# Send keys to the prompt
alert.send_keys("Number 2 was correct")
# Accept the prompt (click OK)
alert.accept()
time.sleep(5)
except NoSuchElementException as e:
print("NoSuchElementException: Could not find an element.")
traceback.print_exc()
except TimeoutException as e:
print("TimeoutException: An element took too long to load.")
traceback.print_exc()
except Exception as e:
print(f"An unexpected error occurred: {e}")
traceback.print_exc()
finally:
driver.quit()

46
test/conftest.py Normal file
View File

@ -0,0 +1,46 @@
import os
import pytest
from selenium import webdriver
@pytest.fixture
def restore_database():
''' Restore the database.
It is useful for making sure that each end-to-end test
starts with the same database.
Benefit: we can reproduce the same test result.
'''
PASSWORD = 'p-@va9' # root password
DB_NAME = 'lrr' # database name used for LRR
# commands used to import data to DB_NAME
cmds = [
f'mysql -u root -p{PASSWORD} -e "DROP DATABASE IF EXISTS {DB_NAME};"',
f'mysql -u root -p{PASSWORD} -e "CREATE DATABASE {DB_NAME};"',
f'mysql -u root -p{PASSWORD} -e "GRANT ALL PRIVILEGES ON {DB_NAME}.* TO lrr@localhost WITH GRANT OPTION;"',
f'mysql -u root -p{PASSWORD} {DB_NAME} < ../lrr_database.sql']
for command in cmds:
os.system(command)
return None
@pytest.fixture
def url():
return 'http://localhost/LRR/' # URL of LRR
@pytest.fixture
def driver():
return webdriver.Chrome()
@pytest.fixture
def admin_username():
return 'admin@qq.com'
@pytest.fixture
def admin_password():
return '123'